.. and ... aren't operators, maybe they should be?

I completely agree. I've wanted to override what's allowed in
a range and there is no way to do it. And a range doesn't seem
like a fundamental thing in the language. I've wanted to do
what you are doing in the example below (create infinite
ranges). With infinite ranges you could do something like
this:

case x
when (nil...-2) then .... # same as if x<-2
when (-2...5) then .... # same as if -2<=x<5
when (5...nil) then .... # same as if x>=5
when (nil..nil) then .... # same as if true
end

It would be nice to not need the nil (which would be translated
to nil), but I realize that could be parsing problem and would
reduce the cleanliness of the language.

Why don't you make an RCR for the having .. and ... be methods
instead of built-in operators?

Eric

ยทยทยท

--- Logan Capaldo <logancapaldo@gmail.com> wrote:

On 5/5/05, Logan Capaldo <logancapaldo@gmail.com> wrote:
> I was just wondering if maybe the range construction syntax
could be
> implemented as a set of operators?
>
> ie
>
> class Object
> def ..(other)
> Range.new(self, other)
> end
> def ...(other)
> Range.new(self, other, true)
> end
> end
>
> This wouldn't implement the parser much (I don't think any
way) and
> it could be useful for things like
> defining inifinite lazy lists, or other ranges with weird
natures
>
> ie
>
> class InfRange
> attr_reader :first
> def take(n)
> i = self.first
> 1.upto(n) { yield(i); i = i.succ }
> end
> def initialize(n)
> @first = n
> end
> end
>
> class Fixnum
> def ..(other)
> if other.nil?
> InfRange.new(self)
> else
> Range.new(self, other)
> end
> end
> def ...(other)
> if other.nil?
> InfRange.new(self)
> else
> Range.new(self, other, true)
> end
> end
> end
>
> (1..inf).take(5) do |x|
> p x
> end
>
> Ok thats a pretty silly example, but lets say succ was more
> complicated than just self + 1
>
> Eh maybe I'm crazy and this is useless. Just seems to be in
line with
> << and + etc. being changeable.
>

Nobody likes this idea? Or is it just so dumb its not worthy
of a response? :wink:

__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail