> LçÉettçËäº E S <eero.saynatkari / kolumbus.fi>
> Aihe: Re: nil question
> 
> > LçÉettçËäº "David A. Black" <dblack / wobblini.net>
> > Aihe: Re: nil question
> > 
> > Hi --
> > 
> > On Mon, 31 Jan 2005, Christian Neukirchen wrote:
> > 
> > > "David A. Black" <dblack / wobblini.net> writes:
> > >
> > >> Hi --
> > >>
> > >> On Sun, 30 Jan 2005, Christian Neukirchen wrote:
> > >>
> > >>> "William James" <w_a_x_man / yahoo.com> writes:
> > >>>
> > >>>> Sam Roberts wrote
> > >>>>> In ruby, zero and empty strings are true
> > >>>>
> > >>>> Since 0 is true, you should be able to do this in Ruby:
> > >>>>
> > >>>> puts "yes" if -5 < x < 9
> > >>>>
> > >>>> The phrase '-5 < x' should yield the value of x instead of true.
> > >>>> That's the way it actually works in the Icon programming language.
> > >>>> But we have to use the klunky
> > >>>>
> > >>>> puts "yes" if -5 < x and x < 9
> > >>>>
> > >>>
> > >>> Erm, say, x is -16:
> > >>>
> > >>> (-5 < x) < 9
> > >>> (-5 < -16) < 9
> > >>> -5 < 9
> > >>> -5
> > >>>
> > >>> -5 is true, probably not what you want.
> > >>
> > >> But -5 < -16 is not true, so it wouldn't get that far.  (I assume
> > >> William means it should return x if the expression is true, false
> > >> otherwise.)
> > >
> > > So false is bigger than 9?  Math books will need to be rewritten. :-)
> > 
> > I assume the expression would short-circuit once one of the
> > sub-expressions returned false, since
> > 
> >    x < y < z
> > 
> > cannot be true unless x < y.  So there would never be a false < z
> > comparison.
> 
> So...
> 
> class Numeric
>   alias :old_lt :<
>   alias :old_gt :<
> 
>   def <(val)
>     val if self.old_lt val
>     false
>   end
> 
>   def >(val)
>     val if self.old_gt val
>     false
>   end
> end
> 
> >> x = 5
> >> puts 4 < x < 6
> => 5
> >> puts 6 < x < 7
> => false
> 
> ?

Stupid webmail. Fixnums and Numerics probably just use <=> and 
<, > from Comparable instead, so this'd require changes to the
core there. Also:

class FalseClass
  def <(val)
    false
  end
end

# And this...
>> x = 5
>> puts 4 < x < 6
# ...should of course return:
=> 6   # or 'true' in a conditional.

> > David
 
E