diff options
author | rsiddharth <s@ricketyspace.net> | 2019-12-06 19:58:09 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2019-12-06 19:58:09 -0500 |
commit | aa947f6031c1523c406a15a934782ec16ffa59c3 (patch) | |
tree | 41ac66125b5039c0c108e8f1a884d963a9cd2904 /net | |
parent | c4e42b086215f617c7332cae31ffdaac882af407 (diff) |
Add (net ricketyspace sicp two thirtysix).
Diffstat (limited to 'net')
-rw-r--r-- | net/ricketyspace/sicp/two/thirtysix.scm | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/two/thirtysix.scm b/net/ricketyspace/sicp/two/thirtysix.scm new file mode 100644 index 0000000..dba2635 --- /dev/null +++ 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) |