On 25Nov2020 22:07, Guido van Rossum firstname.lastname@example.org wrote:
Hmm... In the end I think the language design issue is with functions (and how they capture variable references rather than values), and fixing it by changing the for-loop is still just a band-aid, with other problems and inconsistencies. Agreed that the fix 'x=x' essentially always works, and that having to write 'for new x in ...' is no better, because you'd still forget it.
Maybe we should consider introducing a new kind of function that captures values instead? That would be a much more principled fix.
I was thinking in my previous post (where such thought was off topic:-) that block scopes for Python should be as clear as in C, without using braces.
What about something along the lines of:
with expression as new x, y: ... x and y local to this suite ... ... also x and y cannot shadow existing names ...
I wouldn't want to let any "as" support a "new", but the one on "with" introduces a suite which nicely delineates a block.
Cheers, Cameron Simpson email@example.com