Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top