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

Neil Toronto ntoronto at cs.byu.edu
Mon Oct 9 20:06:07 CEST 2006


Marcin 'Qrczak' Kowalczyk wrote:
>   It should be:
>
> var x = 0
> def f():
>    print x
>    x = 3
>
> for the global variable, and:
>
> var x = 0
> def f():
>    var x
>    print x
>    x = 3
>
> for the local variable.
>
> There are a few sane choices for the semantics of 'var':
>
> 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.
>   

For the record, though I didn't present it this way in my initial 
proposal, I like #1 and #2 better than #3. Otherwise, you'd get this 
silliness:

def f():
   x = 3   # fine, because the magic 'var' down below creates it
   var x = 0


Neil


More information about the Python-3000 mailing list