[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: __eq operator behavior
- From: Dirk Laurie <dpl@...>
- Date: Wed, 30 Mar 2011 10:16:16 +0200
On Tue, Mar 29, 2011 at 11:27:12PM +0200, Guilherme Destefani wrote:
> I understand that the identity comparison is making the whole
> operation more optimized in the common case, but I'm not sure that
> assume everything always compare itself to true is the right
> thing to do.
Well, if you deny the logical validity of A==A, then Aristotle
lived in vain.
What your argument does show, however, is that there is a need for
a __ne metamethod. It should not be implemented as the negation of
__eq, although it may default to that when no __ne is supplied.
There is an efficiency argument as well. If two matrices differ
in the first element, one can immediately exit __ne, whereas you
would need to check the whole lot to evaluate __eq.
Actually, all six comparisons should be available as metamethods,
even if defaults are used to supply the missing ones. As in P*****.
Dirk