[Patches] [Patch #102864] prototype closure implementation (PEP 227)
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 15 Dec 2000 15:29:48 -0800
Patch #102864 has been updated.
Project: python
Category: core (C code)
Status: Open
Submitted by: jhylton
Assigned to : gvanrossum
Summary: prototype closure implementation (PEP 227)
Follow-Ups:
Date: 2000-Dec-15 15:29
By: jhylton
Comment:
Guido,
Here's a very rough implementation of closures. It uses flat closures that do not track rebindings of names in its original namespace. This is discussed briefly in the PEP; it should be straightforward to add a level of indirection to fix this.
I rushed to get something implemented today; it's not the cleanest code. The changes to compile.c are particularly hackish, because the new function find_names() does a lot of work that can simplify code generation for LOAD_NAME, etc. and probably eliminate the need for a separate optimize() pass. I haven't made any attempt to integrate the closure creation cleanly, though; it's just wedged in there.
The patch deals with functions only. Ultimately, classes will have to grow closures, too. The simple examples using classes should work, e.g.
def make_adder(x):
def adder(y):
return x + y
return adder
dec = make_adder(-1)
dec(1) == 0
-------------------------------------------------------
-------------------------------------------------------
For more info, visit:
http://sourceforge.net/patch/?func=detailpatch&patch_id=102864&group_id=5470