lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

To your quotes I will throw back Sussman's _Structure And Interpretation of
Computer Programs_ which shows all sorts of things that you can build
because closures capture variables rather than values. (It covers a lot of
other things but review Chapter 3, Modularity, Objects, and State.

The closure part has to do with the fact that unlike dynamic scoping,
evaluating the function won't go looking for the variable again. The
implementation determines which variable a token corresponds to at the time
the function is constructed based on the lexical scope of the token. A
function captures it's environment at the time it is created and that
environment is based on the lexical arrangement of code rather than the
dynamic arrangement. That environment provides a mapping from variables
names to values.