lua-users home
lua-l archive

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


> More pointedly, should
>
>  t = {}
>  t[x1] = true
>  assert( t[x2] )
>
> succeed?

If one wants this and value equality, the best way is to do interning,
just like its done with strings already. A big hashtable of all
immutable values that exist, and on creation look the hash up, if the
table already exists. It works for strings, so why shouldn't it work
for other analogous constructs just as well?

Pro and contra are just the same as with strings.
Pro: Less memory needs, Fast equal and not equal operations, more
"natural" semantics.
Contra: Slightly more CPU expense on creation and sweeping.

One additonal contra comes to my mind not applicatable to strings,
non-intuativity that mutable tables are not interned, and a mutable
table and immutable table will always == to false, not matter how
equal their current values are.