This is more an exercise than everything else: since in Clojure there is no TCO at all
(unless explicitly through recur calls), the example grows the stack.
I began translating to trampoline style... but that was not very entertaining. :)
(defn cp-reverse [lst k] (loop [current-lst lst current-k k] (if (empty? current-lst) (current-k '()) (recur (rest current-lst) (fn [v] (cons (first current-lst) (current-k v)))))))
No comments:
Post a Comment