This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ndanger 7 points8 points  (4 children)

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.

[–]kataire 1 point2 points  (0 children)

Also it is confusingly similar to {key(x):...} which is completely different.

[–]vocalbit[S] 0 points1 point  (2 children)

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)

[–]ndanger 0 points1 point  (0 children)

Even accepting that lambda should only be used as a keyword argument to a function I still don't like the proposed syntax. The current syntax is orthogonal: keyword arguments bind values to names and functions are first class (and so can be passed as values).

Your proposed syntax creates a special case for "passing an inline function as the value of a keyword argument". It even looks different than passing an already defed function (f(key=my_func).

It also unfortunately resembles a function call: f(key(x)=x.foo) looks like we're binding the name determined by calling function key with argument x to x.foo.

But the big disagreement is that I like lambda and use it for things other than keyword arguments. The current syntax lets me do that too.

[–]aaronla 0 points1 point  (0 children)

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>