Q: Python 2.0 preliminary features?

skaller skaller at maxtal.com.au
Sun Oct 10 22:29:01 EDT 1999


Greg Ewing wrote:
 
> I'd just like to point out that my closures are only "read only"
> because I have deferred making a syntactic decision about how to declare
> variables as "nonlocal" for assignment purposes; there's no inherent
> reason why my closures couldn't be read-write.

You do not need to make any decision. Just use the current 'global'
declaration, this is what Viperi does. The trick is to understand that
'global' means 'up one level exactly', as it does in python now (which
only has two levels).

If you want to write up TWO levels of scope, then the parent
must also contain a global directive:

def f():
   x = 0
   def g():
      global x
      def h():
        global x
        x = 1


This seems consistent. It is not entirely python compatible,
since the global directive in the function h() would normally
refer to module scope. But that is probably irrelevant,
since lexically scoped nested functions aren't compatible with
python ones anyhow.

If you wish to minise syntactic changes to Python, you might
consider this solution, it will also be compatible with
Viper. :-)

-- 
John Skaller, mailto:skaller at maxtal.com.au
1/10 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
downloads: http://www.triode.net.au/~skaller




More information about the Python-list mailing list