[Python-Dev] replacing 'global'
Skip Montanaro
skip at pobox.com
Sun Oct 26 05:42:07 EST 2003
Just> How about adding a "rebinding" operator, for example spelled ":=":
Just> a := 2
Just> It would mean: bind the value 2 to the nearest scope that defines
Just> 'a'.
I see a couple problems:
* Would you be required to use := at each assignment or just the first?
All the toy examples we pass around are very simple, but it seems that
the name would get assigned to more than once, so the programmer might
need to remember the same discipline all the time. It seems that use
of
x := 2
and
x = 4
should be disallowed in the same function so that the compiler can
flag such mistakes.
* This seems like a statement which mixes declaration and execution.
Everyone seems to abhor the global statement. Perhaps its main saving
grace is that it doesn't pretend to mix execution and declaration.
I think to narrow the scope of possible alternatives it would be helpful to
know if what we're looking for is a way to allow the programmer only bind in
the nearest enclosing scope or if she should be able to bind to an arbitrary
enclosing scope. The various ideas seem to be falling into those two
categories. Guido, do you have a preference or a pronouncement on that
idea? Knowing that would eliminate one category of solutions.
Skip
More information about the Python-Dev
mailing list