How to use tail recursion correctly?
问题 I am trying to rewrite this piece of code from https://github.com/lspector/gp/blob/master/src/gp/evolvefn_zip.clj to use recur: (defn random-code [depth] (if (or (zero? depth) (zero? (rand-int 2))) (random-terminal) (let [f (random-function)] (cons f (repeatedly (get function-table f) #(random-code (dec depth))))))) The problem is, I have absolutely no idea how to do that. The only thing I can think of is something like this: (defn random-code [depth] (loop [d depth t 0 c []] (if (or (zero?