free variables in procedures
eliminating a parameter
- helper’s parameter x is bound to the same value on every call
- so can eliminate the parameter
- now x in the body of helper refers to the parameter of exp
(define (exp x k)
(define (helper k s)(if (= k 0) s
(helper x (- k 1) (* x s))))
(helper k 1))
note
- x is now a free variable of the procedure helper
- so helper would not work elsewhere if we cut and pasted the code