Implement till 3.66
This commit is contained in:
@@ -34,15 +34,6 @@
|
||||
|
||||
(display "\nex-3.51\n")
|
||||
|
||||
(define (show x)
|
||||
(display-line x)
|
||||
x)
|
||||
|
||||
(define (stream-ref s n)
|
||||
(if (= n 0)
|
||||
(stream-car s)
|
||||
(stream-ref (stream-cdr s) (- n 1))))
|
||||
|
||||
(define x (stream-map show (stream-enumerate-interval 0 10)))
|
||||
|
||||
(stream-ref x 5)
|
||||
@@ -59,9 +50,6 @@
|
||||
|
||||
(display "\nex-3.52\n")
|
||||
|
||||
(define (display-stream s)
|
||||
(stream-for-each display-line s))
|
||||
|
||||
(define sum 0)
|
||||
|
||||
(define (accum x)
|
||||
@@ -106,19 +94,10 @@
|
||||
|
||||
(display "\nex-3.53\n")
|
||||
|
||||
(define (add-streams s1 s2)
|
||||
(stream-map + s1 s2))
|
||||
|
||||
(define ones (cons-stream 1 ones))
|
||||
|
||||
(define integers (cons-stream 1 (add-streams ones integers)))
|
||||
|
||||
(define (take n xs)
|
||||
(if (= n 0)
|
||||
'()
|
||||
(cons (stream-car xs)
|
||||
(take (- n 1) (stream-cdr xs)))))
|
||||
|
||||
(assert (take 3 integers)
|
||||
'(1 2 3))
|
||||
|
||||
@@ -131,9 +110,6 @@
|
||||
(assert (take 7 fibs)
|
||||
'(0 1 1 2 3 5 8))
|
||||
|
||||
(define (scale-stream stream factor)
|
||||
(stream-map (lambda (x) (* x factor)) stream))
|
||||
|
||||
(define double (cons-stream 1 (scale-stream double 2)))
|
||||
|
||||
(assert (take 3 double)
|
||||
|
||||
Reference in New Issue
Block a user