File: power.ss

package info (click to toggle)
chezscheme 9.5.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 58,092 kB
  • sloc: ansic: 17,515; sh: 760; makefile: 509; csh: 430; asm: 56
file content (12 lines) | stat: -rw-r--r-- 280 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
;;; 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))))])))