[Python-Dev] Proper tail recursion

Greg Ewing greg at cosc.canterbury.ac.nz
Fri Jul 16 05:55:32 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.

We could get the benefits of that just by eliminating recursive calls
to ceval() when a Python function calls a Python function. I think
that would be a worthwhile thing to do on its own, because it would
mean recursion in pure Python would be limited only by available
memory and not an arbitrary recursion limit, which has always seemed
like a kludge to me.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list