What is "lambda x=x : ... " ?

kirby.urner at gmail.com kirby.urner at gmail.com
Thu Jan 10 13:38:30 EST 2008


You're talking about syntax from the bad old days
when the scope rules were different.

If not too archeological for your tastes, download
and boot a 1.5 and see what happens.

Less empirically, here're some key references:
http://www.python.org/doc/2.2.3/whatsnew/node9.html
http://www.python.org/dev/peps/pep-0227/

The change came in 2.2 with from __future__ support
in 2.1.

Kirby
4D


On Jan 10, 11:25 am, "zsl... at gmail.com" <levili... at gmail.com> wrote:
> I'm reading this page:http://www.ps.uni-sb.de/~duchier/python/continuations.html
> and I've found a strange usage of lambda:
>
> ####################
> Now, CPS would transform the baz function above into:
>
> def baz(x,y,c):
>         mul(2,x,lambda v,y=y,c=c: add(v,y,c))
>
> ###################
>
> What does "y=y" and "c=c" mean in the lambda function?
> I thought it bounds the outer variables, so I experimented a little
> bit:
>
> #################
> x = 3
> y = lambda x=x : x+10
>
> print y(2)
> ##################
>
> It prints 12, so it doesn't bind the variable in the outer scope.




More information about the Python-list mailing list