From 53bc477bbacacece64e1b569b68c6bbe36f65ca9 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <vu3rdd@gmail.com>
Date: Thu, 28 Jul 2011 22:26:24 +0530
Subject: [PATCH] adding interleave and pair procedures

---
 src/sicp/streams.rkt | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/sicp/streams.rkt b/src/sicp/streams.rkt
index 42bde47..b68afe1 100644
--- 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)))))
+
+   
-- 
2.45.2