Function decorator that caches function results

Paul Rubin http
Sun Oct 9 17:13:04 EDT 2005


Steven D'Aprano <steve at REMOVETHIScyber.com.au> writes:
> No. I'm obsessed with finding out what closures are, since nobody seems to
> have a good definition of them!

Why don't you read SICP:

   http://mitpress.mit.edu/sicp/full-text/book/book.html

You will be a much wiser person for having done so.

> However, I have learnt some things: closures are something which
> functions HAVE, not ARE. 

Nah, that describes the data layout through which CPython implements
closures, not the bigger idea of what closures are.

> The func_closure attribute is just part of the implementation of the
> closure. Some languages have closures and some don't. And a closure
> is something that lets a function object access the lexical scope
> that existed when the function object was created, e.g. the
> namespace of the function which created it.

I'd say, the closure is the function's executable code, plus the
lexical environment that got recorded at the time the function was
created.



More information about the Python-list mailing list