procedures as arguments
problem
- allow the rate to vary as function of year
solution
- use a procedure parameter (ratep)
(define (compound-vary principal ratep term)
(define (citer year gross)
(if (= term year) gross (citer (inc year) (+ gross (* gross (ratep year))))))
(citer 0 principal))
- sample evaluations
(define (five year) 0.05) ; fixed rate of 5%
(compound-vary 1000 five 20) ; evals to 2653, as before
(define (up year) ; rate ramps up (+ 0.05 (/(modulo year 10) 100)))
(compound-vary 1000 up 20) ; evals to 6099
(define (dn year) ; rate ramps down (+ 0.15 (- (/(modulo year 10) 100))))
(compound-vary 1000 dn 20) ; evals to 7316