sicp

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

commit aa947f6031c1523c406a15a934782ec16ffa59c3
parent c4e42b086215f617c7332cae31ffdaac882af407
Author: rsiddharth <s@ricketyspace.net>
Date:   Fri,  6 Dec 2019 19:58:09 -0500

Add (net ricketyspace sicp two thirtysix).

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

diff --git a/net/ricketyspace/sicp/two/thirtysix.scm b/net/ricketyspace/sicp/two/thirtysix.scm @@ -0,0 +1,27 @@ +;;;; License: CC0-1.0 + +(define-module (net ricketyspace sicp two thirtysix) + #:export (accumulate-n)) + + +(define (accumulate op initial sequence) + (if (null? sequence) + initial + (op (car sequence) + (accumulate op initial (cdr sequence))))) + + +(define (accumulate-n op init seqs) + (if (null? (car seqs)) + '() + (cons (accumulate op init (map (lambda (seq) (car seq)) seqs)) + (accumulate-n op init (map (lambda (seq) (cdr seq)) seqs))))) + + +;;; Guile REPL +;;; +;;; scheme@(guile-user)> ,use (net ricketyspace sicp two thirtysix) +;;; scheme@(guile-user)> (accumulate-n + 0 '((1 2 3) (4 5 6) (7 8 9) (10 11 12))) +;;; $9 = (22 26 30) +;;; scheme@(guile-user)> (accumulate-n + 0 '((2 4 6) (3 6 9) (4 8 12) (5 10 15) (6 12 18))) +;;; $10 = (20 40 60)