Clojure 编程/示例/API 示例/映射运算符
外观
user=> (map + [1 2 3 4] [1 2 3 4])
(2 4 6 8)
user=> (reduce * [2 3 4]) 24 ; 将奇数求和到 100 ;; 代码不漂亮,请看下一个示例以了解更好的方法 (reduce #(+ %1 (if (= 1 (rem %2 2)) %2 0)) (range 100))
; 将奇数求和到 100 (更简洁的版本) (reduce + (filter odd? (range 100)))
user=> (apply str [1 2])
"12"
(defn factorial [n]
(apply * (range 2 (inc n))))