diff --git a/scm.mes b/scm.mes index eb7f1c82..001cacbd 100755 --- a/scm.mes +++ b/scm.mes @@ -185,6 +185,11 @@ (define (remainder x y) (- x (* (/ x y) y))) +(define (expt x y) + (let loop ((s 1) (count y)) + (if (= 0 count) s + (loop (* s x) (- count 1))))) + (define (max x . rest) (if (null? rest) x (let* ((y (car rest)) diff --git a/test.mes b/test.mes index 771c5724..ea410a76 100644 --- a/test.mes +++ b/test.mes @@ -104,6 +104,7 @@ (pass-if "/" (seq? (/ 9 3) 3)) (pass-if "remainder" (seq? (remainder 11 3) 2)) (pass-if "modulo" (seq? (modulo 11 3) 2)) +(pass-if "expt" (seq? (expt 2 3) 8)) (pass-if "=" (seq? 3 '3)) (pass-if "= 2" (not (= 3 '4)))