Exercise 3.50

Read Exercise 3.50 ~ Solution


(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))))))

In order to test streams I had to track down a way of creating cons-stream. The book says it is a special form and so I found the following. I later found that the planet package I used previously provides a version of cons-stream too, but I’m sticking to the racket language for now.

(define-syntax cons-stream
  (syntax-rules ()
    ((_ A B) (cons A (delay B)))))

Leave a comment