Question

As far as I can tell, Clojure's recur is backed by the compiler whereas in other lisps it is implemented at a lower level.

As I read, this wouldn't be a "general" TCO. Aside from the obvious (a keyword + checking are needed), is in any way recur less powerful?

Was it helpful?

Solution

recur only supports tail-recursion optimization, which is a subclass of general TCO. Clojure also supports mutual or indirect recursion through trampoline.

EDIT Also, I think general TCO was expected to land in JVM with Java 7 and recur was meant as a temporary solution. Then Oracle happened. I've mixed that with Project Lambda's (adding closures in Java) schedule

OTHER TIPS

recur differs slightly from full TCO in that recur works with both loops and functions and does not do some of the things that a full implementation of TCO would. The philosophical backing for this is to make the special part look special as opposed to silently optimizing a uniform syntax.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top