summing naturals
problem: summing
- we want (sum n) to evaluate to the sum of the integers from 1 to n
- write a tail recursive version sumi too
solution
- (define (sum n) (if (= n 1) 1 (+ n (sum (- n 1)))))
- (define (sumi n) (sumiter n 0))
- (define (sumiter k s) (if (= k 1) s (sumiter (- k 1) (+ s n))))