5 ms·
The way I understand it, is that Scala does support tail-call recursion by way of compiling to a loop. Compilation was definitely a pain when I experimented wit
by jonesetc 13y ago
The way I understand it, is that Scala does support tail-call recursion by way of compiling to a loop. Compilation was definitely a pain when I experimented with Sit.
- chc 13y agoScala supports simple recursive tail-call optimization, but is less elegant in handling mutual recursion (due to JVM constraints). Clojure is probably the one you're thinking of that doesn't support tail-call elimination at all. Rich Hickey thought that if you couldn't do it cleanly in all cases (like mutual recursion), you may as well just come up with something else. So instead of optimizing recursive calls, Clojure has the recur function.
- cordite 13y agoI recall that scala uses "trampolines" by compiling to what is more like a state machine.
- judk 13y agoI thought Actors does that, but not Scala in general.(?)
- cordite 13y agoRúnar Bjarnason talked about it in his presentation "FP Programming is Terrible" [0] (he makes up for that title in the end) I asked him about it on twitter since it reminded me of thunks, he said " a trampoline executes a sequence of thunks, yeah" [1] [0]: https://www.youtube.com/watch?v=hzf3hTUKk8U https://www.youtube.com/watch?v=hzf3hTUKk8U [1]: https://twitter.com/runarorama/status/449070763421618176 https://twitter.com/runarorama/status/449070763421618176
- judk 13y agoOnly self recursion, which is a special but common case.