sicp

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

commit b3705061d22326b41c3751512e7b50388992c87e
parent 09096bfaa15c34ba4c6010cc0765658e6327c19f
Author: rsiddharth <s@ricketyspace.net>
Date:   Fri, 30 Mar 2018 23:14:56 +0000

net: Add (net ricketyspace sicp one fortyfour)

* net/ricketyspace/sicp/one/fortyfour.scm: New file.

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

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