making a procedure tail-recursive: example
example
- given procedure that generates recursive process
(define (exp x k)(if (= k 0) 1 (* x (exp x (- k 1)))))
- progress: might have done multiplications of values seen so far
- new formal parameter: s
- new expression: (* x s)
- termination condition: (= k 0), as before
result
(define (expi x k) (expiter x k 1))
(define (expiter x k s)(if (= k 0) s
(expiter x (- k 1) (* x s))))