3 ms·
TCO can be implemented easily in non TC optimized langauges with a trampoline wrapper. Why do i need a fully fledged library for something that is basically a
by phplovesong 11mo ago
TCO can be implemented easily in non TC optimized langauges with a trampoline wrapper.
Why do i need a fully fledged library for something that is basically a few lines of code?
- srean 11mo agoThere's quite a bit of overhead. I believe Clojure does it with trampoline as JVM does not (as far as I know) does not support tail call optimization. Ironic, given Guy Steele.
- ndr 11mo agoYes, Clojure doesn't have TCO either. You get `(loop ... (recur ...))` or `trampoline`. Naive recursion will consume the stack. https://clojuredocs.org/clojure.core/loop https://clojuredocs.org/clojure.core/loop https://clojuredocs.org/clojure.core/recur https://clojuredocs.org/clojure.core/recur https://clojuredocs.org/clojure.core/trampoline https://clojuredocs.org/clojure.core/trampoline
- pfdietz 11mo agoNor can you count on Common Lisp to have TCO. People who are new to CL and treat it like Scheme run into this constantly. Basically never recur down a list, since the list could be long. This problem also shows up in cases where TCO is not possible. For example, suppose we have a syntax tree for some program and need to traverse the tree. Nodes that represent lists of things might have a long list of children, and in a sufficiently large program recursing down that list can blow out the stack. Just recurse on list elements, which one can reasonably assume don't nest too deeply.