diff options
Diffstat (limited to 'net/ricketyspace')
-rw-r--r-- | net/ricketyspace/sicp/one/eighteen.scm | 18 | ||||
-rw-r--r-- | net/ricketyspace/sicp/one/seventeen.scm | 5 |
2 files changed, 22 insertions, 1 deletions
diff --git a/net/ricketyspace/sicp/one/eighteen.scm b/net/ricketyspace/sicp/one/eighteen.scm new file mode 100644 index 0000000..0c75311 --- /dev/null +++ b/net/ricketyspace/sicp/one/eighteen.scm @@ -0,0 +1,18 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; <https://creativecommons.org/licenses/by-sa/4.0/>. + +(define-module (net ricketyspace sicp one eighteen) + #:use-module (net ricketyspace sicp one seventeen) + #:export (ifast-*)) + +(define (ifast-iter-* a b n) + (cond ((= b 0) n) + ((even? b) (ifast-iter-* (double a) (halve b) n)) + (else (ifast-iter-* a (- b 1) (+ a n))))) + +(define (ifast-* a b) + "Compute A * B. + +Iterative version of fast-*." + (ifast-iter-* a b 0)) diff --git a/net/ricketyspace/sicp/one/seventeen.scm b/net/ricketyspace/sicp/one/seventeen.scm index 48717e9..1ef69cc 100644 --- a/net/ricketyspace/sicp/one/seventeen.scm +++ b/net/ricketyspace/sicp/one/seventeen.scm @@ -20,7 +20,10 @@ ;;; (define-module (net ricketyspace sicp one seventeen) - #:export (fast-*)) + #:export (double + halve + fast-*) + #:replace (even?)) (define (double a) "Return A + A." |