a. Show that
) 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)
takes as arguments the same term and range specifications as
, together with a
procedure (of two arguments) that specifies how the current term is to be combined with the accumulation of the preceding terms and a
that specifies what base value to use when the terms run out. Write
and show how
can both be defined as simple calls to
b. If your
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.
There are no comments yet.
You must log in to post a comment.Login
(define (inc n) (+ n 1)) (define (square x) (* x x)) (define (identity x) x) (check-equal? (accumulate * 1 square 1 inc 3) 36) (check-equal? (accumulate * 1 identity 3 inc 5) 60) (check-equal? (accumulate + 0 identity 1 inc 10) 55)