A critic of Guido's blog on Python's lambda

Alex Martelli aleaxit at yahoo.com
Sun May 7 14:57:58 EDT 2006


Frank Buss <fb at frank-buss.de> wrote:

> Alex Martelli wrote:
> 
> > I cannot conceive of one.  Wherever within a statement I could write the
> > expression
> >     lambda <args>: body
> > I can *ALWAYS* obtain the identical effect by picking an otherwise
> > locally unused identifier X, writing the statement
> >     def X(<args>): body
> > and using, as the expression, identifier X instead of the lambda.
> 
> This is true, but with lambda it is easier to read:
> 
> http://www.frank-buss.de/lisp/functional.html
> http://www.frank-buss.de/lisp/texture.html
> 
> Would be interesting to see how this would look like in Python or some of
> the other languages to which this troll thread was posted :-)

Sorry, but I just don't see what lambda is buying you here.  Taking just
one simple example from the first page you quote, you have:

(defun blank ()
  "a blank picture"
  (lambda (a b c)
    (declare (ignore a b c))
    '()))

which in Python would be:

def blank():
    " a blank picture "
    return lambda a, b, c: []

while a named-function variant might be:

def blank():
    def blank_picture(a, b, c): return []
    return blank_picture

Where's the beef, really?  I find the named-function variant somewhat
more readable than the lambda-based variant, but even if your
preferences are the opposite, this is really such a tiny difference that
I can't see why so many bits should gets wasted debating it (perhaps
it's one of Parkinson's Laws at work...).


Alex



More information about the Python-list mailing list