3 ms·
Any languages don't implement tail-call optimizations though which makes using recursion expensive.
by brighter2morrow 7y ago
Any languages don't implement tail-call optimizations though which makes using recursion expensive.
- asimpletune 7y agoPretty easy to implement tail recursion though. Sometimes it’s hard to know if a language that automatically compiles to tail recursion will even always do it.
- JD557 7y ago> Sometimes it’s hard to know if a language that automatically compiles to tail recursion will even always do it. I wish more languages that do not always compile to tail recursive methods had something similar to Scala's `@tailrec` annotation (which forces the compilation to fail if the tail calls cannot be optimized). It's not a very elegant solution, but at least it works.
- 0xcde4c3db 7y agoI even convinced a C++ compiler (don't recall whether it was g++ or clang++; it might have been during a FreeBSD fling) to do TCO at one point, but I don't remember exactly how I did it and don't think the requirements are documented anywhere. It probably involved functions declared "static" (i.e. internal linkage) and with the same signature.
- dleslie 7y agoGCC does it automatically, if it's told to optimize at level 2, IIRC. It's -foptimize-sibling-calls
- celticmusic 7y agoI think you meant Many languages?