You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sicp-all-tasks/sicp/3_002e52

32 lines
684 B

Exercise 3.52: Consider the sequence of
expressions
(define sum 0)
(define (accum x)
(set! sum (+ x sum))
sum)
(define seq
(stream-map
accum
(stream-enumerate-interval 1 20)))
(define y (stream-filter even? seq))
(define z
(stream-filter
(lambda (x)
(= (remainder x 5) 0)) seq))
(stream-ref y 7)
(display-stream z)
What is the value of sum after each of the above expressions is
evaluated? What is the printed response to evaluating the stream-ref
and display-stream expressions? Would these responses differ if we had
implemented (delay ⟨exp⟩) simply as (lambda () ⟨exp⟩)
without using the optimization provided by memo-proc? Explain.