Am 05.03.2013 08:36, schrieb Jack R.:
> You're right, I missed the subtlety that 0 is "at the end" of an empty
> array.  But wouldn't -1 be "at the end" of an empty array also (since it
> is defined as being "the last element of the array")?  And while the

"At the end" is not the same as "the last element":

2.0.0-p0 :001 > a = [0,1,2]
  => [0, 1, 2]
2.0.0-p0 :002 > a[2,1]
  => [2]
2.0.0-p0 :003 > a[-1,1]
  => [2]
2.0.0-p0 :004 > a[3,1]
  => []

"At the end" here means the index *following* the last valid element,
and -1 is the index of the last element.

> is defined as being "the last element of the array")?  And while the
> documentation may be technically accurate, it certainly falls short of
> being "clear", since one would have to guess that 0 is "at the end" of
> an empty string. Least surprise, anyone?

I think this is consistent and clear (what would be the alternatives?).

Another way to view this (i.e. slicing with a range) is to think about
the index denoting the position _between_ the elements, starting with
position 0 before the first element. This IMO leads to a very consistent
description of the observed behaviour.


-- 
<https://github.com/stomar/>