Simple tail calls
David-Sarah Hopwood
david.hopwood at industrial-designers.co.uk
Sat Dec 6 18:26:36 PST 2008
Michael Day wrote:
> Hi Mike,
>
>> What about
>>
>> function f()
>> {
>> try {
>> return g();
>> } finally { h(); }
>> }
>
> Good point! Is there any solution other than to say that try { }
> disables tail calls?
try blocks generally disable tail-call optimization in other language
implementations.
> It seems that the h() inside the finally could be return h(), which
> would make it a tail call.
Yes, but 'return g();' still wouldn't be.
>> function f()
>> {
>> with (o)
>> return g();
>> }
>
> Okay, so the with statement modifies the scope chain, which must be
> undone after the call to g(). Off the top of my head, I would say that
> this should still be a tail call unless enough implementers complain :)
Probably not worth the hassle given the usage frequency of 'with'.
--
David-Sarah Hopwood
More information about the Es-discuss
mailing list