On Wednesday 06 October 2004 01:28 pm, Brian Candler wrote:
| On Thu, Oct 07, 2004 at 02:06:24AM +0900, trans.  (T. Onoma) wrote:
| > On Wednesday 06 October 2004 06:16 am, Brian Candler wrote:
| > | (FWIW, these ranges annoy me: firstly because they're not ranges, and
| > | secondly because I can never remember the difference between a[2..4]
| > | versus a[2,4], and I write a[2,-1] when I should write a[2..-1]. I have
| > | to make test cases in irb every time!)
| >
| > Agreed. I doubt they are ever used. I don't even consider them.
| > Obfuscation pure and simple.
|
| Is there an easier way to say "give me all the elements of this
| (string/array) from position P to the end"?
|
|     str[p, str.size-p]
|
| is not particularly nice. Allowing Infinity for the second parameter might
| be nice though :-)
|
| Also, occasionally I've wanted "give me every element apart from the last
| one": again,
|
|    str[0, str.size-1]
|
| isn't pretty. I suppose str[0..-2] is more compact but more obscure.

My mistake. I actually disagree. I use a[0..-2] and the like regularly.  I 
like them despite the zero point discrepancy.  Sorry I got a bit confused by 
one of your examples. I thought you were referring to something else related 
to:

   a = [1,2,3,4,5]
   a[3,-2]  #=> [4,3] or [3,4]

Which would make sense, but currently it returns nil.

Back to your point. With Infinity (or just Inf) There could be:

  a[0..Inf]

and

  a[0..Inf-1]

Although that possibly brings Float into the picture.

Interestingly there is the (obscure) notion of -0 (negative zero), basically 
the infinitesimal iota to the negative side of the number line. This 
corresponds to the like concept of -Infinity. In "spherical" non-Euclidean 
geometries, -Infinity and +Infinity meet at Infinity in the same way as -0 
and +0 meet at 0.

Anyway, I'm more interested in a simple unambiguous Range notation to express 
start,length.

T.