|
|
|
|
|
by jerf
5041 days ago
|
|
That makes no sense at all. The lambda complaint is mostly a syntax complaint, it is not a complaint about not having anonymous functions. It even has the ability to invoke __call__ on instances, allowing you to create your own "functions" that are actually objects, if you like, which is somewhat unusual. There's no point in having an anonymous function decorator. You'd simply inline it into the body itself right on the spot, anything else would simply be obfuscation for the sake of obfuscation. This only makes sense if you're using a decorator applied elsewhere, at which point all languages require you to have named it, so there's no point complaining about lack of anonymous functions here. Python has first-class functions. It even has first-class methods, with automatic instance binding. It just doesn't quite work how very functionally-oriented people want it to work. Part of the reason I don't like the kvetching that such people do is that it does seem to convince people that Python is lacking function references. Nope. It just doesn't spell them to everybody's taste (for instance, "it doesn't have Ruby blocks" translates to "it doesn't have block syntax", not "it can't do function references", and this is a taste issue not a fundamental capability issue), and the can rarely have moderately inconvenient scope rules if you want to write to outer scopes. Decorators are syntax sugar, not a new feature. |
|
https://en.wikipedia.org/wiki/Python_syntax_and_semantics#Fi...
What I was speaking to is the desire to write:
My understanding is that Python doesn't like two different things about this. First, the multi-line anonymous lambda being used as the target of the decorator. Second, a function being called with another function as its argument as an expression within an instance method definition.I'm open to reëducation.