sicp

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

commit 16eedb8d4db0a3c3cef797eaa52564d53a2f6af8
parent e175ae249db5fad445395f244f6cd0b4e497c004
Author: rsiddharth <s@ricketyspace.net>
Date:   Fri, 22 Nov 2019 17:07:12 -0500

net: Add (net ricketyspace sicp two thirtyfour).

Diffstat:
net/ricketyspace/sicp/two/thirtyfour.scm | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/net/ricketyspace/sicp/two/thirtyfour.scm b/net/ricketyspace/sicp/two/thirtyfour.scm @@ -0,0 +1,25 @@ +;;;; License: CC0-1.0 + +(define-module (net ricketyspace sicp two thirtyfour) + #:export (horner-eval)) + + +(define (accumulate op initial sequence) + (if (null? sequence) + initial + (op (car sequence) + (accumulate op initial (cdr sequence))))) + + +(define (horner-eval x coefficient-sequence) + (accumulate (λ (this-coeff higher-terms) + (+ this-coeff (* higher-terms x))) + 0 + coefficient-sequence)) + +;;; Guile REPL +;;; +;;; scheme@(guile-user)> ,use (net ricketyspace sicp two thirtyfour) +;;; scheme@(guile-user)> (horner-eval 2 (list 1 3 0 5 0 1)) +;;; $2 = 79 +;;;