proper tail calls

Igor Bukanov igor at mir2.org
Mon Jan 21 10:48:47 PST 2008


On 21/01/2008, Jon Zeppieri <zeppieri at gmail.com> wrote:
> On 1/21/08, Igor Bukanov <igor at mir2.org> wrote:
> > let f2;
> >
> > function f(a)
> > {
> >     f2 = function() { return a; }
> >     goto return g();
> > }
> >
> > function g() {f2 = null; ... }
...
>
> I don't understand your claim.  You're claiming that the "frame of f"
> is "referenced through a global variable"?  Clearly, f2 is the global
> variable, you're referring to.  f2 may be bound to a function value
> that closes over a, which is part of f's activation frame -- or, more
> specifically, part of f's closure environment.  But how would this
> prevent the call to g from being a tail call?  Are you assuming that a
> would be on the stack?  That is not a warranted assumption.

I am saying that even for calls in the tail position an implementation
may not eliminate the parent frame completely as it still may be
exposed via closures. As such the tail call optimization cannot
guarantee that the space complexity of the tail recursion is O(1).

>



More information about the Es4-discuss mailing list