Chapter 3, Modularity, Objects, and State

Exercise 3.56


This is quite cool example!

1
2
3
4
5
(define S (cons-stream
		              1
	  			      (merge (scale-stream S 2)
			   				 (merge (scale-stream S 3)
									(scale-stream S 5)))))

Output:

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
1 ]=> (stream-ref S 0)

;Value: memo-proc

1 ]=> 
;Value: 1

1 ]=> (stream-ref S 1)

;Value: 2

1 ]=> (stream-ref S 2)

;Value: 3

1 ]=> (stream-ref S 3)

;Value: 4

1 ]=> (stream-ref S 4)

;Value: 5

1 ]=> (stream-ref S 5)

;Value: 6

1 ]=> (stream-ref S 6)

;Value: 8

1 ]=> (stream-ref S 7)

;Value: 9

1 ]=> (stream-ref S 8)

;Value: 10

1 ]=> (stream-ref S 9)

;Value: 12

1 ]=> (stream-ref S 10)

;Value: 15

1 ]=> (stream-ref S 11)

;Value: 16

1 ]=> (stream-ref S 12)

;Value: 18