It's heartening to see that lambda functions (once slated to be abolished) have been given a reprieve. Otherwise there would have been no concise way of passing anonymous functions as a data type, and instead of being able to do something like (to quote a rather silly example):
greeters = {
'english' : lambda name: "Hello, %s"%name,
'french' : lambda name: "Bonjour, %s"%name,
'australian' : lambda name: "G'day, %s"%name
}
one would have to take the long way around, doing something like:
def greet_english(name): return "Hello, %s"%name
def greet_french(name): return "Bonjour, %s"%name
def greet_australian(name): return "G'day, %s"%name
greeters = { 'english': greet_english, ... }
And I don't buy the argument that anonymous functions are bad form, and that each chunk of code should have a name that describes what it does. There are many instances where one wants to specify a tiny fragment of code which will fit into a larger mechanism like a small but crucial cog (be it in a function call, a data structure or wherever), without the bureaucratic overhead of giving it a name. Otherwise we may as well be programming in Java or COBOL or some Vogon-designed abomination of a language.
Please keep comments on topic and to the point. Inappropriate comments may be deleted.
Note that markup is stripped from comments; URLs will be automatically converted into links.
http://www.antiwikipedia
Tue Aug 29 23:18:03 2006
Interesting blog! I was curious as to where I could find more of I Want A Hovercraft as their page linked from the wikipedia article you wrote is broken. Thanks!