lua-users home
lua-l archive

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


DR> I've been thinking, which isn't a good sign...

if you say so... ;-)

DR> I think it would be nice to extend the use of '.' and ':' to all types.
DR> I'd like to be able to do something like this:

I don't feel this would be such a great idea, from a consistency point
of view. Using the colon or dot notation on a table means that you
consider this individual table and its metatable(s) in order to resolve
the table lookup and thus the resulting operation. The lookup of the
required field occurs in the context of the _value_ in question, and
is thus dynamic.

Your proposal would lead to a second, very different meaning for the
colon, namely that the resolution of the table lookup would occur
someplace else. As strings and numbers are immutable values, it would
not make much sense to directly attach a metatable to such a value.
Also, you can not do table lookups on them. So you'd have some global
means to do the required lookup. But then the lookup does not take
place in the context of your value any more. Instead, it happens in
the static environment of the _operation_ in question. Of course, you
could use setfenv() to work around this, but this opens another can of
worms. 

Thus, you'd end up with two meanings of the colon operator, that
differ in both semantics and binding. That's way too much differing
for me to support such a change. 

just my thoughts,

Gunnar