setting variables in outer functions
Duncan Booth
duncan.booth at invalid.invalid
Thu Nov 1 05:26:21 EDT 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[0] 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.
What is your point here? Python isn't C (or Javascript). If you have a
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
mailing list