From: Chad Perrin Date: 2007-07-20T00:17:47+09:00 Subject: Re: The Pebble in the Ruby Shoe On Thu, Jul 19, 2007 at 06:13:56PM +0900, Adrian Howard wrote: > (taken off-list since wandering way OT :-) Understandable. > > On 17 Jul 2007, at 20:03, Chad Perrin wrote: > > >On Tue, Jul 17, 2007 at 10:43:35PM +0900, Adrian Howard wrote: > >> > >>Perl's misfeature is pretty different - it's a global rather than a > >>per-array thing. Being able to say "this particular array has indices > >>-10 -> 10 is considerably more useful than saying "every array starts > >>at -10" :-) > > > >News to me. Would you point me at more information on the topic, > >please? > > In the perl world we have the $[ variable (see perldoc perlvar for > gory details) that resets the index of the first element. As the > documentation says "Its use is highly discouraged.". I'd imagine that > it's primary motivation for inclusion was to make compatability with > awk easier in early perl's (which also has 1 indexing). I didn't know about the likely awk connection in the existence of $[, and didn't know early Perl used 1-indexing. I guess I learn something new every day. When I said something was news to me, however, I meant specifically your statement that the "fix" was global rather than per-array. I somehow read that as "it applies globally, and you can't make it apply per array", rather than how I now realize you meant it. When you first mentioned that, I thought you were saying there was something like perhaps a pragma that changed the way Perl handled arrays, or something like that. . . . but yeah, I see now you were just referring to the fact that $[ is a global variable. Of course, there's always the local hack: { local $[ = 1; # do stuff } > > For example: > > my @array = ( 1 .. 10 ); > > $[ = 0; > print @array[5], "\n"; > > $[ = 1; > print @array[5], "\n"; > > $[ = 2; > print @array[5], "\n"; > > would produce > > 6 > 5 > 4 > > Spooky action at a distance. Scary. A little weird, to be sure -- but awfully flexible if you need it, I suppose. Probably the most disturbing thing about it for me is the fact that, for each of the changes to $[ in your code snippet, that changes the behavior of *all* arrays. Downright terrifying. > > Fortran (or those versions that support it anyway) allow you to > specify the indices of a particular array - so for example you could > have > > real temperature(-100:100) > > to make an array of real values with indices from -100 to 100. So you > can make the indices of your array match the indices of your domain - > if that would make your life easier :-) I don't know any Fortran, so the talk of Fortran and arbitrary array ranges is entirely new to me -- and fascinating. The various differences of feature sets between languages really teaches some interesting principles, I find. > > See > for some examples. Thanks. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] Dr. Ron Paul: "Liberty has meaning only if we still believe in it when terrible things happen and a false government security blanket beckons."