Alternative to multi-line lambdas: Assign-anywhere def statements

Ian Kelly ian.g.kelly at gmail.com
Wed Feb 11 21:57:20 EST 2015


On Wed, Feb 11, 2015 at 7:06 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> I can't see why the parser would understand more easily
>>
>> def f(x):
>>      return x**2
>> than
>>
>> f = x->
>>      return x**2
>
>
> The parser parses both equally well.  That is not the issue.

The compiler could at some point recognize that the function is being
assigned to a simple name and transform the assignment into a def for
purposes of byte code generation. It could also do the same with
lambda, although it currently doesn't.

The reason I don't like this replacing def isn't because the name is
necessarily lost. It's because the lack of the well-defined def
statement encourages more complex usages like

    functions['f'] = x -> x**2

where such implicit transformations won't work.



More information about the Python-list mailing list