From: Ben Tilly Date: 2000-12-10T01:21:17+09:00 Subject: [ruby-talk:6971] Re: Accessing an non-existing segment of an array Dave Thomas wrote: > >raja@cs.indiana.edu (Raja S.) writes: > > > 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? > I have felt the convenience in Perl. For instance: while (my @group = splice(@list, 0, 10)) { # Do something with the group of entries } The point being to push down to the language all of the logic about where the boundaries of the array are. This snippet for implementing paging logic would be much longer if I had to concern myself with logic about finding the boundary of the array. Instead I just know that it will exit correctly, and might sometimes give me fewer elements. Cheers, Ben _____________________________________________________________________________________ Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com