[Python-Dev] statically nested scopes
Guido van Rossum
Thu, 02 Nov 2000 02:59:55 -0500
> Don't know if you saw the discussion in the PEP or not.
Sorry, I had no time. I have read it now, but it doesn't change my
point of view.
> I made two
> arguments for being able to assign to variables bound in enclosing
> 1. Every other language that supports nested lexical scoping allows
> this. To the extent that programmers have seen these other
> languages, they will expect it to work.
But we have a unique way of declaring variables, which makes the
Your PEP wonders why I am against allowing assignment to intermediate
levels. Here's my answer: all the syntaxes that have been proposed
to spell this have problems. So let's not provide a way to spell it.
I predict that it won't be a problem. If it becomes a problem, we can
add a way to spell it later. I expect that the mechanism that will be
used to find variables at intermediate levels can also be used to set
them, so it won't affect that part of the implementation much.
> 2. It is possible to work around this limitation by using containers.
> If you want to have an integer that can be updated by nested
> functions, you wrap the interger in a list and make all assignments
> and references refer to list. It would be unfortunate if
> programmers used this style, because it is obscure. I'd rather see
> the language provide a way to support this style of programming
I don't expect that programmers will use this style. When they have
this need, they will more likely use a class.
--Guido van Rossum (home page: http://www.python.org/~guido/)