lua-users home
lua-l archive

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


On Sat, Jul 16, 2016 at 4:14 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
> Am 16.07.2016 um 22:44 schröbte Soni L.:
>>
>>
>> I'm not sure what your point here is.
>
>
> My point is still:
>>
>> Doing the interning and equivalence class thing during construction
>> of your bigints instead of during table indexing has the added
>> advantage, that `100 == bigint(100)` works as well, that something
>> like `table.insert({}, bigint(1), x)` works as well, and that it's
>> probably also faster.
>
>
> But in the interest of avoiding infinite recursion I'll add that making
> values of two separate types equivalent to each other may lead to situations
> where you get one type of operation when you intended the other kind, and
> that it's more likely to happen when you do the interning during
> construction. The only way to prevent it completely is to use separate
> operators (very much like string concatenation `..` doesn't re-use the `+`
> operator). Since you can't add new operators to Lua, that usually means
> functions.

On the other hand, this is also irrelevant, because there's no way to
make use of this key equality trait except when using the values as
keys in a table. `print(100 === bigint(100))` very likely returns
false. Most of the ugly side effects simply don't come up by virtue of
being used in a very constrained context.

/s/ Adam