From bbdba26201e90c2abfb99e10ef49533a414cb88a Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 24 Jul 2016 17:16:55 +0200 Subject: [PATCH] scm.mes: add expt. --- scm.mes | 5 +++++ test.mes | 1 + 2 files changed, 6 insertions(+) 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)))