PEP 312 - Making lambdas implicit worries me, surely it's just the name 'lambda' that is bad...

Stephen Horne intentionally at
Tue Mar 11 03:43:00 CET 2003

On Tue, 11 Mar 2003 13:42:54 +1300, "Greg Ewing (using" <me at> wrote:

>Andrew Koenig wrote:
>> For that reason, although I wouldn't mind having a more compact way of
>> writing lambda-expressions, I don't think that the colon syntax is
>> the best way to do it.
>How about
>    (a, b) -> expr

I see what you're getting at. I'd certainly prefer it to the existing
PEP312 suggestion. I could even imagine putting the name back on the
front as a shorthand for short named functions that don't need
imperative statements - giving a syntax which is almost identical to
the math notation...

  f (a, b) -> expr

But there is, IMO, still a clarity issue. Apart from people who use
the math notation every day, I suspect most people won't find the
meaning of this notation obvious. Also, the leading part describing
the formal parameters looks a lot like (in most cases, exactly like) a
tuple until you reach that operator.

In other words, this could be a bit confusing.

In general, I like all but the most obvious constructs to have a
leading keyword - even if it's an abbreviation - because as a last
resort the reader can always look up that keyword to find an
explanation of the syntax and what it means.

Your idea isn't necessarily bad - the '->' operator is at least a
unique symbol rather than a reuse of existing symbols, and the syntax
has a clear basis outside of the limits of Python programming - it's
just that it still makes me slightly nervous.

Of course, I could just be rationalising to cover up my "it's new"
syndrome ;-)

More information about the Python-list mailing list