Of what use is 'lambda'???

Erik Max Francis max at alcyone.com
Sun Sep 24 23:52:39 EDT 2000


Jonadab the Unsightly One wrote:

> Encapsulation arguments never win any points with me.

I guess you don't like object orientation, then.

> If
> the user shouldn't call it, just give it the docstring
> "internal function", but frankly I've not infrequently found
> myself legitimately calling code that the author considered
> to be internal and thought I shouldn't call.

The option is between simply using an anonymous, local function,
eliminating any such issue, or going through the trouble of choosing a
name for the function, entering it in a module namespace, and
documenting it as undocumented and not for public use.  Save the
keystrokes.

> The map/mapcar argument I still can't argue against,
> because I have no experience with map/mapcar.

I think that's the issue here.  If you're not familiar with map and
reduce (in Python), which lambdas are often perfect for, it doesn't make
much sense.  lambda functions are often created for tasks where there
really is _no_ use in calling the anonymous function outside of that
context, not because there's the danger of someone using an internal
function and corrupting things, but rather a special-purpose, one-time
function is required for a map/reduce operation that has no meaning or
usefulness outside of the local context.  That's what lambda is for; for
functions that not only don't _need_ a name, but for functions for which
giving a name to and making available to others would be a total waste
of time.

You might want to check out the uses of map and reduce in your favorite
Python book for more information.  It is curious that you're objecting
to the use of lambdas but are explicitly stating that you're with the
functional language features of Python which is what make them useful.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ We learn from history that we do not learn from history.
\__/ Georg Friedrich Wilhelm Hegel
    Official Buh rules / http://www.alcyone.com/max/projects/cards/buh/
 The official rules to the betting card game, Buh.



More information about the Python-list mailing list