2014-05-11から1日間の記事一覧

4Clojure-Part2

Factorial Fun (fn [n] (loop [n n f 1] (if (zero? n) f (recur (dec n) (* f n))))) そのまんま。 Interpose a Sequence (fn [x coll] (loop [coll coll s ()] (if (empty? coll) (rest (reverse s)) (recur (rest coll) (cons (first coll) (cons x s)) )…

4Clojure-Part1

Find the odd numbers (fn [coll] (loop [coll coll odds ()] (if (empty? coll) (reverse odds) (recur (rest coll) (if (odd? (first coll)) (cons (first coll) odds) odds))))) もうちょっと短くしたいな・・・ Reverse a Sequence (fn my-reverse [coll…