[Python-ideas] Proposal for function expressions

Carl Johnson cmjohnson.mailinglist at gmail.com
Wed Jul 15 07:51:07 CEST 2009


George Sakkis wrote:

> Seconded, there's too much going on ('&', what's "do", a function ?,
> what's "item" ?, etc.). FWIW the only readable suggestion for
> multiline lambdas with almost zero learning curve I have seen is the
> one implemented in Boo, anonymous def and regular indentation:
>
> y = sorted(x, key=def (item):
>                               name = item.split('-')[1]
>                               return name.upper()
>               )

FWIW, I find that completely ugly and non-Python-esque (unpythonic
being perhaps too strong of criticism). :-D

Clearly this is an issue which has a lot of good arguments on both
sides, and since the final metric has to be "readability of code" it's
going to hard to make a knock-down argument for one side or the other.
I'm fine with the status quo for now: in Guido's gut we trust.

My suggestion for future would be language extenders is that they try
to solve a broader problem than just the "how do I make callbacks more
convenient" problem. Just solving that one problem by itself seems
unlikely to make it into the language, since it is pure "sugar" and
Pythoneers have a well justified wariness toward anonymous functions
(why not just name them and be done with it?). Perhaps someone should
take a look at the original "with" proposal, or some of the various
"do" and "block" proposals. One idea I think about sometimes is having
a more convenient way to do something along the lines of
metaclass.__prepare__ but for functions…

-- Carl Johnson



More information about the Python-ideas mailing list