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

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Mon Oct 9 20:43:19 CEST 2006


Neil Toronto <ntoronto at cs.byu.edu> 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 at cs.byu.edu> 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 at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Python-3000 mailing list