3 ms·
Cool, now ABCL can have TCO!
by droideqa 2y ago
Cool, now ABCL can have TCO!
- dapperdrake 2y agoFinally. The ANTLR guys went through terrible contortions for their parsers. Never felt like working those details out for ABCL.
- 1932812267 2y agoThis isn't a _general_ tail call optimization--just tail recursion. The issue is that this won't support mutual tail recursion. e.g.: (defun func-a (x) (func-b (- x 34)) (defun func-b (x) (cond ((<= 0 x) x) ('t (func-a (-x 3)))) Because func-a and func-b are different (JVM) functions, you'd need an inter-procedural goto (i.e. a tail call) in order to natively implement this. As an alternative, some implementations will use a trampoline. func-a and func-b return a _value_ which says what function to call (and what arguments) for the next step of the computation. The trampoline then calls the appropriate function. Because func-a and func-b _return_ instead of actually calling their sibling, the stack depth is always constant, and the trampoline takes care of the dispatch.
- knome 2y agoSounds like a manual form of clojures recur function. https://clojuredocs.org/clojure.core/recur https://clojuredocs.org/clojure.core/recur
- 1932812267 2y agoClojure's loop/recur is specifically tail recursion like scala's tailrec or the optimization described in the blogpost. It doesn't use trampolines to enable tail calls that aren't tail recursion.