On Aug 3, 2:19 am, Daniel Kersten <dkers...@gmail.com> wrote:
> Can one not detect that a recursive call is a tail call and then transform
> the AST so that its iterative instead - ie, not use the stack besides for
> initial setup of local variables (which then get reused in each recursive
> tail-call). Isn't this how its done in native compiled languages with TCO?
> How is this different from generating bytecode for iterative loops in
> imperative languages, or from what recur does? Alternatively, why can't the
> tail call be detected and converted into recur? I'm guessing that the
> problem is detecting tal calls - but why; speed of dynamic compilation?
> Something else?
>
> Obviously I'm missing something fundamental here - can somebody explain to
> me what it is?
>

When speaking about general TCO, we are not just talking about
recursive self-calls, but also tail calls to other functions. Full TCO
in the latter case is not possible on the JVM at present whilst
preserving Java calling conventions (i.e without interpreting or
inserting a trampoline etc).

While making self tail-calls into jumps would be easy (after all,
that's what recur does), doing so implicitly would create the wrong
expectations for those coming from, e.g. Scheme, which has full TCO.
So, instead we have an explicit recur construct.

Essentially it boils down to the difference between a mere
optimization and a semantic promise. Until I can make it a promise,
I'd rather not have partial TCO.

Some people even prefer 'recur' to the redundant restatement of the
function name. In addition, recur can enforce tail-call position.

Rich

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to