racket/examples/power.ss
dyb 1356af91b3 initial upload of open-source release
original commit: 47a210c15c63ba9677852269447bd2f2598b51fe
2016-04-26 10:04:54 -04:00

13 lines
280 B
Scheme

;;; doubly recursive power (expt) function
;;; try using trace-lambda to see the nesting.
(define power
(lambda (x n)
(cond
[(= n 0) 1]
[(= n 1) x]
[else
(let ([q (quotient n 2)])
(* (power x q) (power x (- n q))))])))