lua-users home
lua-l archive

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

Point taken - I guess it's a side-effect of some early design decisions.

Changing the type of the lhs in an expression such as

var1 = var2

is contrary to the concepts those familiar with compiled languages are used to which is where the compiler attempts to convert var2 into the type of var1. That confuses us poor simple C and C++ coders.

It becomes difficult to keep track of things if variables become effectively just a handle to something else, since the type is effectively mutable on any assignment.

It's another argument (one I'm sure has already been thrashed out) as to whether it is more useful to convert the lhs to the type of the rhs (as lua effectively does), or vice-versa.

It's just another source of confusion for C and C++ programmers, who are used to the other way around. In this respect, Lua doesn't really protect the user from having to know about types at all. The only interchangeable ones are strings and numbers, and that's only because there are built-in converters between these 2 types.

Anyway, it's core to the language, so it probably shouldn't be changed.

In which case, separate functions will need to be written to deep-copy objects... you end up with code like

deepcopy(var1, var2);

or maybe


instead of

var1 = var2;

so I guess __assign is going nowhere.

still no comment on __cast though?

Miles Bader wrote:
Adrien de Croy <> writes:
It could be considered radical maybe for tables.

for userdata and lightuserdata, it makes perfect sense to use the same
syntax to copy one userdata to another one the same as you would a
string value, rather than a function to do it.

It seems a fairly fundamental part of Lua that it's a "reference"
language (like lisp/scheme, clu, etc):  variables store references to
their value, not the values (this is slightly relaxed for numbers, but
that doesn't change the general properties of this behavior).

The result is that users can rely on assignment being very cheap, and
having no side effect other than the obvious one.

I think any change to this could be considered "huge", as could be any
change that makes "assignment" (with "=") different than e.g. parameter


Adrien de Croy - WinGate Proxy Server -