Structure and Interpretation of Computer Programs by Harold Abelson & Gerald Jay Sussman & Julie Sussman

Structure and Interpretation of Computer Programs by Harold Abelson & Gerald Jay Sussman & Julie Sussman

Author:Harold Abelson & Gerald Jay Sussman & Julie Sussman
Language: eng
Format: epub
ISBN: 0-262-01153-0
Publisher: MIT Press


(define x (stream-map show (stream-enumerate-interval 0 10)))

(stream-ref x 5)

(stream-ref x 7)

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.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.