On Tue, Mar 10, 2009 at 7:44 PM, Jim Jewett <jimjjewett@gmail.com> wrote:
When someone says they need anonymous functions, I hear:
"I really, really *need* the __name__ to be useless!"
I think you need your hearing tuned. By convention anonymous functions and expressions creating functions are almost always synonymous, in almost all languages. So people use the shorter term "anonymous functions" when what they really care about is "expression syntax for creating new functions on the fly".
I don't see the conceptual difference between a "def-expression" (if it were syntactically possible) and a lambda-expression. What is the difference in your view?
The only differences *I* see are syntactical warts in lambda.
Well, those have been discussed at length and depth, and nobody has come up with an acceptable syntax to embed a block of statements in the midst of an expression, in Python. That's why they are separate.
The __name__ is available in case you want to use it for a dispatch table, or to populate fields in an alternative User Interface. (For example, accessibility APIs)
When people want the name, they can give it a name using a def statement. I don't accept your argument against that which seems to go along the lines of "but maybe they might want the name later". You can write unreadable code without lambda too. And yes, lambda can be abused; for a really evil example see this recipe: http://code.activestate.com/recipes/148061/ (note the mis-use of the term "one liner" :-). -- --Guido van Rossum (home page: http://www.python.org/~guido/)