这个题目比较简单,直接上代码.
(defn accumulate [op initial sequences]
(if (empty? sequences)
initial
(op (first sequences)
(accumulate op initial (rest sequences))
)
)
)
(defn map2 [p sequences]
(accumulate (fn [x y] (if (= x nil) nil (p x y) ) ) nil sequences)
)
(defn append [seq1 seq2]
(accumulate cons seq2 seq1)
)
(defn length [sequences]
(accumulate (fn [x y] (if (= x nil) 0 (+ y 1) )) 0 sequences )
)