-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ex3_50.scm
41 lines (29 loc) · 863 Bytes
/
Ex3_50.scm
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
(define stream-null? null?)
(define the-empty-stream '())
(define (memo-proc proc)
(let ((already-run? #f) (result #f))
(lambda ()
(if (not already-run?)
(begin (set! result (proc))
(set! already-run? #t)
result)
result))))
(define (delay exp)
(memo-proc (lambda () exp)))
(define (force delayed-exp)
(delayed-exp))
(define (cons-stream a b)
(cons a (delay b)))
(define (stream-car stream)
(car stream))
(define (stream-cdr stream)
(force (cdr stream)))
(define (stream-map proc . argstreams)
(if (stream-null? (car argstreams))
the-empty-stream
(cons-stream
(apply proc (map stream-car argstreams))
(apply stream-map
(cons proc (map stream-cdr argstreams))))))
(define stream-arg (cons-stream 1 (cons-stream 2 (cons-stream 3 '()))))
(stream-map + stream-arg stream-arg stream-arg)