Say I have a function like this:
user=> (def m {10 5, 5 2, 2 1}) #'user/m user=> (defn hierarchy [x] (when x (cons x (hierarchy (get mx))))) #'user/hierarchy user=> (hierarchy 10) (10 5 2 1) user=>
And, obviously, this is great, because the depth of the stack will be small. But for this general type of problem, when I create the list I want to return, the recursive call always ends inside the cons call. How would I convert this to tail recursion so that I can use recur and not take stack space?
source share