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

Mike Meyer mwm at mired.org
Thu Jan 10 13:43:35 EST 2008


On Thu, 10 Jan 2008 10:25:27 -0800 (PST) "zslevi at gmail.com" <levilista 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?

Older versions of python didn't make variables in an outer scope
visible in the inner scope. This was the standard idiom to work
around that.

       <mike
-- 
Mike Meyer <mwm at mired.org>		http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.



More information about the Python-list mailing list