Exercise 1.32
- Recursive:
(define (accumulate combine id term a next b)
(if (> a b)
id
(combine (term a)
(accumulate combine id term (next a) next b))))
- Iterative:
scheme
(define (accumulate combine id term a next b)
(define (iter a acc)
(if (> a b)
acc
(iter (next a) (combine (term a) acc))))
(iter a id))
Implementing sum and product in terms of accumulate: