PEP 318 - Function Modifier Syntax
Beni Cherniavsky
cben at techunix.technion.ac.il
Mon Jun 9 11:59:12 EDT 2003
Duncan Booth wrote on 2003-06-09:
> You need to say what order the modifiers are applied when there is
> more than one. Specifically is it left to right, or right to left?
>
> I wonder what the implementation of this should be. Should the
> bytecode that is produced implement a loop over the modifiers
> directly, or should there be a new builtin that takes the function
> and the modifiers as arguments and the bytecode simply has to call
> the function and assign its result to the name? The second of these
> sounds as though it ought to be simpler to implement.
>
In the latter case you don't need new builtins at all. Just
compile::
def spam() [foo, bar]:
pass
exactly as::
def spam():
pass
spam = foo(spam)
spam = bar(spam)
The limitation for avoiding a loop is that the individual expressions
of the items should be known when compiling. You can always allow the
generic case with a loop and consider this purely an optimization.
I wrote the last lines this way rather than::
spam = bar(foo(spam))
to emphasize the order. IMO since they are written at the end of the
line, the only sensible order is applying them left-to-right. This is
like postfix (reverse polish) notation: the outermost application is
written last.
--
Beni Cherniavsky <cben at users.sf.net>
More information about the Python-list
mailing list