deprecated
deprecated

Reputation: 5242

How limited is recur?

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?

Upvotes: 5

Views: 273

Answers (2)

ivant
ivant

Reputation: 3919

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

Upvotes: 2

Arthur Ulfeldt
Arthur Ulfeldt

Reputation: 91554

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.

Upvotes: 1

Related Questions