sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit 7520b56810dcf0b3766c85ab81fdc22d788f72d5
parent e41fe7ced52fca41f3968b97df9572e4011025de
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 18 Feb 2017 05:15:09 +0000

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:
net/ricketyspace/sicp/one/eighteen.scm | 18++++++++++++++++++
net/ricketyspace/sicp/one/seventeen.scm | 5++++-
2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/net/ricketyspace/sicp/one/eighteen.scm 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 @@ -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."