From: raja@... (Raja S.) Date: 2000-12-10T02:40:02+09:00 Subject: [ruby-talk:6975] Re: Accessing an non-existing segment of an array >> My personal experience has been that when I ask for a segment of an >> array my intention is: "give me as much as you've got and truncate >> the rest". Of course, if that portion itself had nils in it then it >> is my responsibility to be able to handle them. >> >> 0 1 2 3 4 >> a = [2,3,5,7,11] >> >> b = a[3..10] #-> [7,11] >I guess my confusion comes from the intent of the code: why would you >ever _ask_ for elements outside the bounds of the array? You are right in that one would generally not -explicitly- ask for elements outside of the array. But when you ask for something like a[i..j] one -may- not always be sure that i & j will be within the current bounds of the array. So for primarily, -always- being able to do things along the line of for x in a[i..j] or a[i..j].each {...} ... i was wondering about the return value of a[i..j] for non-existing segments the merits of [] vs nil. Python returns []. Returning nil requires an explit check before each such iteration. Which is better? Though my preference at the moment is towards [] perhaps i'll need more exposure to the ruby way to identify the merits of nil. Regards, Raja