Q: Python 2.0 preliminary features?
skaller
skaller at maxtal.com.au
Sun Oct 17 09:26:43 EDT 1999
Guido van Rossum wrote:
>
> (I'm falling into the middle again. But this is interesting. I hope
> I haven't misunderstood Greg's description.)
>
> Greg Ewing <greg.ewing at compaq.com> writes:
> > Under my scheme, that piece of code in itself does not create
> > a cycle. This is because a nested def does not immediately create
> > a closure; instead it creates a special "local function object"
> > which simply wraps the function. A closure is created "on
> > demand" whenever a local function object is fetched out of a
> > local variable. This is analogous to the way a bound method
> > object is created whenever a function is fetched out of a
> > class during an attribute lookup.
>
> Hm. I don't find it analogous, and while I agree that it's a clever
> hack to avoid cycles, I don't like it much.
But the real problem is simply that the inner function is
named, which can be avoided using a proper lambda. This isn't
a 'transparent' solution. However, until CPython gets a real
garbage collector (which solves the problem), a way to simultaneously
delete and return a function would be interesting: consider
changing 'del x' to an expression returning x, then:
def make_adder():
def adder ..
return (del adder)
will remove adder from make_adder's stack frame, eliminating
the cycle.
--
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