[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Object equality
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 02 Jul 2002 11:53:07 -0300
> With an "equals" tag method, there is no guarantee that a value will not
> compare equal to nil (unless there is such a guarantee, but that would be
> yet another kludge).
There is such guarantee; whether is a kludge or not is up to you:
Objects can only be equal if they have the same type. Different types
imply different objects, no questions asked (i.e. no tag methods
involved). No object can be equal to nil, nor to 3 or "hello".
> How do I test to see if the result of a computation is NaN? Do you
> contemplate an isNaN() function?
Yes, but NaN is not ANSI. That is, the current (old?) ANSI C allows a
NaN, but it does not "recognize" it. So there is no portable way to
implement a isNaN. What we do in Lua is to expose the underlying rules
to the programmer, so that if your "machine" says that `a ~= a', so does
> This will be a little odd, though: with equal tag methods, it is no
> longer the case that b == c implies a[b] == a[c].
Actually, even before that was not the case, because "a[b]" might
involve tag methods ;-) So, what is the case is that rawequal(b,c)
implies rawequal(rawget(a,b), rawget(a,c)).