[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua and backwards compatibility - was Re: [ANN] Lua 5.3.4 (rc2) now available,
- From: Coda Highland <chighland@...>
- Date: Thu, 12 Jan 2017 12:46:43 -0800
On Thu, Jan 12, 2017 at 10:33 AM, William Ahern
<william@25thandclement.com> wrote:
> On Thu, Jan 12, 2017 at 07:42:49AM -0800, Coda Highland wrote:
>> On Thu, Jan 12, 2017 at 6:44 AM, Nagaev Boris <bnagaev@gmail.com> 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
>>
>> 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
> closures.
That C++ stack variables go away is really a sign that it IS in fact
shared, and one consumer has explicitly destroyed it. You'd have the
same problem with any other data-sharing construct in C++, so this
specific limitation is just a matter of language best practices rather
than "C++ can't do it".
Obj-C blocks can capture boxed values that are refcounted/garbage-collected.
>> 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.
Okay, so maybe I'm wrong about Python, but I'm not wrong about the C
family. You're right that multiple stacks on its own aren't equivalent
to coroutines, but they provide the essential structure necessary to
implement them. You can't just look at the core language definition
and stop there. I've used a coroutine library before. It's really not
bad at all.
Also, ES7 has them.
/s/ Adam
- References:
- Lua and backwards compatibility - was Re: [ANN] Lua 5.3.4 (rc2) now available,, Dibyendu Majumdar
- Re: Lua and backwards compatibility - was Re: [ANN] Lua 5.3.4 (rc2) now available,, William Ahern
- Re: Lua and backwards compatibility - was Re: [ANN] Lua 5.3.4 (rc2) now available,, Nagaev Boris
- Re: Lua and backwards compatibility - was Re: [ANN] Lua 5.3.4 (rc2) now available,, Coda Highland
- Re: Lua and backwards compatibility - was Re: [ANN] Lua 5.3.4 (rc2) now available,, William Ahern