(define ones (cons-stream 1 ones)) (define (add-streams first second) (stream-map + first second)) (define integers (cons-stream 1 (add-streams ones integers))) (define (display-stream stream) (display "[") (stream-for-each (lambda (x) (display x) (display " ")) stream) (display "]")) (define (display-stream-start stream i) (if (<= i 0) (newline) (begin (display (stream-car stream)) (display " ") (display-stream-start (stream-cdr stream) (-1+ i))))) (display-stream-start integers 10) ; Ex. 3.50 in the book ; stream map with multiple argument streams ;(define (stream-map proc . argstreams) ; (if () ; the-empty stream ; ( ; (apply proc (map argstreams)) ; (apply stream-map ; (cons proc (map argstreams)))))) ;; this version of stream-map-n assumes that the argument streams ;; are the same length (define (stream-map-n proc . argstreams) (if (stream-null? (car argstreams)) the-empty-stream (cons-stream (apply proc (map stream-car argstreams)) (apply stream-map-n (cons proc (map stream-cdr argstreams)))))) (define (stream-enumerate-interval low high) (if (> low high) the-empty-stream (cons-stream low (stream-enumerate-interval (+ low 1) high)))) (define mysum (stream-map-n + (stream-enumerate-interval 1 10) (stream-enumerate-interval 5 14) (stream-enumerate-interval 8 17))) (stream-car (stream-cdr mysum))