summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2017-02-18 05:15:09 +0000
committerrsiddharth <s@ricketyspace.net>2017-02-18 05:15:09 +0000
commit7520b56810dcf0b3766c85ab81fdc22d788f72d5 (patch)
treeed0eeabad09ec73a30f5d63d58ecf4b885b458d3 /net
parente41fe7ced52fca41f3968b97df9572e4011025de (diff)
net: Add `ifast-*` function.
* net/ricketyspace/sicp/one/eighteen.scm (ifast-iter-*) (ifast-*): New functions. * net/ricketyspace/sicp/one/seventeen.scm (double, halve): Add functions to export. (even?): Add function to replace.
Diffstat (limited to 'net')
-rw-r--r--net/ricketyspace/sicp/one/eighteen.scm18
-rw-r--r--net/ricketyspace/sicp/one/seventeen.scm5
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."