[Python-ideas] Thoughts on lambda expressions

Chris Angelico rosuav at gmail.com
Wed Mar 2 20:20:41 EST 2016


On Thu, Mar 3, 2016 at 11:46 AM, Sjoerd Job Postmus <sjoerdjob at sjec.nl> wrote:
> One thing I do see as being different, is that `def` takes statements,
> not an expression. So, one should write an extra `return` as in
>
>     sorted(datalist, key=def x: return x[5])
>
> (Not requiring `return` here would be very confusing if one were to
> re-use the keyword `def`.)
>
> On the other hand, then one might even do something like
>
>     sock.send_data(data,
>         on_error=def err:
>             some
>             statements
>             handling
>             err
>         ,
>         on_complete=def:
>             draw
>             a
>             kitten
>     )
>

Someone will correct me if I'm wrong, but I'm pretty sure Python's
grammar cannot handle statements inside expressions. Creating a "def"
expression that has a suite inside it would mess with everyone's heads
AND the parser, and I'm pretty sure that one won't fly.

ChrisA


More information about the Python-ideas mailing list