lua-users home
lua-l archive

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


On 21 August 2015 at 08:48, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> So different metatable for 4 than for 5? That would be... interesting.
>
> Actually, different fours could have different metatables :-)

This whole concept sounds very scary to me.
Subtypes make for strange and weird semantics;
we already have a 4 that's not a 4:

Lua 5.3.1  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> 4 == 4.0
true
> rawequal(4, 4.0)
true
> math.type(4) == math.type(4.0)
false
> t = {}; t[4] = "foo"; print(t[4.0])
foo
> math.type(next({[4.0]=true}))
integer


This breaks currying, memoization, and other useful things.
Extending this to other types seems to be asking for a mess.

  - it seems like we need a rawrawequal();
  - following table semantics, there will always be a 'primary'
subtype that is used when the object is a table key