[Python-3000] Sky pie: a "var" keyword

Ka-Ping Yee python at zesty.ca
Wed Oct 11 11:18:05 CEST 2006


Nick Coghlan wrote:
> Re-using 'global' wasn't popular because it would actually be
> *wrong* for the new semantics

On Wed, 11 Oct 2006, Greg Ewing wrote:
> I don't agree that it's wrong -- it's perfectly
> legitimate to regard "local" and "global" as
> relative terms, i.e. anything not local to you
> is global from your point of view.

It is possible to think of those terms in that way, but in this
context, i disagree.  I don't believe this is what any programmer
means when they say "global variable".

Consider the following example:

    def spam(x):
        def eggs():
            global x
            x = x + 1
        eggs()
        print x

In today's Python, eggs() affects the global variable x; with the
new meaning for "global", it instead affects the x local to spam().

Here are two arguments against redefining the "global" keyword:

1.  Notice that changing "global" to mean "don't create a new binding"
    changes the meaning of the above code incompatibly.

2.  With the new meaning for "global", what is x?  Is x a "global
    variable"?  I just can't imagine calling it that.  It doesn't
    make sense to use the keyword "global" to declare something that
    is clearly not a global variable.


-- ?!ng


More information about the Python-3000 mailing list