From: Marcin 'Qrczak' Kowalczyk Date: 2003-10-02T05:19:35+09:00 Subject: Re: Making == symmetric? W li�cie z �ro, 01-10-2003, godz. 21:42, Sean O'Dell pisze: > The notion of a symmetrical equality test is an abstract concept. In > reality, whether it's Ruby or anything else, testing is NOT symmetrical. The method used to determine the outcome is not symmetrical internally, but the outcome is (or rather: should be). > If you say: > > if (a == b) then > > ... then you are accepting one pass. If you say: > > if (a == b and b == a) then > > ... then you are demanding a second pass and trying to get a better idea > if they are equal or not. My concept of == requires that they give the same result, i.e. if they differ then some definition of == must be insane (probably a programmer- -supplied interpretation of == for a particular type). I mean that if an algorithm relies on == being symmetrical but doesn't explicitly check both directions and fails because of this, then the fault is at the definition of ==, not in the algorithm which uses ==. It wouldn't know what to do with conflicting answers anyway, except to signal error. Why do you use "and" and not "or" for example? Well, another, equally valid requirement is x==x, which is usually not satisied by NaN. I say: it is indeed against the rules; sometimes it's useful to make an exception. You shouldn't rely much on equality of floats anyway. > > I don't say that the language should enforce == to be symmetric. I say > > that the language should allow to define a symmetric == with the desired > > meaning. > > But it does. You can very easily override == just as I described in my > example code. You can make == anything you want it to be, for any > class, existing or not. How to make a new numeric type (say, long integer objects from another language or library wrapped as Ruby objects) and make == between this type and other numeric types compute the equality of numbers being represented? You don't know all other numeric types. -- __("< Marcin Kowalczyk \__/ qrczak@knm.org.pl ^^ http://qrnik.knm.org.pl/~qrczak/