From: Ramakrishnan Muthukrishnan Date: Tue, 3 Aug 2010 14:15:18 +0000 (+0530) Subject: solution to 2.36 X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/biz/cyclelanguage?a=commitdiff_plain;h=80daf2d6ef4b3afaf444fcd5a145b0d20c73c1a2;p=sicp.git solution to 2.36 --- diff --git a/src/sicp/ex2_36.clj b/src/sicp/ex2_36.clj new file mode 100644 index 0000000..acd7124 --- /dev/null +++ b/src/sicp/ex2_36.clj @@ -0,0 +1,19 @@ +(ns sicp.ex2_36 + (:use [clojure.test] + [sicp [ch2-2 :only (accumulate)]])) + +;; (define (accumulate-n op init seqs) +;; (if (null? (car seqs)) +;; nil +;; (cons (accumulate op init ) +;; (accumulate-n op init )))) +(defn accumulate-n [op init seqs] + (if (nil? (first seqs)) + nil + (cons (accumulate op init (map first seqs)) + (accumulate-n op init (map next seqs))))) + +(deftest test-accumulate-n + (let [s (list (list 1 2 3) (list 4 5 6) (list 7 8 9) (list 10 11 12))] + (is [= (accumulate-n + 0 s) + (list 22 26 30)]))) \ No newline at end of file