This repository has been archived on 2022-08-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
chez-openbsd/examples/power.ss

13 lines
280 B
Scheme
Raw Normal View History

2022-07-29 15:12:07 +02:00
;;; 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))))])))