Securing a future for anonymous functions in Python
jeff at ccvcorp.com
Fri Dec 31 00:15:51 CET 2004
David Bolen wrote:
>>I think this specific use case -- defining callbacks -- should be
>>addressed, rather than proposing a solution to something that isn't
>I'd be interested in this approach too, especially if it made it simpler
>to handle simple manipulation of callback arguments (e.g., since I often
>ignore a successful prior result in a callback in order to just move on
>to the next function in sequence).
It seems to me that what most people *actually* want, when asking for
lambdas, is a quicker and more convenient way to get closures. (At
least, that's what the vast majority of examples of lambda use seem to
be for.) Perhaps one could get a bit more traction by looking for
improved closure syntax instead of focusing on the anonymous function
All of the suggestions for anonymous multiline functions (with embedded
indentation) seem to me to miss what seems to me to be the only
significant benefit of lambda -- its ability to be used in-line without
creating a huge ugly tangle. (I'd argue that lambdas create a *small*
ugly tangle, but apparently that's just me. ;) ) Lambdas do have some
value in defining callbacks, but that value derives almost exclusively
from the fact that they are in-line (rather than a few lines above).
Mimicking function-def indentation inside of another function's arglist
strikes me as an abomination just waiting to happen; in comparison, the
need to type a name twice seems trivial.
As a result, it seems to me that, rather than generalize lambdas into
"full" anonymous functions (with most of the negatives and few of the
positives of lambda), it would be much better to specialize them further
into inline-closure-creators, where they can serve a valuable purpose
without quite as much risk of code pollution.
More information about the Python-list