summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2017-09-25 02:27:07 +0000
committerrsiddharth <s@ricketyspace.net>2017-09-25 02:27:07 +0000
commitb0170945a60133e0468161e069b3d817502f9091 (patch)
treefc57ca455c68c92353452e473d4bac9678837827
parent39c264bbafc10ad9997c21ae36995ab179d8d2b9 (diff)
net: Update (net ricketyspace sicp one twentynine)
* net/ricketyspace/sicp/one/twentynine.scm (simpsons): Rename function to `simpson`; Add comments.
-rw-r--r--net/ricketyspace/sicp/one/twentynine.scm13
1 files changed, 11 insertions, 2 deletions
diff --git a/net/ricketyspace/sicp/one/twentynine.scm b/net/ricketyspace/sicp/one/twentynine.scm
index 1dfdc45..5d1af80 100644
--- a/net/ricketyspace/sicp/one/twentynine.scm
+++ b/net/ricketyspace/sicp/one/twentynine.scm
@@ -3,7 +3,7 @@
;;;; <https://creativecommons.org/licenses/by-sa/4.0/>.
(define-module (net ricketyspace sicp one twentynine)
- #:export (simpsons))
+ #:export (simpson))
(define (sum term a next b)
(if (> a b)
@@ -11,7 +11,7 @@
(+ (term a)
(sum term (next a) next b))))
-(define (simpsons f a b n)
+(define (simpson f a b n)
(let* ((h (/ (- b a) (* 1.0 n)))
(y (lambda (k) (+ a (* k h))))
(ce (lambda (k) ;coefficient
@@ -23,3 +23,12 @@
(next (lambda (k) (1+ k))))
(* (/ h 3.0)
(sum term 0 next n))))
+
+;;; Guile REPL
+;;; scheme@(guile-user)> ,use (net ricketyspace sicp one twentynine)
+;;; scheme@(guile-user)> (define (cube x) (* x x x))
+;;; scheme@(guile-user)> (simpson cube 0 1 100)
+;;; $23 = 0.24999999999999992
+;;; scheme@(guile-user)> (simpson cube 0 1 1000)
+;;; $24 = 0.2500000000000003
+