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

Terry Reedy tjreedy at udel.edu
Wed Feb 12 17:13:12 EST 2003


"Christos TZOTZIOY Georgiou" <DLNXPEGFQVEB at spammotel.com> wrote in
message news:ndlk4voeumusmmfsgrldj22kbs0df1k7mh at 4ax.com...

> On Wed, 12 Feb 2003 07:01:31 +0200, rumours say that Beni
Cherniavsky
> >  def closure:    # back to the subject :-)
> >    c = 5
> >    d = 7
> >    def function(args):
> >      "normal code follows here"
> >    return function
> >  function = closure()
>
> 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).
However, you can make them list or dict objects and replace the
contents with normal assignments.

> 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.

Terry J. Reedy






More information about the Python-list mailing list