summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-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
+