Paul
11/19/2007 6:38:00 AM
On Nov 19, 1:15 pm, Clifford Heath <n...@spam.please.net> wrote:
> Todd Benson wrote:
>
> Firstly Todd, thanks for quoting Konrad, as his messages aren't getting to the newsgroup.
>
> > Somebody please explain to me what good is a Range object that goes
> > from 1 to something_undefined?
>
> I have a meta-language in which it's possible to define value restrictions,
> where a value restriction is a list of values or value ranges, including
> open-ended ones. I never plan to iterate over an open-ended range (though
> I'd expect such a loop to be terminated by exception or some-such), merely
> to detect whether a value is allowed by the restriction or not, i.e., either
> matches one of the single values or falls inside one of the ranges.
>
> Apart from the open endedness of the ranges in this language (which is not
> of my design), the Range object serves perfectly. The Infinity and -Infinity
> will serve for numbers, but not for open-ended string ranges.
>
> > Set.new(1..nil) - Set.new(5..nil)
>
> > Is nil supposed to represent infinity?
>
> No, Infinity will serve for that... but not for Strings. Perhaps the empty
> string will serve? It seems to be able to go on either end of a range.
> ("".."a").each only calls the block once, passing the Range.
>
> Clifford Heath.
irb(main):010:0* 1..(1/0.0)
=> 1..Infinity
irb(main):011:0>
irb(main):012:0* (1..(1/0.0)).each { |i| puts i }
1
2
3
4
5
6
etc, etc.