[Python-ideas] Default arguments in Python - the return - running out of ideas but...
Terry Reedy
tjreedy at udel.edu
Wed May 13 23:58:46 CEST 2009
MRAB wrote:
> There's the suggestion that Carl Johnson gave:
>
> def myfunc(a, b, c else []):
> pass
>
> or there's:
>
> def myfunc(a, b, c def []):
> pass
>
> where 'def' stands for 'default' (or "defaults to").
I had the idea of def f(c=:[]): where ':' is intended to invoke the idea
of lambda, since the purpose is to turn the expression into a function
that is automatically called (which is why lambda alone is not enough).
So I would prefer c = def [] where def reads 'auto function defined
by...'.
or c = lambda::[] where the extra ':' indicates that that the function
is auto-called
or c = lambda():[], (now illegal), where () is intended to show that the
default arg is the result of calling the function defined by the
expression. lambda:[]() (now legal) would mean to (uselessly) call the
function immediately.
Thinking about it, I think those who want a syntax to indicate that the
expression should be compiled into a function and called at runtime
should build on the existing syntax (lambda...) for indicating that an
expression should be compiled into a function, rather than inventing a
replacement for that.
Terry Jan Reedy
More information about the Python-ideas
mailing list