From: Austin Ziegler Date: 2002-06-14T00:09:47+09:00 Subject: Re: Relational operators redux (returning RHS) On Thu, 13 Jun 2002 23:26:52 +0900, Martin Weber wrote: > On Thu, Jun 13, 2002 at 11:13:03PM +0900, Austin Ziegler wrote: >> [...] >> In [ruby-talk:6572], Hugh says he'd probably exclude == and !=. >> >> I don't honestly know the state of this proposal (there's no >> mention of it in the Pickaxe book, which may or may not mean >> anything), but I think it would be a very good thing, and >> disagree that == and != should be excluded. > Imagine == and != returned rhs: > > t == nil ? > nil == t ? > t != nil ? > nil != t ? True enough. I'm not sure that simple RHS return would be good in the event that one of the values is nil; but I think that the idea is fundamentally sound (warning; the following is untested air-code). alias :oeq, :== def == (other) if other.nil? false elsif oeq(other) other else false end end It would be necessary to replace NilClass#== with class NilClass def ==(other) false end end to handle nil on the LHS. If we have the NilClass replacement and the first code in Fixnum, then: x = 5 y = 6 p x == x #=> 5 p x == y #=> false p x == nil #=> false p nil == x #=> false Unfortunately, because != is simply syntactic sugar for ! (x == x), the != tests aren't as clean: p x != x #=> false p x != y #=> true p x != nil #=> true p nil != x #=> true This means that if this were to become normative behaviour, x != y would produce surprising results. I'm not quite sure what the proper answer to this is, but it's just a thought or two. As I said, I *like* the idea that nil isn't equal to anything, including nil. -austin -- Austin Ziegler, austin@halostatue.ca on 2002.06.13 at 10.41.47