From 7520b56810dcf0b3766c85ab81fdc22d788f72d5 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 18 Feb 2017 05:15:09 +0000 Subject: 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. --- net/ricketyspace/sicp/one/eighteen.scm | 18 ++++++++++++++++++ net/ricketyspace/sicp/one/seventeen.scm | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 net/ricketyspace/sicp/one/eighteen.scm (limited to 'net') 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 +;;;; . + +(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." -- cgit v1.2.3