[Python-ideas] Syntax for passing lambdas to functions
Chris Angelico
rosuav at gmail.com
Thu Feb 27 07:35:19 CET 2014
On Thu, Feb 27, 2014 at 5:16 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
>>It's really a bad idea to have syntax for a "shorter lambda"
>
>>that works here:
>>
>> f(arg=***whatever***)
>>
>>but not in these:
>
> I don't think that's _necessarily_ a problem. After all, it's not a problem that you can filter a for loop in a comprehension but not anywhere else, is it?
I do.
spam = ***whatever1***
***whatever2*** spam ***whatever3***
***whatever2*** (***whatever1***) ***whatever3***
Regardless of the exact values of the whatevers, these should be
equivalent (apart from the fact that the first one forces evaluation
of whatever1, while the second might not). You can't, however, put a
filter onto spam, so that comparison with the comprehension isn't
fair.
There should be absolutely no difference between:
f(arg=***whatever***)
and:
spam=***whatever***
f(arg=spam)
(Okay, okay, the bytecode will differ, and the second one evaluates f
after working out the argument value, and so on. I mean in normal
usage.) Breaking that expectation would confuse a lot of people. It's
problematic because it's still legal - if it threw a SyntaxError, it
would at least be visible, but it doesn't:
spam=fire_the_ducks(42)
f(onclick()=spam)
ChrisA
More information about the Python-ideas
mailing list