3 [sicp [ch2-2 :only (accumulate)]
4 [ex2_36 :only (accumulate-n)]]))
6 ;; The accumulate procedure is also known as fold-right, because it combines
7 ;; the first element of the sequence with the result of combining all the elements
8 ;; to the right. There is also a fold-left, which is similar to fold-right, except
9 ;; that it combines elements working in the opposite direction:
10 (def fold-right accumulate)
12 (defn fold-left [op initial sequence]
16 (op initial (first sequence))
19 ;; What are the values of
23 (fold-right / 1 (list 1 2 3))
26 (fold-left / 1 (list 1 2 3))
29 (fold-right list nil (list 1 2 3))
32 (fold-left list nil (list 1 2 3))