An accumulator is a procedure that is called repeatedly with a single numeric argument and accumulates its arguments into a sum. Each time it is called, it returns the currently accumulated sum. Write a procedure
that generates accumulators, each maintaining an independent sum. The input to
should specify the initial value of the sum, for example:
(define A (make-accumulator 5)) (A 10) 15 (A 10) 25
There are no comments yet.
You must log in to post a comment.Login
(define A (make-accumulator 5)) (check-equal? (A 10) 15) (check-equal? (A 10) 25) (check-equal? (A -5) 20) (check-equal? ((make-accumulator 0) 5) 5)