[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua and backwards compatibility - was Re: [ANN] Lua 5.3.4 (rc2) now available,
- From: William Ahern <william@...>
- Date: Thu, 12 Jan 2017 10:33:36 -0800
On Thu, Jan 12, 2017 at 07:42:49AM -0800, Coda Highland wrote:
> On Thu, Jan 12, 2017 at 6:44 AM, Nagaev Boris <firstname.lastname@example.org> 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.
> > https://play.golang.org/p/o23Z6bbUTp
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.