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

Josiah Carlson jcarlson at uci.edu
Mon Oct 9 21:18:12 CEST 2006


Neil Toronto <ntoronto at cs.byu.edu> wrote:
> Fredrik Lundh wrote:
> > Neil Toronto wrote:
> >> Heck no. An assignment would modify an existing variable only.
> >>     
> >
> > what's an "existing variable"?  how would STORE_GLOBAL work under your 
> > proposal?
> 
> I haven't got a clue what STORE_GLOBAL is, apart from the fact that it 
> looks like it has something to do with Python's bytecode.
> 
> If it's what I think it is (so don't hold me to this), it'd raise an 
> exception if you used on something that hadn't been created yet. 
> Probably need a MAKE_GLOBAL in addition to it, or keep STORE_GLOBAL as 
> it is (for "var x = 0") and add MODIFY_GLOBAL that raises an exception 
> on uncreated variables.
> 
> Or something. Again, I'm guessing, and you have me at a disadvantage. 
> Can we keep the discussion above the bytecode level for now?

Ok, but you need to understand a few things about how Python handles
things "under the covers".

Function-level scopes are not implemented as dictionaries.  They are
implemented as arrays, and the compiler maps local names to positions in
the in the array that stores locals.  The module-level namespace (which
can be accessed as a dictionary via globals()) is a dictionary, but this
is because anyone can insert or remove names arbitrarily, which is not
the case for function locals.  Also, Python's use of an array for locals
allows for a significant improvement in execution speed.


When Fredrik brought up the STORE_GLOBAL opcode, it was applicable
because the compiler needs to know at compile time whether a variable is
global (for the various *_GLOBAL opcodes) or local (for the various
*_FAST opcodes).

From what I can tell, the only thing that your 'var' keyword does is
ambiguate the global vs. local case, nevermind breaking 99% of currently
working Python code.  I'd save my time and get used to the way scopes
are working now, because I doubt they are going to change (none of the
core developers (I'm not one) who have chimed in have been positive).

 - Josiah



More information about the Python-3000 mailing list