3.50 Exercise 3.50
This generalized version of stream-map allows us to pass a procedure proc of n arguments as well as n streams, and returns a stream containing proc applied to each of the ith values of the streams. It assumes that each stream is at least as long as the first, and returns a stream of only as many elements as there are elements of this. Note that, because argstreams is a list of streams, we can use normal list procedures on it.
(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))))))
As an example,
> (display-stream (stream-map + (stream-enumerate-interval 1 10) (stream-enumerate-interval 1 1000000)))
2
4
6
8
10
12
14
16
18
20
'done