closure = decorator?

Jussi Piitulainen jpiitula at ling.helsinki.fi
Thu Oct 10 10:15:06 EDT 2013


Chris Angelico writes:

> def outer(x):
>     x += 1
>     def inner():
>         return x
>     return inner
...
> The terminology is that inner() "closes over" x, if I have that
> correct (I've not been all that big in functional programming and
> lambda calculus). Someone will correct me if I'm not.

I don't actually know for sure what the most correct terminology is,
but I like to think that a closure is a procedure (function) closed in
the environment (namespace) where it was created, so even when it is
called from another environment, it uses the one where it was born.

But that may be private to me.



More information about the Python-list mailing list