Yes, it is lexically scoped. The weird part is that I can't know by reading counter1 and counter2 whether they share a counter i. That depends on global properties of the file.
I can't think of any other language where I would not be able to determine this from the presence or absence of a variable declaration inside counter1 and counter2. (I don't know Ruby, perhaps it is weird in the same way.)
Python classes work this way. Broadly, you'll get some variant of this in any language that has nested scopes and uses the same syntax for definition and reassignment.
As I said in another comment, I think the weirdness here is not so much in the scoping rules, but in the ambiguity of the = operator.
View all comments
Show parent comment
4
u/rwbarton Jul 26 '13
Yes, it is lexically scoped. The weird part is that I can't know by reading
counter1andcounter2whether they share a counteri. That depends on global properties of the file.I can't think of any other language where I would not be able to determine this from the presence or absence of a variable declaration inside
counter1andcounter2. (I don't know Ruby, perhaps it is weird in the same way.)