[Python-ideas] Syntax for late-binding of arguments [was: Default arguments ...]

Steven D'Aprano steve at pearwood.info
Fri May 15 14:11:33 CEST 2009


On Fri, 15 May 2009 08:26:30 pm Nick Coghlan wrote:
> Steven D'Aprano wrote:
> > Some years ago, Python overloaded the binary operators * and ** for
> > use as special markers in parameter lists. I suggest we could do
> > the same, by overloading the & operator in a similar fashion:
> > inside the parameter list, &x would mean to delay evaluation of the
> > default argument:
[...]
> Marking the parameter name strikes me as wrong anyway - it's only the
> evaluation of the default argument which is special, not the
> parameter itself.

But it is the parameter that is special. The default object itself is 
not. Consider the function definition:

def f(x=[], &y=[]):

(or any other syntax you prefer). The empty list you get as the default 
value for x is exactly the same as the empty list you get in y, in 
every way except for identity.



-- 
Steven D'Aprano



More information about the Python-ideas mailing list