lua-users home
lua-l archive

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


On Tue, Dec 22, 2009 at 5:38 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
> But I'm also looking for is a more formal one.

i think formally there's no difference between primitives 'value
based' types and 'reference based'

to me, it's more like this:

- values have type
- variables have no type
- variables reference values
- simple assignment and function parameters copy variables (that is,
references), not values
- there are immutable types (number, string, lightuserdata), and
mutable types (table, function, full userdata)

implementation detail: numbers and lightuserdatas are small enough to
reside in the variable themselves and are copied around; but since
they're immutable, it doesn't make any difference.

IOW, the 'by value vs. by reference' is only an implementation detail
and not a formal specification.  the behaviour must conform to the
theoretical specification where every variable holds only a reference.

-- 
Javier