4 ms·
I did not get the tatoo reference, haha. As far as I understand, though, there is TCO in Clojure, right? You just have to be explicit and use (recur).
by djacobs 16y ago
I did not get the tatoo reference, haha. As far as I understand, though, there is TCO in Clojure, right? You just have to be explicit and use (recur).
- silentbicycle 16y agoThat's not TCO, that's just an optimization for individual recursion. You might be able to use it for multiple forms under the same recur (like w/ "labels"), but it's very different when it applies to everything. With TCO, you can use a set of mutually-recursive functions - you can set up a FSM via tail calls, use CPS for backtracking (and many other things), a re-entrant virtual machine where each opcode is a tail call (rather than a giant switch/case or lots of gotos), etc. Being able to use function calls like "gotos with arguments" (but with local scopes, etc.) can make some constructs much easier to read, reason about, etc. I'm not that familiar with the implementation of the JVM, but AFAICT it's due to difficulties setting up tail calls efficiently in JVM bytecode.
- bitsai 16y agoYou can do optimized mutual-recursion in Clojure as well, using (trampoline). As with the optimized self-recursion using (recur), it's more work and not as nice as built-in TCO, but this is likely as good as it gets for now, given the current limitations of the JVM.
- nickik 16y agoRich is very mutch pro tail calls. Look at his talk at the JVM Language http://wiki.jvmlangsummit.com/What_the_JVM_needs http://wiki.jvmlangsummit.com/What_the_JVM_needs (the video is not online jet). As soon as the JVM supports it Clojure will support it. For me recur and trampoline are quite ok. I would want to miss on clojure because of TCO but I don't know what would be possible with TCO. I hope I can learn that in one of the books I have here :)
- silentbicycle 16y agoAny thoughts on the question I made before that (http://news.ycombinator.com/item?id=1736446 http://news.ycombinator.com/item?id=1736446)? And yeah, I thought of mentioning trampolines, didn't know that it already had a readymade one. Sometimes they add too much overhead, but often it's still a good trade-off.
- nickik 16y agoDo you mean the question if it was worth your while? If it was I would say yes because its a modern list that fixes old lisp problems, learn from the new languages and is pretty fast.