SICP Exercise 3.76 modular implementation of smooth and zero-crossing

Exercise 3.76.  Eva Lu Ator has a criticism of Louis's approach in exercise 3.75. The program he wrote is not modular, because it intermixes the operation of smoothing with the zero-crossing extraction. For example, the extractor should not have to be changed if Alyssa finds a better way to condition her input signal. Help Louis by writing a procedure smooth that takes a stream as input and produces a stream in which each element is the average of two successive input stream elements. Then use smooth as a component to implement the zero-crossing detector in a more modular style.

SOLUTION

See in the tests below that the 'smooth' procedure after processing the parabolic stream from Exercise 3.75, produces the same stream as what we saw produced by the corrected procedure in Exercise 3.75. The new procedures are also tested on a random value stream after this.

The code and tests are here.

Comments

Popular posts from this blog

SICP Exercise 2.56 differentiation rule

SICP Exercise 1.28 (Miller-Rabin Test)

SICP Exercise 4.18 a alternative strategy for interpreting internal definitions