lua-users home
lua-l archive

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

On Thu, Jan 12, 2017 at 07:42:49AM -0800, Coda Highland wrote:
> On Thu, Jan 12, 2017 at 6:44 AM, Nagaev Boris <> wrote:
> >> OTOH, Lua wouldn't be the language it is today if backwards compatibility
> >> was a higher priority. Features like closures over mutable variables and
> >> stackful coroutines wouldn't have been developed; features which arguably
> >> are now defining characteristics of Lua relative to other languages. Other
> >> than Scheme, I can't think of any other non-academic language with similarly
> >> powerful constructs.
> >
> > Go seems to have variables mutable from closures.
> >
> C++, Obj-C, and Javascript have them too. It's not all THAT rare.

Javascript does, but C++ and Obj-C do not. C++ lambdas and Obj-C blocks
capture by value fundamentally. It's why a lambda can't close over an
automatic (stack allocated) variable and then access that variable after the
scope of that variable has exited. Being able to access variables after
their scope has ended is pretty much the definition of lexically bound

C and C++ are fundamentally pass-by-value languages. In C++ and Obj-C you
have to manually heap-allocate the variable and close over the pointer
(literally or implicitly via syntactic sugar), as the lambdas/block are
really only capturing the value of the pointer.

> Python and C/C++ (and maybe Obj-C?) have stackful coroutines.

Python doesn't have stackful coroutines. Quite the opposite. Same for C++. A
stackful coroutine means you can yield from nested function invocations
_without_ having to specifically invoke the nested function as a coroutine.

As for C and C++, multiple stacks don't really count, otherwise you could
argue that any language with threads has coroutines. But coroutines aren't
just about maintaining state of function invocations, but about how control
flow is passed.