You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
880 B
25 lines
880 B
|
|
Exercise 1.32:
|
|
|
|
|
|
Show that sum and product (Exercise 1.31) are both special
|
|
cases of a still more general notion called accumulate that combines a
|
|
collection of terms, using some general accumulation function:
|
|
|
|
|
|
(accumulate
|
|
combiner null-value term a next b)
|
|
|
|
Accumulate takes as arguments the same term and range specifications as
|
|
sum and product, together with a combiner procedure (of
|
|
two arguments) that specifies how the current term is to be combined with the
|
|
accumulation of the preceding terms and a null-value that specifies what
|
|
base value to use when the terms run out. Write accumulate and show how
|
|
sum and product can both be defined as simple calls to
|
|
accumulate.
|
|
|
|
If your accumulate procedure generates a recursive process, write one
|
|
that generates an iterative process. If it generates an iterative process,
|
|
write one that generates a recursive process.
|
|
|
|
|
|
|