r/Python • • Jul 13 '11

An alternative lambda syntax for Python

http://vocalbit.com/article/332/an-alternative-lambda-syntax-for-python
4 Upvotes

41 comments sorted by

View all comments

10

u/ndanger Jul 13 '11 edited Jul 13 '11

I agree with vph: this takes a general concept (lambda) and makes it a strange special case.

I'm not a fan of the proposed syntax either:

f(key=lambda x:...)

makes it clear that you are setting key to a function,

f(key(x)=...)

makes it look like you are setting a function of key to a value.

1

u/vocalbit Jul 14 '11

lambda itself is a strange special case of def. Specifically you can use a lambda if you have:

def <foo>(<args>):
     return <expr>

Unfortunately the special lambda syntax can be used in far more places than it should be used. I'm merely specializing the syntax further and restricting where it can be used. There are other examples of syntax that is only valid within the argument list (e.g. **kw)

1

u/aaronla Jul 14 '11

lambda itself is a strange special case of def

They should totally fix that, and support arbitrary statements in lambdas.

Also, you got it backwards -- def is a special case of statement-supporting lambdas combined with assignment:

<foo> = <lambda expression>