|
|
|
|
|
by julian37
5101 days ago
|
|
This is getting a bit tiresome, but I'll play along since your high karma leads me to believe you're genuinely confused and not a troll. The point of anonymous functions is not whether or not they will eventually be bound to an identifier, i.e. what happens with the function later on. The point is terseness in declaration: the ability to avoid having to define a full-blown function for small pieces of code that you want to pass to a higher-order function. In Python, the difference between: def is_not_zero(x): return x != 0
foo = bar.filter(is_not_zero)
and foo = bar.filter(lambda x: x != 0)
The Python language construct for anonymous functions is "lambda". Nothing more, nothing less. Closures don't have anything to do with it, except that of course both named functions and lambdas have closures created when they are referenced.This is my last contribution to this thread. I'm just trying to help clear up an apparent misunderstanding on your part. |
|
Anyways anonymous function syntax is not always terse. So if terseness is the point, then it is a pointless distinction. Consider JavaScript. I am sure that you'd agree that the following is an anonymous function (Wikipedia certainly agrees that it is):
But that is not very terse, is it? Even declaring a named function in Haskell is more terse than that by far. (And that anonymous function could just be: \x y -> x + y) But it is unambiguously an anonymous function syntax.Anyways from the point of view of a programmer, what matters most is what you can say, and then secondly how convenient it is to say it. Anything that you would want to say with anonymous functions, you can say in Python. It will be more verbose by far than a real functional language like Haskell would be. But not really worse than many other scripting languages, like JavaScript.