-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#lang racket | ||
|
||
;; P235 - [序对的无穷流] | ||
|
||
(require "stream.scm") | ||
(require "infinite_stream.scm") | ||
(require "ch3support.scm") | ||
|
||
(define (interleave s1 s2) | ||
(if (stream-null? s1) | ||
s2 | ||
(cons-stream (stream-car s1) | ||
(interleave s2 (stream-cdr s1))))) | ||
|
||
(define (pairs s t) | ||
(cons-stream | ||
(list (stream-car s) (stream-car t)) | ||
(interleave | ||
(stream-map (lambda (x) (list (stream-car s) x)) | ||
(stream-cdr t)) | ||
(pairs (stream-cdr s) (stream-cdr t))))) | ||
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
(displayln "int-pairs") | ||
(define int-pairs (pairs integers integers)) | ||
(display-stream-n int-pairs 20) | ||
|
||
(displayln "prime-pairs") | ||
(define prime-pairs (stream-filter (lambda (pair) | ||
(prime? (+ (car pair) (cadr pair)))) | ||
int-pairs)) | ||
(display-stream-n prime-pairs 20) | ||
|