lua-users home
lua-l archive

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


On 11/8/12, Finn Wilcox <finnw@firecloudsw.co.uk> wrote:
> On 08/11/2012 10:42, joao lobato wrote:
>>
>> I wonder if it would make sense to have __eq influence table hashing.
>
> This works in Lisp only because the :TEST function must be one of the
> four predefined ones (EQ, EQL, EQUAL, EQUALP.)  If you defined your own
> __eq metamethod, it would be impossible (in the general case) for the
> implementation to create a hash function consistent with it.
>
>

Yes. IIRC, one uses the symbols 'eq, etc to specify a particular hash
function. Nevertheless Lua could follow a similar strategy, where
tables created using the { } constructor would use the usual hash
function; there could be functions in the "table" namespace that
constructed objects that would be almost but not quite, entirely
unlike tables: like tables only with fixed length array part (arrays),
tables only with a fixed hash part (records / namespaces / objects),
tables with different, predefined, hash functions.

While one could implement all those things by removing functionality
from ordinary tables using metamethods, it always feels like the wrong
way to extend existing behaviour.