lua-users home
lua-l archive

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


> It is not (as you say) what assignment means in a mathematical 
> sense of course.

Don't blame mathematics for what Fortran, Matlab, etc do.  

I find Lua's assignment rule simplest of all programming languages I know:

> Tables, functions, threads, and (full) userdata values are objects: variables
> do not actually contain these values, only references to them. Assignment,
> parameter passing, and function returns always manipulate references to such
> values; these operations do not imply any kind of copy.

Two sentences, and the whole concept is fully explained.  

It is good that `__assign` is not a metamethod.  We'll then need a library 
function `rawassign`, and it's not worth it.  Copying recursively defined 
objects is a complicated matter, and there should be some visible reminder 
that one is invoking such a mechanism.  After all, it could be as small as 
a pair of parentheses.

-- When object b is constructed, set its __call metamethod to make a copy
-- of itself.  It could even take an argument indicating the desired depth.

a=b     -- `a` is another name for the value of `b`
a=b()   -- `a` is a name for a newly-made copy of `b` 

Dirk