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

Christos TZOTZIOY Georgiou DLNXPEGFQVEB at spammotel.com
Tue Feb 11 08:40:34 EST 2003


On Mon, 10 Feb 2003 21:42:57 +0000, rumours say that Peter Harris
<scav at blueyonder.co.uk> might have written:

>My proposal is for a built-in closure type for Python, and
>a syntax for closure literals.

Hm... perhaps static variables would be something more generic, a la:

def function(args):
    static:
        c = 5
        d = 7
    # normal code follows here

Everything in the static block would be executed only the first time the
function is called, and all names bound in it would be mapped to an
entry in the freevars array, using LOAD_DEREF and STORE_DEREF opcodes in
the normal function body instead of LOAD_FAST and STORE_FAST.
STORE_DEREF exists as an opcode and functionality, but I don't know how
it can be emitted...

Using static followed by a colon, there would not be any need to make it
a keyword (ie, a variable named static would be available and usable).

This is the PEP I will write RSN, when I get the time to implement this
as a patch for the C code...

T
-- 
TZOTZIOY, I speak England very best,
Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64')




More information about the Python-list mailing list