[Python-ideas] For-loop variable scope: simultaneous possession and ingestion of cake
george.sakkis at gmail.com
Sat Oct 4 16:42:20 CEST 2008
On Sat, Oct 4, 2008 at 10:18 AM, Terry Reedy <tjreedy at udel.edu> wrote:
Greg Ewing wrote:
> tement, which will be familiar to nobody.
>> It's true that with a 'let' statement or equivalent,
>> there's no strict need for a change to the for-loop,
>> since you can always say
>> for i in range(10):
>> let i = i:
>> funcs.append(lambda: i)
>> But it's an annoying and odd-looking piece of
>> boilerplate to have to use, and in that respect is
>> similar to the existing solutions of inserting another
>> lambda or using a default argument value.
>> So as a *convenience*, I'm suggesting that the
>> for-loop be given automatic let-like behaviour.
> Whereas I consider the proposed automaticity to be a grave inconvenience
> and confusion factor. What if I *want* a closure to be over variables, as
> normal, instead of values.
Why would you want that for a loop variable ? Can you give an example where
this would be the desired behavior ?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas