[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: documentation: metatable is a reference (refman is unclear)
- From: Coda Highland <chighland@...>
- Date: Mon, 8 May 2017 15:42:05 -0700
On Mon, May 8, 2017 at 3:40 PM, Gé Weijers <firstname.lastname@example.org> wrote:
> On Mon, May 8, 2017 at 3:02 PM, Ross Berteig <email@example.com> wrote:
>> The fact that tables are "stored by reference" is just an implementation
>> detail that makes the value semantics of tables practical to implement. This
>> is similar to strings being internalized, which is also just an
>> implementation detail that make their value semantics practical to
> Lua tables do not have value semantics, as you examples are clearly showing.
> a.x = 1
> b.x = 2
> print(a.x) -- prints 2
> This is reference semantics. You'd see '1' if Lua implemented value
> String internalization is a different beast, because strings are immutable,
> so value semantics and reference semantics are indistinguishable if you
> ignore memory and complexity issues.
In the context, I understood that what he meant was "the semantics of
a table", not "tables have value semantics".
Yes, there is a semantic difference, and he was incorrect due to his
choice of words, but the actual reasoning is sound.