lua-users home
lua-l archive

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


On Tue, Oct 23, 2012 at 2:46 PM, spir <denis.spir@gmail.com> wrote:
> Yes, thank you very much. I knew of such uses of closures, actually, but had
> not yet realised they require the variable, not the data, to be recorded
> with the func.

personally, i wouldn't call a function 'closure' if it doesn't enclose
external variables like that.  in fact, i don't consider a language
has lexical scoping unless it implements real closures.

as in every learning experience, well-defined features let you easily
reason around requirements and expected outcomes.  these same
constructs are common in Javascript, Scheme, Python and many others
simply because knowing that they are lexicaly scoped lets you be
confident in the result.  [ at least while 'this' variable isn't
involved in JS case! ;)  ]

But to do a similar thing in C or Java I would have to pay much more
attention to the exact behavior, and the result would not be so
readable as these examples.  Much easier would be to use common OOP
idioms in that case.

-- 
Javier