PEP 309 - Built-in closure type (with tentative syntax proposal)

Christos TZOTZIOY Georgiou DLNXPEGFQVEB at spammotel.com
Thu Feb 13 08:26:13 EST 2003


On Wed, 12 Feb 2003 17:13:12 -0500, rumours say that "Terry Reedy"
<tjreedy at udel.edu> might have written:

>> This is the way to create closures and I use it too.  Can you rebind
>c
>> or d inside function?  If yes, please show me how.
>
>You cannot rebind c or d from within 'function' by normal means (where
>'abnormal' means fiddling with or replacing closure's code object).

The STORE_DEREF opcode exists, though, and it'd be nice to take
advantage of it.

>However, you can make them list or dict objects and replace the
>contents with normal assignments.

Yes, this is the known method.  It feels like a workaround, exactly like
adding function properties outside the function body and then accessing
them from the function body going through a global reference (ie, the
function object itself).

>> After all, I won't write a PEP unless I have a working patch (I
>think
>> it's a prerequisite for a PEP).

>No, not initially.  See http://www.python.org/peps/pep-0001.html.
>However, proof of feasibility certainly helps the evaluation process.

Thanks for the hint; even so, I won't write a PEP without working code.
It's something that hardly most of the people would think as *necessary*
since there are workarounds, but if implemented in a clear and/or
'pythonic' way, I think it will be easier for many pythonistas to find
it acceptable.

[tongue in cheek] but first I will write a PEP to make the 'x and/or y'
keyword applicable in python; ie whatever the truth values of x and y,
do the right thing :)
-- 
TZOTZIOY, I speak England very best,
Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64')




More information about the Python-list mailing list