diff options
author | rsiddharth <s@ricketyspace.net> | 2018-03-30 23:14:56 +0000 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2018-03-30 23:14:56 +0000 |
commit | b3705061d22326b41c3751512e7b50388992c87e (patch) | |
tree | 660b10f83d97477813777a0007149a97866c9e5f /net | |
parent | 09096bfaa15c34ba4c6010cc0765658e6327c19f (diff) |
net: Add (net ricketyspace sicp one fortyfour)
* net/ricketyspace/sicp/one/fortyfour.scm: New file.
Diffstat (limited to 'net')
-rw-r--r-- | net/ricketyspace/sicp/one/fortyfour.scm | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/one/fortyfour.scm b/net/ricketyspace/sicp/one/fortyfour.scm new file mode 100644 index 0000000..b7079f8 --- /dev/null +++ b/net/ricketyspace/sicp/one/fortyfour.scm @@ -0,0 +1,37 @@ +;;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;;; International. See +;;;; <https://creativecommons.org/licenses/by-sa/4.0/>. +;;;; + +(define-module (net ricketyspace sicp one fortyfour) + #:export (smooth)) + +(define (avg-3 x y z) + (/ (+ x y z) 3.0)) + +(define dx 0.00001) + +(define (smooth f) + (lambda (x) (avg-3 (f (- x dx)) + (f x) + (f (+ x dx))))) + +;;; GNU Guile REPL +;;; +;;; scheme@(guile-user)> ,use (net ricketyspace sicp one fortythree) +;;; scheme@(guile-user)> ,use (net ricketyspace sicp one fortyfour) +;;; scheme@(guile-user)> (sqrt 27) +;;; $2 = 5.196152422706632 +;;; scheme@(guile-user)> ((smooth sqrt) 27) +;;; $3 = 5.1961524227065725 +;;; scheme@(guile-user)> ((smooth (smooth sqrt)) 27) +;;; $4 = 5.196152422706514 +;;; scheme@(guile-user)> ((smooth (smooth (smooth sqrt))) 27) +;;; $5 = 5.196152422706454 +;;; scheme@(guile-user)> (((repeated smooth 1) sqrt) 27) +;;; $6 = 5.1961524227065725 +;;; scheme@(guile-user)> (((repeated smooth 2) sqrt) 27) +;;; $7 = 5.196152422706514 +;;; scheme@(guile-user)> (((repeated smooth 3) sqrt) 27) +;;; $8 = 5.196152422706454 +;;; |