[4Clojure]解题记录-#78

Reimplement Trampoline
 

Difficulty: Medium
Topics: core-functions

 

Reimplement the function described in "Intro to Trampoline".
 
(= (letfn [(triple [x] #(sub-two (* 3 x)))
          (sub-two [x] #(stop?(- x 2)))
          (stop? [x] (if (> x 50) x #(triple x)))]  (__ triple 2))  82)
 
(= (letfn [(my-even? [x] (if (zero? x) true #(my-odd? (dec x))))
          (my-odd? [x] (if (zero? x) false #(my-even? (dec x))))]
    (map (partial __ my-even?) (range 6)))  [true false true false true false])
 
解长度 41:
#(loop [t (apply % %&)] (if (fn? t) (recur (t)) t))
posted @ 2014-11-27 20:56  TomAndRainy  阅读(145)  评论(0编辑  收藏  举报