lua-users home
lua-l archive

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

On 02/27/2014 04:06 PM, Steve Litt wrote:
Hi Steve,

I must be missing something here, because I never thought of closures
as mindblowingly powerful. First, maybe I have the wrong idea of what a
closure is. I thought it was an inner function contained in an outer
function, where the inner function is passed back as the return of the
outer function, and the inner function can see and modify the outer
function's local variables, but each newly returned inner function
starts over with the vars set by the outer function, so four returned
inner functions can operate completely independently of each other. Am
I right so far?

I think that so.

What finally impressed me about closures is how they make objects work without even thinking in that terms. Not even syntax to signal what an object is. You just declare some variables, return some functions and *BAM* you have objects. You only have to declare the variables in the scope where they make sense.

To be honest, it's a bit unsettling.