<< Previous exercise (3.73)
| Index |
Next exercise (3.75) >>
(stream-map sign-change-detector sense-data (cons-stream 0 sense-data)))
I don't think that is right. If the first element of the sense-data stream were negative above solution will show a sign-change crossing immediately when there is none.
(define (zero-crossings sense-data)
(stream-map sign-change-detector sense-data (stream-cdr sense-data)))
meteorgan's solution complies with the original zero-crossings in the book.
The first two arguments to sign-change-detector should be:
(stream-car sense-data) and 0
I agree with hoonji that meteorgan's solution correctly answers the problem. However I would like to point out that the last-value parameter is completely superfluous when the next value in the stream is always easily accessible. In this manner, we can rewrite make-zero-crossings elegantly to require only a single argument:
(define (make-zero-crossings input-stream)
(stream-map sign-change-detector (stream-cdr sense-data) sense-data))
karthikk's solution addresses this issue too, but as pointed out already, that is not what the book is asking for literally in this exercise. In my opinion this seems like a rare example of lapse of judgment on the part of the authors.