Empty Array returned but expect nil

Hi,

Could someone please explain what I am (obviously) missing here?

Because [5,0] is out of array boundary.

  					matz.

But a[4] = nil ( it’s a 4-element Array), so isn’t a[4,0] also out of the
boundary?

Sorry if I’m being thick here.

Barry

···

Tired of spam? Get advanced junk mail protection with MSN 8.
http://join.msn.com/?page=features/junkmail

Hi,

Could someone please explain what I am (obviously) missing here?

Because [5,0] is out of array boundary.

matz.

But a[4] = nil ( it’s a 4-element Array), so isn’t a[4,0] also out of the
boundary?

Yes, but 5 is RIGHT out. :wink:

Sorry if I’m being thick here.

I don’t think you’re being thick… it’s one of
those “gotchas” in my opinion.

The explanation (which I can’t recall or repeat)
has to do with imagining that there is a “cursor”
that doesn’t point AT array elements, but at the
points IN BETWEEN them. (I seem to recall that
Emacs encourages this kind of thinking.)

Someone else can explain better.

Hal

···

----- Original Message -----
From: “Barry Shultz” barry_sh@hotmail.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Thursday, February 06, 2003 3:10 AM
Subject: Re: empty Array returned but expect nil

Hi,

But a[4] = nil ( it’s a 4-element Array), so isn’t a[4,0] also out of the
boundary?

Imagine index point at the beginning of elements, i.e.

a = [0,1,2,3]

0|1|2|3|
0 1 2 3 4 5
^

so that a[4,0] touches at the end of an array, whereas a[5,0] does
not.

						matz.
···

In message “Re: empty Array returned but expect nil” on 03/02/06, “Barry Shultz” barry_sh@hotmail.com writes: