-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ex3_52.scm
51 lines (34 loc) · 1018 Bytes
/
Ex3_52.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
40
41
42
43
44
45
46
47
48
49
50
(define stream-null? null?)
(define the-empty-stream '())
(define (cons-stream a b)
(cons a (delay b)))
(define (stream-car stream)
(car stream))
(define (stream-cdr stream)
(force (cdr stream)))
(define (stream-enumerate-interval low high)
(if (> low high)
the-empty-stream
(cons-stream
low
(stream-enumerate-interval (+ low 1) high))))
(define (stream-ref s n)
(if (= n 0)
(stream-car s)
(begin (display (stream-cdr s))
(stream-ref (stream-cdr s) (- n 1)))))
(define (stream-map proc s)
(if (stream-null? s)
the-empty-stream
(cons-stream (proc (stream-car s))
(stream-map proc (stream-cdr s)))))
(define sum 0)
(define (accum x)
(set! sum (+ x sum))
sum)
(define seq (stream-map accum (stream-enumerate-interval 1 20)))
(stream-ref (stream-enumerate-interval 1 20) 5)
(define (integer-starting-from n)
(cons-stream n (integer-starting-from (+ n 1))))
(define integers (integer-starting-from 1))
(stream-ref integers 10)