1 (define (memo-proc proc)
2 (let ((already-run? false) (result false))
6 (begin (set! already-run? true)
10 (define-syntax mydelay
11 (rsc-macro-transformer
14 `(memo-proc (lambda () ,exp)))))
16 (apply xfmr (cdr e))))))
18 (define (myforce delayed-object)
21 (define-syntax cons-stream
22 (rsc-macro-transformer
23 (let ((xfmr (lambda (x y) `(cons ,x (mydelay ,y)))))
25 (apply xfmr (cdr e))))))
27 (define (stream-car s)
29 (define (stream-cdr s)
31 (define stream-null? null?)
32 (define the-empty-stream '())
34 (define (integers-starting-from n)
35 (cons-stream n (integers-starting-from (+ n 1))))
37 (define (stream-ref s n)
40 (stream-ref (stream-cdr s) (- n 1))))
41 (define (stream-map proc s)
44 (cons-stream (proc (stream-car s))
45 (stream-map proc (stream-cdr s)))))
46 (define (stream-for-each proc s)
49 (begin (proc (stream-car s))
50 (stream-for-each proc (stream-cdr s)))))
52 (define (display-stream s)
53 (stream-for-each display-line s))
54 (define (display-line x)
58 (define (test-case actual expected)
63 (display "Expected: ")
67 ;; Exercise 3.50. Complete the following definition, which generalizes stream-map to allow procedures that take multiple arguments, analogous to map in section 2.2.3, footnote 12.
69 (define (stream-map proc . argstreams)
70 (if (stream-null? (car argstreams))
73 (apply proc (map stream-car argstreams))
75 (cons proc (map stream-cdr argstreams))))))
77 (define integers (integers-starting-from 1))
78 (test-case (stream-car (stream-cdr (stream-cdr (stream-cdr (stream-map * integers integers))))) 16)