[Python-ideas] a new lambda syntax

Nick Coghlan ncoghlan at gmail.com
Tue Oct 20 00:00:14 CEST 2009

Masklinn wrote:
> On 19 Oct 2009, at 22:50 , Ben Finney wrote:
>> starwing <weasley_wx at qq.com> writes:
>>> Oleg Broytman 写道:
>>>> Single-line lambdas are good enough, and if you need more - just
>>>> create a named function.
>>> BUT, why we need a name? just to process something or make decide,
>>> sometimes code itself is enough.
>> When the code is more complex than a single expression, it's already
>> complex enough that defining it first and then referring to it makes for
>> clearer code.
> That sounds quite recursive. Is it a hard rule or are you allowed to
> write three consecutive statements or expressions in some cases?

The difference lies largely in whether or not you are bundling up that
code and giving it to another piece of code to use.

For myself, I don't actually agree it's a valid design rule - I think
anonymous blocks have legitimate use cases (see Ars Technica's writeup
of the Apple's new Grand Central Dispatch and C-level anonymous block
system in OS X 10.6).

However, for Python, the idea of having anonymous blocks runs headlong
into the use of indentation for block delineation. You have to either
come up with a non-indentation based syntax for the statements inside
the anonymous blocks, essentially inventing a whole new language, or you
have to embed significant whitespace inside an expression rather than
only having it between statements.

Nobody has come up with a solution to that mismatch which is superior to
just naming the block and using a normal def statement to create it.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list