[Python-ideas] Thoughts on lambda expressions

Paul Moore p.f.moore at gmail.com
Thu Mar 3 04:15:52 EST 2016


On 3 March 2016 at 00:00, Mike Miller <python-ideas at mgmiller.net> wrote:
> On 2016-03-02 15:03, Paul Moore wrote:
>>
>> PS For the record, I dislike the lambda syntax intensely - the odd
>> keyword, the fact that "lambda" is sometimes almost as long as than
>> the expression I'm using, the use of the mid-line colon which is hard
>> to spot, ... So in principle I'm inclined to support "improvement"
>
>
> Hmm, can't think of a way to get rid of the colon without it looking like a
> generator, but perhaps we could tackle the other issues by letting "def"
> stand in for "lambda":
>
>         lambda x: x.y
>
>         def x: x.y
>
> It's shorter, not an esoteric word, and is analogous to a named function
> definition, reminiscent of javascript.  The lack of name/parens separates it
> from the standard form.  Doable, but of course its pretty late in the game
> to be changing lambda, perhaps in Python 4?

To reinstate the context: even though I dislike the lambda syntax, in
general I *don't* want it "improved" - instead I want a move away from
needing it. Things that help:

1. Encouraging the community to appreciate that throwaway named
function definitions are an acceptable approach.
2. Specialised syntax or (possibly 3rd party) modules for handling the
common cases - the fn.py module sounds like a good example for
handling simple expressions.

I think we should keep lambda syntax for the relatively few cases
where it would remain the best option, but I don't think it needs to
be changed - if nothing else the backward compatibility issues would
be too great.

Paul


More information about the Python-ideas mailing list