sicp

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

commit 3e3f894460e5c5da45c645c5dd937bbbc62ebadf
parent b0170945a60133e0468161e069b3d817502f9091
Author: rsiddharth <s@ricketyspace.net>
Date:   Sat, 30 Sep 2017 21:19:27 +0000

net: Add (net ricketyspace sicp one thirty).

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

diff --git a/net/ricketyspace/sicp/one/thirty.scm b/net/ricketyspace/sicp/one/thirty.scm @@ -0,0 +1,28 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; <https://creativecommons.org/licenses/by-sa/4.0/>. + +(define-module (net ricketyspace sicp one thirty) + #:export (sum)) + +(define (sum term a next b) + (define (iter a result) + (if (> a b) + result + (iter (next a) (+ (term a) result)))) + (iter a 0)) + +;;; GNU Guile REPL +;;; +;;; scheme@(guile-user)> ,use (net ricketyspace sicp one thirty) +;;; scheme@(guile-user)> (define (inc n) (+ n 1)) +;;; scheme@(guile-user)> (define (cube x) (* x x x)) +;;; scheme@(guile-user)> (sum cube 1 inc 10) +;;; scheme@(guile-user)> (define (pi-sum a b) +;;; (define (pi-term x) +;;; (/ 1.0 (* x (+ x 2)))) +;;; (define (pi-next x) (+ x 4)) +;;; (sum pi-term a pi-next b)) +;;; scheme@(guile-user)> (* 8 (pi-sum 1 1000)) +;;; $9 = 3.139592655589782 +;;;