I was going through the exercises at http://rubykoans.com/ and got
struck with the following problem:

array = [:peanut, :butter, :and, :jelly]

array[0]        => :peanut
array[0,1]     => [:peanut]
array[0,2]     => [:peanut, :butter]
array[0,0]     => []
array[2]        => :and
array[2,2]     => [:and, :jelly]
array[2,20]   => [:and, :jelly]
array[4]        => nil              # This is OK
array[4,0]     => []               # why is this an empty array and not
nil?
array[4,100] => []               # why is this an empty array and not
nil?
array[5]        => nil              # as expected
array[5,0]     => nil              # as expected

I have gone through the Ruby doc to get an explanation of this behavior,
but there it is marked as '# special cases' but there is no explanation
of this behavior. I being a newb, it would be of immense help if you can
give me some pointers where I can find a correct explanation of this
behaviour.

The python slices seem to behave similarly

arr = [1, 2, 3]

arr[3] # Gives IndexError: list index out of range
>>> arr[3:3] # gives []
>>> arr[3:4] # gives []

But I could not find an explanation in the python docs either.

Thanks

-- 
Posted via http://www.ruby-forum.com/.