SICPゼミ第26回
練習問題3.50
(define (stream-map proc . argstreams) (if (null? (car argstreams )) the-empty-stream (stream-cons (apply proc (map stream-car argstreams)) (apply stream-map (cons proc (map stream-cdr argstreams))))))
by dolicas
練習問題3.51
gosh> (define x (stream-map show (stream-enumerate-interval 0 10))) 0x gosh> (stream-ref x 5) 1 2 3 4 55 gosh> (stream-ref x 7) 6 77
練習問題3.52
> (define sum 0) >(define (accum x) (set! sum (+ x sum)) sum) > sum 0 > (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) 136 > sum 136 > (display-stream z) 10 15 45 55 105 120 190 210'done > sum 210
メモ化していないと、毎回accumが呼ばれてsumに足されていってしまうのでへんなことになる。
by tube