4 ms·
> Also, the post states that you can't have nested "tail-call optimized" loops in clojure, which is only partially correct: Using nested loops is commonly done
by xiaq 6y ago
> Also, the post states that you can't have nested "tail-call optimized" loops in clojure, which is only partially correct: Using nested loops is commonly done in Clojure, the only thing you can't do is have the loops call each other mutually-recursively, which is a far less common use case (but still a feature I hope to see in Clojure some day).
I guess you are referring to recur (https://clojuredocs.org/clojure.core/recur https://clojuredocs.org/clojure.core/recur), and I also think that it's a quite cheap way to get ~90% of the benefit of TCO without actually implementing TCO. It's also more explicit than TCO which is a plus over TCO.
For mutual recursions there is always trampoline (https://clojuredocs.org/clojure.core/trampoline https://clojuredocs.org/clojure.core/trampoline), FWIW.
- drcode 6y agoYes, 'recur is most commonly used in conjunction with 'loop, thanks for clarifying.