[Python-ideas] And now for something completely different
cliff at develix.com
Thu Sep 18 08:01:59 CEST 2008
On Wed, 2008-09-17 at 23:54 -0400, Terry Reedy wrote:
> Cliff Wells wrote:
> > You can accomplish this to some degree by using lambda,
> You can do it completely as far as I know.
> > but I'd much prefer something indicated in the function signature
> > than in the calling code.
> Given Python's nature as a compiled dynamic language, indications are
> really needed in both caller and callee, as at present: pass a function
> and call it. Without an explicit indication at the call site, the
> compiler would have to compile both direct evaluation and function
> object creation and the code to select between them at runtime according
> to an attribute of the function resulting from evaluation of the
> presumed function expression. This would slow *all* function calls,
> which are slow enough already. Also, one could not tell what objects
> get passed to a function without knowing the signature in detail, making
> code harder to read.
There's one other approach: have two types of functions: <function> and
<function-with-lazy-args>. Whenever Python encounters a declaration of
a function with a lazy argument it creates the latter. This would allow
Python to know at runtime how to handle it. The difference could be
transparent to user code (although it might be unappealing to disguise
such a difference).
More information about the Python-ideas