PEP 312 - Making lambdas implicit worries me, surely it's just the name 'lambda' that is bad...

Thomas Bellman bellman at lysator.liu.se
Wed Mar 12 11:19:47 EST 2003


"Daniel Dittmar" <daniel.dittmar at sap.com> writes:

> coming from Smalltalk:
> Python lambdas are restricted to one expression, which makes them cumbersome
> to use for more complex stuff and difficult to debug as you can't insert a
> quick 'print'.

They also execute in their own namespace, with their own local
variables.  From what I understand, code blocks in Smalltalk
execute in the same namespace/scope as the surrounding code, and
cam thus bind variables in the surrounding code.  Even if lambdas
in Python were not restricted to expressions, the following
would still just print "17":

    def select(n, *blocks):
	blocks[n]()

    x = 17
    select(1, lambda: x=23, lambda: x=69, lambda: x=4711)
    print x


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"You cannot achieve the impossible without   !  bellman @ lysator.liu.se
 attempting the absurd."                     !  Make Love -- Nicht Wahr!




More information about the Python-list mailing list