lua-users home
lua-l archive

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


On 2015-08-28 18:35 +0200, Parke wrote:

As far as numbers with different metatables... that might allow units
of measure (or other type information) to be associated with numbers.
I have used that capability in other languages in pursuit of
correctness and more informative error messages.  For example, is 4
meters the same as 4 feet?  4 US dollars the same as 4 Euros?

IMHO 4 meters is not the number 4 with additional information, it should have its own "meters" type. So if you want the 4 to be different from other fours (e.g. not allowing addition with them), wrap in in a table or a userdata object and give it the arithmetic metamethods along with an appropriate __tostring. If that is too expensive performance-wise, then I still think that rather than allowing per-value metatables for all value types, a new value type should be introduced for this purpose (or a way to create new value-(sub)types on the fly?). The fact that all 4s are the same is IMHO not (only) a limitation, it also reliefs us from much complexity.

(Sorry if that has all already been said, I haven't read all the messages about this topic.)


‒ Christian