global in nested functions (viper)

Jeremy Hylton jeremy at cnri.reston.va.us
Tue Sep 21 18:51:29 EDT 1999


>>>>> "ES" == Evan Simpson <evan at tokenexchange.com> writes:

  ES> This sounds relevent to one of my many proposals to make work
  ES> for other folks <wink>.  Perhaps instead of causing a reference
  ES> to the (grand-)*parent's locals, this could simply copy the
  ES> object into a local variable at definition time?

This wouldn't help for code that uses assignment.  The expected
behavior of 'x = 2' is that all code that can access x will see the
new value.  Copying into a local variable would make changes visible
only in the local scope.

The problem with the earlier proposal -- that global means look in the 
locals of the containing function unless it also contains a global
decl -- is that you need to add a global decl to every scope between
the one where the variable is created and the one where it is used.
It seems less tedious to define global to mean the nearest enclosing
scope. 

Jeremy




More information about the Python-list mailing list