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 _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
