lua-users home
lua-l archive

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


steve donovan wrote:
[...]
> I am probably not using the correct terminology, but I simply mean
> that values like numbers are copied, whereas tables are not copied by
> assignment. This does seem to confuse people, but is of course common
> to many languages.  Of course, everything is passed by value (as in C)
> ultimately but there are no special copy semantics as C++ programmers
> would understand it.

It's much easier to think of this as *all* values being passed by
reference... it's just that numbers, like strings, are immutable and
cannot be changed. Therefore:

a = a + 1

...does not *change* the value of the thing a points at. Instead it
creates a new number with the value (a+1) and then reassigns a to point
at the new number instead of the old one.

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "There does not now, nor will there ever, exist a programming
│ language in which it is the least bit hard to write bad programs." ---
│ Flon's Axiom