From 3e3f894460e5c5da45c645c5dd937bbbc62ebadf Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 30 Sep 2017 21:19:27 +0000 Subject: net: Add (net ricketyspace sicp one thirty). --- net/ricketyspace/sicp/one/thirty.scm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 net/ricketyspace/sicp/one/thirty.scm diff --git a/net/ricketyspace/sicp/one/thirty.scm b/net/ricketyspace/sicp/one/thirty.scm new file mode 100644 index 0000000..48269f5 --- /dev/null +++ b/net/ricketyspace/sicp/one/thirty.scm @@ -0,0 +1,28 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; . + +(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 +;;; -- cgit v1.2.3