[Python-Dev] any support for a methodcaller HOF? (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Sat Feb 4 13:55:23 CET 2006


Nick Coghlan wrote:

Hell no. If I want to write a real function, I already have perfectly good syntax for that in the form of a def statement. I want to increase the conceptual (and pedagogical) difference between deferred expressions and real functions, not reduce it. There's a reason I try to use the term 'deferred expression' for lambda rather than 'anonymous function'. Even if lambdas are implemented as normal function objects, they're a conceptually different beast as far as I'm concerned - a function is typically about factoring out a piece of common code to be used in multiple places, while a lambda is about defining here and now an operation that is to be carried out elsewhere and possibly later (e.g., sorting and predicate arguments are defined at the call site but executed in the function body, callbacks are defined when registered but executed when the relevant event occurs).

Hmm. A function also defines here and now an operation to be carried out elsewhere and later.

Generator expressions allow a generator to be embedded only if it is simple enough to be written using a single expression in the body of the loop. Lambda does the same thing for functions, but for some reason people seem to love the flexibility provided by genexps, while many think the exact same restriction in lambda is a problem that needs "fixing". Maybe once PEP 308 has been implemented, some of that griping will go away, as it will then be possible to cleanly embed conditional logic inside an expression (and hence inside a lambda).

I believe that usage of a keyword with the name of a Greek letter also contributes to people considering something broken.

Regards, Martin



More information about the Python-Dev mailing list