[Python-3000] Possible alternative lambda syntax?
Adam Atlas
adam at atlas.st
Sat Jan 13 22:48:49 CET 2007
On 13 Jan 2007, at 12.05, Greg Falcon wrote:
> On 1/13/07, Adam Atlas <adam at atlas.st> wrote:
>> [lambda ideas snipped]
>>
>> Any thoughts on either of these?
>
> Replying privately instead of on the mailing list, because I'm not
> trying to call you out in public or anything like that.
>
> But Guido wrote a great essay that covers what you're suggesting:
> http://www.artima.com/weblogs/viewpost.jsp?thread=147358
>
> Also you should take a look at PEP 3099 before suggesting features for
> Python 3000.
>
> Greg F
(Replying on the mailing list because being called out in public is
fine with me. Especially by the guy who made "Irrational Exuberance"
and "Dash". :P)
Okay, I definitely understand Guido's point about switching to paying
attention to indentation within an expression. I guess that could get
very ugly. My suggestion for (a, b: a+b) syntax still stands; it
seems unambiguous enough that we can simply drop the "lambda" keyword
and the parentheses around the arglist, bringing a syntax that's not
fundamentally very different from the current one, but quicker to
write and visually more elegant and simple.
As for allowing statements in lambdas, how about this -- the part
after the colon can simply be a series of statements (separated by ;,
not multiline). If so, the function is constructed from those
statements, and it's expected to have a 'return' instead of just
having the last statement be an expression. If, rather, the part
after the colon is one expression, then it acts like it does now.
It's minimally obtrusive; it doesn't really use any syntax that
doesn't already exist, it just allows it in a different context.
(Again, apologies if I'm beating a dead horse, or a Dead Parrot as
the case may be, but these ideas don't seem too far-out to me; I
could even try implementing this as a patch for the current Py3K
codebase myself, probably.)
More information about the Python-3000
mailing list