[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Per-value metatables would be great for threads
- From: Parke <parke.nexus@...>
- Date: Fri, 28 Aug 2015 09:35:19 -0700
Dirk Laurie wrote:
>> Was there near-universal acclaim for per-value metatables,
>> or am I just remembering what I like to? Anyway, pointing out
>> one more advantage can't hurt :-)
On Fri, Aug 28, 2015 at 5:32 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> I originally proposed that in jest. (The light userdata part was
> serious, but the "(We could even gain individual metatables for numbers
> :-)" was intended as a joke...
Per value metatables would allow strings to have different metatables.
It would solve many (all of?) the problems Roberto pointed out
previously:
On Tue, May 5, 2015 at 9:00 AM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> More to the point, strings have no notion of "self", or of being
> created. If you run "a".."bc" twice, do you create two different
> strings (with two different metatables) or only one? Are they the
> same as "abc"? Does that depend on whether there is a GC between the
> execution of those expressions? However you answer those questions,
> there will be a lot of drawbacks.
http://lua-users.org/lists/lua-l/2015-05/msg00094.html
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?
-Parke