4 ms·
Spend some time with a language that not only supports them but actually encourages their use, and you will see for yourself. This isn't an example and does no
by req2 17y ago
Spend some time with a language that not only supports them but actually encourages their use, and you will see for yourself.
This isn't an example and does nothing to convince me that it's actually useful. Your suggested application just hints at difficult debugging when a Car object can be a stealth Truck. Maybe it isn't actually difficult, but why is this actually better than subclassing?
TCO allows programs to, in certain circumstances, reuse existing stack frames for possibly many function invocations. For example, if a function is written to be tail recursive, a VM with TCO could reuse the same stack frame for each recursive function invocation until the terminating condition is reached, at which point the last return value is caught and the frame is popped off the stack. (TCO isn't strictly limited to making tail recursion more efficient, but that is its most often cited benefit.)
Sounds like a loop.
- chromatic 17y agoDon't fall into the Turing equivalence tarpit. It's indeed possible to rewrite recursive code in terms of iteration and vice versa, but the most natural expression of many algorithms is recursion. If you can convince the compiler and/or runtime to manage your stack for you, you can concentrate on the interesting parts of the algorithm. It's like the difference between using objects in Smalltalk and writing your own object system in C.