6 ms·
Next stop, tail calls plz.
by noelwelsh 4y ago
Next stop, tail calls plz.
- JonChesterfield 4y agoTail calls make stack traces harder to read and it looks from the outside like java development is primarily about reading stack traces
- aembleton 4y agoThe strange thing is that the JVM can handle them because Scala and Kotlin have them. Java though, doesn't.
- aardvark179 4y agoScala and Kotlin just implement them using a trampoline, the JVM does not itself support tail calls.
- aembleton 4y agoHow do they do that? I thought it would need to be done at the JVM level so that stack didn't grow.
- kaba0 4y agoEvery recursion can be converted to code that uses only a single stack. Tail calls can be easily eliminated at compile time automatically as well, that’s why it only needs compile-time support — I don’t specifically know what Scala/etc do, but the mentioned trampoline is basically just a function pointer one can jump to, accumulating results in some non-stack data structure if needed.