lua-users home
lua-l archive

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


On Thu, Feb 27, 2014 at 8:06 PM, Steve Litt <slitt@troubleshooters.com> wrote:
> Don't get me wrong: I love closures because in Lua, they're one tool
> that's useful for a huge number of situations, but I've missed how
> they're more powerful than standard objects or ordinary callback
> routines.

Which is why Sean had to quote that koan; objects and closures are two
ways of doing the same thing.  A Java anonymous class is a closure
(one that can't modify its outer scope) but man it is an ugly beast to
construct and to read.  Same for a classic C++ 'functor' - some
extraordinary clever (but hacky) stuff was done to make that read
naturally (boost lambda library).  C++11 has now got proper anonymous
functions with control about whether the bound variables are copies or
not; apparently even Java is bowing to pressure.

'Equivalent power' does not mean equally easy to use.

I've been aware of how so much more convenient they are than plain
callbacks, since I've been doing a fair amount of C; a function is
just a plain pointer to executable code, and the context has to be
separately schlepped around.  I had to resist the temptation to use
GCC's support for nested functions, but it has zero chance of getting
into any standards.