Syntax for one-line "nonymous" functions in "declaration style"
Alexey Muranov
alexey.muranov at gmail.com
Thu Mar 28 12:29:30 EDT 2019
On jeu., Mar 28, 2019 at 5:00 PM, python-list-request at python.org wrote:
>
> So my opinion is that lambda expressions should only be used within
> larger expressions and never directly bound.
>
>> It would be however more convenient to be able to write instead just
>>
>> f(x) = x*x
>
> Given my view above, this is, standing alone, strictly an
> abbreviation of the equivalent def statement. I am presuming that a
> proper implementation would result in f.__name__ == 'f'.
>
No, after some thought, i think it should be an abbreviation of "f =
lambda x: x*x", f.__name__ would still be '<lambda>'.
But i see your point about never assigning lambdas directly, it makes
sense. But sometimes i do assign short lambdas directly to variable.
> Is the convenience and (very low) frequency of applicability worth
> the inconvenience of confusing the meaning of '=' and complicating
> the implementation?
>
>> I do not see any conflicts with the existing syntax.
>
> It heavily conflicts with existing syntax. The current meaning of
> target_expression = object_expression
> is
> 1. Evaluate object_expression in the existing namespace to an object,
> prior to any new bindings and independent of the target_expression.
> 2. Evaluate target_expression in the existing namespace to one or
> more targets.
> 3. Bind object to target or iterate target to bind to multiple
> targets.
I do not thick so. In "x = 42" the variable x is not evaluated.
All examples of the proposed syntax i can think of are currently
illegal, so i suppose there is no conflicts. (I would appreciate a
counterexample, if any.)
Thanks for the reference to PEP 8, this is indeed an argument against.
Alexey.
More information about the Python-list
mailing list