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

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Oct 9 17:01:16 CEST 2006


"Paul Moore" <p.f.moore at gmail.com> writes:

>> 1. The variable is visible from 'var' to the end of the scope.
>>    If 'var' doesn't specify an initial value, accessing the variable
>>    before it gets assigned to is an error.
>>
>> 2. The variable is visible from 'var' to the end of the scope.
>>    If 'var' doesn't specify an initial value, 'None' is used.
>>
>> 3. The variable is visible from the beginning to the end of the scope.
>>    Accessing the variable before the 'var' is executed is an error.
>>    If 'var' doesn't specify an initial value, 'None' is used.
>
> Of these, only (3) specifies what happens if the variable is
> referenced before the 'var' statement.

In (1) and (2) an outer meaning of the variable is used.

> None of them make it clear what the effect of 'var' is in a context
> where an outer (or global) definition of the variable is available.

In all variants a new variable is created, unrelated to the outer
variable.

> I don't see any way in which the proposed statement is any less
> confusing than the current semantics - it's just confusing in a
> different way.

Creating a new variable with the given initial value, and modifying
the value of an existing variable, are different concepts. The
proposal distinguishes them, and doesn't need a 'global' declaration.
A variable is created when a 'var' statement is executed.

Current Python doesn't make very clear when a variable is created.
A global variable is created the first time it is assigned to outside
any function without a 'global' declaration. A local variable is
created at the beginning of the innermost scope which contains an
assignment statement to that variable name. This is implicit and
more complex.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Python-3000 mailing list