<< Previous exercise (3.75) | Index | Next exercise (3.77) >>


 (define (smooth s) 
         (stream-map (lambda (x1 x2) (/ (+ x1 x2) 2)) 
                             (cons-stream 0 s) 
 (define (make-zeor-crosssings input-stream smooth) 
         (let ((after-smooth (smooth input-stream))) 
             (stream-map sign-change-detector after-smooth (cons-stream 0 after-smooth)))) 


Again no need to cons-stream 0 in this case.

This had to be done in the non-modular (i.e. without using stream-map) 3.74 and 3.75 cases because the function had to be provided with an (arbitrary) initial value of 0 (and presumably the first couple of elements of output stream discarded)

With stream-map, there is no need for an arbitrary initial value for the sense-data: Thus:

 (define (smooth input-stream) 
   (stream-map (lambda(x y)(/ (+ x y) 2)) input-stream (stream-cdr input-stream))) 
 (define (zero-crossings input-stream) 
   (stream-map sign-change-detector input-stream (stream-cdr input-stream))) 
 (define (smoothed-zero-crossing sense-data) 
   (zero-crossings (smooth sense-data)))