[Python-ideas] Explicit variable capture list

Steven D'Aprano steve at pearwood.info
Wed Jan 27 20:06:03 EST 2016


On Wed, Jan 27, 2016 at 12:49:12PM -0800, Andrew Barnert via Python-ideas wrote:

> > The for-loop is a special case, because it assigns a
> > variable in a place where we can't capture it in a
> > let-block. So we introduce a variant:
> > 
> >  for let x in things:
> >    funcs.append(lambda: process(x))
> 
> This reads weird to me. I think it's because I've been spending too 
> much time in Swift, but I also think Swift may have gotten things 
> right here, so that's not totally irrelevant.

It reads weird to me too, because "for let x in ..." is just weird. It's 
uncanny valley for English grammar: at first glance it looks like valid 
grammar, but it's not.


[...]
> As I've mentioned before, both C# and Ruby made breaking changes from 
> the Python behavior to the Swift behavior, because they couldn't find 
> any legitimate code that would be broken by that change.

I'm not sure if you intended this or not, but that sounds like "they 
found plenty of code that would break, but decided it wasn't legitimate 
so they didn't care".


-- 
Steve


More information about the Python-ideas mailing list