summaryrefslogtreecommitdiffstats
path: root/net/ricketyspace
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2018-01-20 16:19:30 +0000
committerrsiddharth <s@ricketyspace.net>2018-01-20 16:19:30 +0000
commit65bfbb936e608d0c8654f3117b9c5cdb4763505f (patch)
treed9122bbdf71dbf64cae960536f230fe10abd3f0d /net/ricketyspace
parent57dd424ec01775df3a10b246f60db749e1015b8b (diff)
Add net/ricketyspace/sicp/one/thirtyseven.scm
Diffstat (limited to 'net/ricketyspace')
-rw-r--r--net/ricketyspace/sicp/one/thirtyseven.scm22
1 files changed, 22 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/one/thirtyseven.scm b/net/ricketyspace/sicp/one/thirtyseven.scm
new file mode 100644
index 0000000..09081d4
--- /dev/null
+++ b/net/ricketyspace/sicp/one/thirtyseven.scm
@@ -0,0 +1,22 @@
+;;;; Under Creative Commons Attribution-ShareAlike 4.0
+;;;; International. See
+;;;; <https://creativecommons.org/licenses/by-sa/4.0/>.
+
+(define-module (net ricketyspace sicp one thirtyseven)
+ #:export (cont-frac-iter))
+
+(define (cont-frac-iter n d k)
+ (define (do-iter n d i)
+ (cond ((< i k) (/ (n i)
+ (+ (d i) (do-iter n d (1+ i)))))
+ (else (/ (n i) (d i)))))
+ (do-iter n d 1))
+
+;;; Guile REPL
+;;;
+;;; scheme@(guile-user)> ,use (net ricketyspace sicp one thirtyseven)
+;;; scheme@(guile-user)> (cont-frac-iter (lambda (i) 1.0) (lambda (i) 1.0) 10)
+;;; $16 = 0.6179775280898876
+;;; scheme@(guile-user)> (cont-frac-iter (lambda (i) 1.0) (lambda (i) 1.0) 11)
+;;; $17 = 0.6180555555555556
+