[Python-ideas] One more time... lambda function <--- from *** signature def.

Chris Angelico rosuav at gmail.com
Fri Feb 28 18:54:15 CET 2014


On Sat, Mar 1, 2014 at 4:17 AM, Ron Adam <ron3200 at gmail.com> wrote:
> This returns a lambda-like function.
>
>       def star_lambda(***expr): return expr
>
>
> And is used this way...
>
>       result = star_lambda(a * b + c)  # captures expression.
>
>       actual_result = ***result        # *** resolves "result" here!
>

Interesting, but I don't like the way the interpretation of a function
call depends on the target function. With both * and ** notations,
there's absolutely no difference: the function is called with these
positional and those keyword arguments, whether they came from actual
args or from * or ** unpack/repacks; and there's no difference between
a function that collects args with *args,**kwargs and one that
collects them with individual names (or a C-level function that might
do something altogether different). With this proposal, your
star_lambda function's declaration changes the call site - instead of
evaluating a*b+c, it has to construct an anonymous function and pass
it along.

ChrisA


More information about the Python-ideas mailing list