[Python-ideas] A Continuations Compromise in Python

Arnaud Delobelle arnodel at googlemail.com
Sun May 3 19:42:20 CEST 2009


2009/5/3 Stephen J. Turnbull <stephen at xemacs.org>:
> Greg Ewing writes:
>
>  > It's also by no means certain that TCO would provide the
>  > kind of speed benefit that people imagine. A lot of the
>  > overhead of making a Python function call is concerned
>  > with packing up the arguments and unpacking them again,
>  > which you still need to do even if you're reusing the
>  > stack frame.
>
> I thought that was a good part of the appeal of TCO, though, that the
> compiler can often arrange to do data manipulations in such a way that
> the stack frame (or even data-in-register) is just there, ready to go
> when control is transferred.  Ie, the packing/unpacking that is purely
> related to function calling is avoided.  Is this a difficulty in
> implementing for Python, or did I misunderstand the concept?

This can be done with recursive tail calls, but I guess that in
Python, in general, the compiler is not able to know whether a tail
call is actually calling the function currently being executed, as the
compiler only knows it calls a function with a given name (which is
only bound to an object at runtime).  However, I think that the
interpreter would be able to decide this at run time - and even to
short-circuit the packing/unpacking sequence of parameters.

-- 
Arnaud



More information about the Python-ideas mailing list