[Python-ideas] Default arguments in Python - the return - running out of ideas but...

spir denis.spir at free.fr
Wed May 13 12:38:09 CEST 2009


Le Wed, 13 May 2009 16:34:02 +0900,
"Stephen J. Turnbull" <stephen at xemacs.org> s'exprima ainsi:

> I
> also see the elegance and coherence of Tennessee's proposal to
> *always* dynamically evaluate, but I don't like it.  Given that always
> evaluating dynamically is likely to have performance impact that is as
> surprising as the behavior of "def foo(bar=[])", I find it easy to
> reject that proposal on the grounds of "although practicality beats
> purity".

I do not understand why defaults should be evaluated dynamically (at runtime, I mean) in the proposal.

This can happen, I guess, only for default that depend on the non-local scope:

def f(arg, x=a):
   <body>

If we want this this a changing at runtime, then we'd better be very clear and explicit:

def f(arg, x=UNDEF):
   # case x is not provided, use current value of a
   if x is UNDEF: x = a
   <body>

(Also, if x is not intended as a user defined argument, then there is no need for a default at all. We simply have a non-referentially transparent func.)

Denis
------
la vita e estrany



More information about the Python-ideas mailing list