3 ms·
Tail call optimization is a neat idea, but I have always felt that it is too magical. You cannot opt out of it. Clojure's approach strikes a good balance: Cloju
by xiaq 9y ago
Tail call optimization is a neat idea, but I have always felt that it is too magical. You cannot opt out of it. Clojure's approach strikes a good balance: Clojure doesn't do TCO, but it gives you "recur" as an explicit way to do tail recursions that don't consume stack space: https://clojuredocs.org/clojure.core/recur https://clojuredocs.org/clojure.core/recur
Clojure has also had "trampoline" in core since 1.0, which was released in the same year this article was written: https://clojuredocs.org/clojure.core/trampoline https://clojuredocs.org/clojure.core/trampoline. I have no idea how well it performs though.
If your language has "goto", it is very easy to manually optimize mutually recursive functions. One of the few valid use cases of "goto" today. (As someone who writes a lot of Go, I have always suspected this use case is why Go still has "goto".)
- sedachv 9y ago> One of the few valid use cases of "goto" today. Manually rewriting recursive algorithms is one of the least valid use case of GOTO. You need GOTO for low-level concurrency, IO multiplexing, and transpiling: https://github.com/vsedach/Eager-Future2/blob/master/future.lisp#L79 https://github.com/vsedach/Eager-Future2/blob/master/future.... https://github.com/vsedach/Vacietis/blob/master/compiler/implementation.lisp#L179 https://github.com/vsedach/Vacietis/blob/master/compiler/imp...
- richdougherty 9y agoJavaScript is considering syntactic support for tail calls instead of automatic support. Automatic optimisation is currently in the spec but is apparently controversial. https://github.com/tc39/proposal-ptc-syntax https://github.com/tc39/proposal-ptc-syntax