lua-users home
lua-l archive

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


On 25 April 2018 at 16:31, Hisham <h@hisham.hm> wrote:
> On 25 April 2018 at 05:06, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> 2018-04-25 0:20 GMT+02:00 Bruce Hill <bruce@bruce-hill.com>:
>>> Hey everybody, I just released a library that allows you to create immutable
>>> tables in Lua. The tables are stored compactly and instances are interned
>>> (but garbage collected), so the immutable tables can be used as table keys.
>>> I know there's been a lot of talk lately about "arrays with holes", and my
>>> library supports that.
>>
>> How does your library compare with pure-Lua read-only tables?
>
> This works:
>
> T[tuple("foo", "bar")] = 123
> assert(T[tuple("foo", "bar")] == T[tuple("foo", "bar")])
>
>> https://www.lua.org/pil/13.4.5.html
>
> This doesn't:
>
> T[readonly{"foo", "bar"}] = 123
> assert(T[readonly{"foo", "bar"}] == T[readonly{"foo", "bar"}])

Or rather, this particular assert will pass because nil == nil.

Make it:

assert(T[readonly{"foo", "bar"}] == 123)

> -- Hisham