Exercise 1.31
- The
sumprocedure is only the simplest of a vast number of similar abstractions that can be captured as higher-order procedures.[51] Write an analogous procedure calledproductthat returns the product of the values of a function at points over a given range. Show how to definefactorialin terms ofproduct. Also useproductto compute approximations to π using the formula [52]
- If your
productprocedure generates a recursive process, write one that generates an iterative process. If it generates an iterative process, write one that generates a recursive process.
[51] The intent of exercises 1.31 - 1.33 is to demonstrate the expressive power that is attained by using an appropriate abstraction to consolidate many seemingly disparate operations. However, though accumulation and filtering are elegant ideas, our hands are somewhat tied in using them at this point since we do not yet have data structures to provide suitable means of combination for these abstractions. We will return to these ideas in section 2.2.3 when we show how to use sequences as interfaces for combining filters and accumulators to build even more powerful abstractions. We will see there how these methods really come into their own as a powerful and elegant approach to designing programs. [back]
[52] This formula was discovered by the seventeenth-century English mathematician John Wallis. [back]
Corresponding Section:

Comments
Post new comment