logo       

Re: Sky pie: a "var" keyword: msg#00044

python.python-3000.devel

Subject: Re: Sky pie: a "var" keyword

Neil Toronto <ntoronto@xxxxxxxxxx> writes:

> 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

In my semantics #3 this would be a runtime error at the assignment
(the compiler could catch it statically in this case, but not always).


Neil Toronto <ntoronto@xxxxxxxxxx> writes:

> var x = 0
> def f():
> if sometest:
> var x = 3
>
> x = 2
>
> which is seriously evil, because it's not clear which 'x' the last
> assignment refers to.

Should be:

var x = 0
def f():
var x
if sometest:
x = 3
x = 2

For 'for' loops there are two choices:

1. 'for x in coll' creates x which is local to the loop.

2. 'for var x in coll' creates a local x, 'for x in coll'
modifies an existing x.

I admit that Python choices of expressing certain constructs
(conditionals, loops) as statements instead of expressions
make a sane semantics of variable declarations less convenient.

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


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise