Q: Python 2.0 preliminary features?
Jeremy Hylton
jeremy at cnri.reston.va.us
Mon Oct 11 12:41:43 EDT 1999
>>>>> "GE" == Greg Ewing <greg.ewing at compaq.com> writes:
GE> Also, to clarify Tim's rather waffly characterisation of when my
GE> closures do or don't cause cycles, it's quite simple: they never
GE> cause cycles unless you write code which makes them do so. This
GE> is no worse than the situation with regard to cycles everywhere
GE> else in the language.
I think this description is at least as waffly as Tim's :-). It seems
to me that most of the interesting uses of lexical scoping necessarily
create cycles. Is there a large class of uses that will not create
cycles?
One of the prototypical uses of lexical scoping is functions like
these:
def make_adder(num):
def adder(x):
global num
return x + num
return adder
In this case, adder maintains a reference to make_adder's
environment, and that environment maintains a reference to adder,
because adder was defined there. So we have a cycle...
It seems odd to propose adding lexical scoping to Python, and then
tell people not to write code like make_adder.
Jeremy
More information about the Python-list
mailing list