Antoon Pardon wrote:

> It also is one possibility to implement writable closures.
> 
> One could for instace have a 'declare' have the effect that
> if on a more inner scope such a declared variable is (re)bound it
> will rebind the declared variable instead of binding a local name.

That is one possibility, but I think that it would be better to use a 
keyword at the point of the assigment to indicate assignment to an outer 
scope. This fits with the way 'global' works: you declare at (or near) the 
assignment that it is going to a global variable, not in some far away part 
of the code, so the global nature of the assignment is clearly visible. The 
'global' keyword itself would be much improved if it appeared on the same 
line as the assignment rather than as a separate declaration.

e.g. something like:

var1 = 0

def f():
  var2 = 0

  def g():
     outer var2 = 1 # Assign to outer variable
     global var1 = 1 # Assign to global
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to