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

Steve R. Hastings steve at hastings.org
Sat May 6 05:56:03 CEST 2006

On Fri, 05 May 2006 21:16:50 -0400, Ken Tilton wrote:
> The upshot of 
> what he wrote is that it would be really hard to make semantically 
> meaningful indentation work with lambda.

Pretty much correct.  The complete thought was that it would be painful
all out of proportion to the benefit.

See, you don't need multi-line lambda, because you can do this:

def make_adder(x):
    def adder_func(y):
        sum = x + y
        return sum
    return adder_func

add5 = make_adder(5)
add7 = make_adder(7)

print add5(1)  # prints 6
print add5(10)  # prints 15
print add7(1)  # prints 8

Note that make_adder() doesn't use lambda, and yet it makes a custom
function with more than one line.  Indented, even.

You could also do this:

lst = []  # create empty list
def f(x):
    return x + 5
del(f)  # now that the function ref is in the list, clean up temp name

print lst[0](1)  # prints 6

Is this as convenient as the lambda case?

lst.append(lambda x: x + 7)
print lst[1](1)  # prints 8

No; lambda is a bit more convenient.  But this doesn't seem like a very
big issue worth a flame war.  If GvR says multi-line lambda would make
the lexer more complicated and he doesn't think it's worth all the effort,
I don't see any need to argue about it.

> But the key in the whole thread is simply that indentation will not 
> scale. Nor will Python.

This is a curious statement, given that Python is famous for scaling well.

I won't say more, since Alex Martelli already pointed out that Google is
doing big things with Python and it seems to scale well for them.
Steve R. Hastings    "Vita est"
steve at hastings.org    http://www.blarg.net/~steveha

More information about the Python-list mailing list