# hw10 - - ;; Exercise 3.50 (define (stream-map proc ....

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: - ;; Exercise 3.50 (define (stream-map proc . argstreams) (if (stream-null? (car argstreams)) the-empty-stream (cons-stream (apply proc (map stream-car argstreams)) (apply stream-map (cons proc (map stream-cdr argstreams)))))) ;; Exercise 3.51 (define (show x) (display-line x) x) (define x (stream-map show (stream-enumerate-interval 0 10))) ; ; Value: x (stream-ref x 5) ; 1 ; 2 ; 3 ; 4 ; 5 ; Value: 5 (stream-ref x 7) ; 6 ; 7 ; Value: 7 ; ;; Exercise 3.52 (define sum 0) (define (accum x) (set! sum (+ x sum)) sum) (define seq (stream-map accum (stream-enumerate-interval 1 20))) ; sum = 1 (define y (stream-filter even? seq)) ; sum = 6 (define z (stream-filter (lambda (x) (= (remainder x 5) 0)) seq)) ; sum = 10 (stream-ref y 7) ;Value: 136 (display-stream z) ; 10 ; 15 ; 45 ; 55 ; 105 ; 120 ; 190 ; 210 ; sum = 210 ; ;; Exercise 3.53 (define s (cons-stream 1 (add-streams s s))) ; returns (1 2 4 8 16 32 ...) ; ;; Exercise 3.54 (define factorial (cons-stream 1 (mul-stream factorial integers)))...
View Full Document

## This note was uploaded on 11/30/2010 for the course EECS 21281 taught by Professor Harvey during the Spring '10 term at University of California, Berkeley.

### Page1 / 2

hw10 - - ;; Exercise 3.50 (define (stream-map proc ....

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online