← Back to context

Comment by dnbfbfhf

6 hours ago

The CS 101 model of computing doesn’t have TCO… which makes it pretty accurate to the real world.

TCO is surprisingly commonly supported in the real world. TCO is supported in C++ compilers, JavaScript in Safari, Scala, Clojure in a way, etc.!

For instance:

"All current mainstream [C++] compilers perform tail call optimisation fairly well (and have done for more than a decade), even for mutually recursive calls" [1].

"As of July 22, 2023 Safari is the only browser that supports tail call optimization" of JavaScript [2].

"Since Clojure uses the Java calling conventions, it cannot, and does not, make the same tail call optimization guarantees. Instead, it provides the recur special operator, which does constant-space recursive looping" [3].

"The Scala compiler will automatically optimize any truly tail-recursive method. If you annotate a method that you believe is tail-recursive with the @tailrec annotation, then the compiler will warn you if the method is actually not tail-recursive" [4].

[1]: https://stackoverflow.com/a/34129

[2]: https://stackoverflow.com/a/37224563

[3]: https://stackoverflow.com/a/34097339

[4]: https://stackoverflow.com/a/3114245