a related problem
problem
- write a procedure display-exp such that(display-exp x k) displays “x to the k is …”
- eg, (display-exp 2 3) causes “2 to the 3 is 8” to be displayed
solution
(define (display-exp x k)
(define (helper j s)(if (= j 0) (begin (display x) (display “ to the “) (display k) (display “ is “ ) (display s))
(helper x (- j 1) (* x s))))
(helper k 1))
note
- if we don’t rename helper’s parameter, k would always be bound to 0 in (display k)