3 ms·
Those are cool properties. Another one is that you get a compilation error if your recursive call isn't in the tail position (and thus would actually grow the s
by wging 4y ago
Those are cool properties. Another one is that you get a compilation error if your recursive call isn't in the tail position (and thus would actually grow the stack when you thought it didn't).
One thing I don't think you can do with loop/recur, though, is optimize more complicated bits of recursion than a single function that calls itself. I.e. imagine a recursive call pattern that goes like f -> g -> f -> g -> ...
(edit: I'm pretty sure this is why trampoline exists, though I've never really played with it... https://clojuredocs.org/clojure.core/trampoline https://clojuredocs.org/clojure.core/trampoline)