[Python-ideas] For-loop variable scope: simultaneous possession and ingestion of cake

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Oct 5 02:38:12 CEST 2008

Terry Reedy wrote:

> Or perhaps a different proposal:
> Def statements close over variables, as currently.
> Lambda expression close over values, as some people seem to expect them 
> to.

I don't think it would be a good idea to make defs and lambdas
have different behaviour, because they're not interchangeable
otherwise. If you're forced to use a def because what you
want can't be done in a lambda, you'd be forced to accept
different binding behaviour as well.

Also, I'm not convinced that people think of defs and
lambdas as differing like that. I suspect that they would
have the same expectation if a def were written inside
the loop instead of a lambda.


More information about the Python-ideas mailing list