sicp

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

commit 65bfbb936e608d0c8654f3117b9c5cdb4763505f
parent 57dd424ec01775df3a10b246f60db749e1015b8b
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 20 Jan 2018 16:19:30 +0000

Add net/ricketyspace/sicp/one/thirtyseven.scm

Diffstat:
net/ricketyspace/sicp/one/thirtyseven.scm | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/net/ricketyspace/sicp/one/thirtyseven.scm 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 +