From 65bfbb936e608d0c8654f3117b9c5cdb4763505f Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 20 Jan 2018 16:19:30 +0000 Subject: Add net/ricketyspace/sicp/one/thirtyseven.scm --- net/ricketyspace/sicp/one/thirtyseven.scm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 net/ricketyspace/sicp/one/thirtyseven.scm (limited to 'net') 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 +;;;; . + +(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 + -- cgit v1.2.3