good question #3
improving performance (daniel, recitation 0)
- why not save cost of last procedure call?
(define (exp x k)
(define (helper k s)(if (= k 1) (* x s)
(helper x (- k 1) (* x s))))
(helper k 1))
- two reasons
cost is minimal anywayas k becomes larger, saving becomes proportionally less
now (exp 2 0) will fail
conclusion
- don’t optimize your code with little hacks
- to improve performance, think big: iterative squaring instead?
- procedures often make assumptions about the values of their parameters
- these assumptions can be very important (as you’ll see if you take 6170)