[Python-Dev] Proper tail recursion
Andrew Koenig
ark-mlist at att.net
Fri Jul 16 00:14:15 CEST 2004
> So let's optimize tail calls, but for each elided one we'll allocate a
> record containing a pointer to its caller, the line number of the
> optimized tail call, and the bindings of locals. It will look pretty
> much exactly like a frame object looks today, but we won't *call* it a
> frame object, and then everyone will be happy <wink>.
Especially because if we allocate such objects in the same way as we
allocate other objects, we no longer need to have an upper bound on the
number of such objects that can exist at one time.
For that matter, perhaps we could make such objects explicitly accessible by
user programs. If we did that, of course, we would not want to restrict
such objects to the ones that correspond to tail calls--we might as well
create them for all calls. We might even make it possible to "call" such an
object, the effect of which would be to cause execution to continue from the
state it was in when that object was created. Gee, once we do that, we
don't need to keep that information around on the stack any more at all.
I guess we need a catchy name for such objects. Because we can use them to
make execution continue from an arbitrary point, how about calling such an
object a "continuation?" <very big wink>
More information about the Python-Dev
mailing list