[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: "local" and stack
- From: Tim Hill <drtimhill@...>
- Date: Sun, 22 Sep 2013 18:54:43 -0700
On Sep 22, 2013, at 12:41 PM, Doug Currie <email@example.com> wrote:
> You are correctly describing the implementation of Lua values, perhaps not the simplest semantics for some people. There is an equivalent way to look at this: the semantics for all values is by reference; some values are mutable (tables, userdata), most values are not mutable (numbers, strings, booleans). Rephrasing your second paragraph above,
> Consider a simple assignment of two variables: "x = y". If y refers to a value, then x will get the same reference. Changing the value of y later (changing what y refers to) will not alter the value of x (what x refers to). But if y contains a reference to a mutable value (such as table), changes made to the value (table) via y will *also* appear in the value (table) x refers to, and vice-versa. Of course, non-mutable values such as numbers or strings cannot be changed like this.
Mostly I agree, but mutability does not completely address "by reference" semantics. There is nothing about a mutable value that says it cannot have copy semantics for assignment etc, so your explanation remains incomplete. The OP was particularly interested in copy vs reference semantics.