[Python-Dev] Re: closure semantics

Greg Ewing greg at cosc.canterbury.ac.nz
Wed Oct 22 20:15:48 EDT 2003


> My problem with the nested functions is that it is much harder to get
> a grasp of what the shared state is -- any local variable in the outer
> function *could* be part of the shared state, and the only way to tell
> for sure is by inspecting all the subfunctions.

That would be solved if, instead of marking variables
in inner scopes that refer to outer scopes, it were
the other way round, and variables in the outer scope
were marked as being rebindable in inner scopes.

  def f():
    rebindable x
    def inc_x_by(i):
      x += i # rebinds outer x
    x = 39
    return x

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+

More information about the Python-Dev mailing list