setting variables in outer functions
duncan.booth at invalid.invalid
Thu Nov 1 10:26:21 CET 2007
Hrvoje Niksic <hniksic at xemacs.org> wrote:
> In real-life code, closures are used to implement callbacks with
> automatic access to their lexical environment without the need for the
> bogus additional "void *" argument one so often sees in C callbacks,
> and without communication through global variables. If the callbacks
> can access variables in the outer scope, it's only logical (and
> useful) for them to be able to change them. Prohibiting modification
> reduces the usefulness of closures and causes ugly workarounds such as
> the avar pattern.
In real life code methods are used to implement callbacks with automatic
access to their environment without the need for any C type hacks.
function which takes a callback in Python you just pass it a bound method
and you have all the context you want without resorting to ugly workrounds.
More information about the Python-list