projects
/
sicp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
8b52e1f
)
adding interleave and pair procedures
author
Ramakrishnan Muthukrishnan
<vu3rdd@gmail.com>
Thu, 28 Jul 2011 16:56:24 +0000
(22:26 +0530)
committer
Ramakrishnan Muthukrishnan
<vu3rdd@gmail.com>
Thu, 28 Jul 2011 16:56:24 +0000
(22:26 +0530)
src/sicp/streams.rkt
patch
|
blob
|
history
diff --git
a/src/sicp/streams.rkt
b/src/sicp/streams.rkt
index 42bde472c9a91079104933978dbba739a8f67d0f..b68afe1ff0636c15a75de12e8d9192f788dadc9f 100644
(file)
--- a/
src/sicp/streams.rkt
+++ b/
src/sicp/streams.rkt
@@
-105,3
+105,19
@@
(stream-cdr stream)))))
(define primes (sieve (integers-starting-from 2)))
+
+(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)))))
+
+