SICP sicp 121: 3.52 exercises 1213.52 and

Source: Internet
Author: User

SICP sicp 121: 3.52 exercises 1213.52 and
Exercise 3-52 original

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? Wocould these responses differ if we had implemented (delay) simply as (lambda () without using the optimization provided by memo-proc? Explain.

Code
(define seq (stream-map accum (stream-enumerate-interval 1 20)))sum;Value: 1(define y (stream-filter even? seq))sum;Value: 6(define z (stream-filter (lambda (x) (= (remainder x 5) 0)) seq))(stream-ref y 7);Value: 136

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.