blob: 37e3a9890920d9ea20140da48c56d064c196923f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
;;; The integers.
(define (ints-from n)
(cons-stream n (ints-from (+ n 1))))
(define integers (ints-from 1))
;;; pairs of integers, A&S version
(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)))))
;;; Louis Reasoner's version, ex. 3.68
(define (louis-pairs s t)
(interleave
(stream-map (lambda (x) (list (stream-car s) x))
t)
(louis-pairs (stream-cdr s) (stream-cdr t))))
;;; Fixing Louis's version with explicit DELAY and FORCE
(define (fixed-pairs s t)
(interleave-delayed
(stream-map (lambda (x) (list (stream-car s) x))
t)
(delay (fixed-pairs (stream-cdr s) (stream-cdr t)))))
(define (interleave-delayed s1 delayed-s2)
(if (stream-null? s1)
(force delayed-s2)
(cons-stream (stream-car s1)
(interleave-delayed (force delayed-s2)
(delay (stream-cdr s1))))))
|