4 ms·
this is cool - but the real magic lies with in recur right? How is that implemented in clojure itself or does that require bytecode magic?
by shaunxcode 16y ago
this is cool - but the real magic lies with in recur right? How is that implemented in clojure itself or does that require bytecode magic?
- deleted 16y ago[deleted]
- fogus 16y agorecur is a special form (i.e. not implemented as a function or macro). It handles the case of the self-recursive call whereas the trampoline handles the mutually recursive call. There is no generalized tail call facility in the JVM and therefore not in Clojure.
- arohner 16y agorecur does two things: it checks that the call is in the tail position, and calls the JVM bytecode to GOTO the top of the function. The JVM has the bytecode to goto inside the current function, but doesn't have the instruction to jump to another function in constant space, which is why recur is the way it is.
- CodeMage 16y agoLots of nice info on SO on JVM and tail call optimization: http://stackoverflow.com/questions/105834/does-the-jvm-prevent-tail-call-optimizations http://stackoverflow.com/questions/105834/does-the-jvm-preve...