From: Ronald Fischer Date: 2007-07-18T16:42:21+09:00 Subject: Re: The Pebble in the Ruby Shoe > In C the expression array[n] is actually just syntactic sugar for > *(array + n). Literally. I haven't tried in years, but the following > is supposed to be legitimate: n[array]. Great for obfuscating code. This indeed works, and consequently funny variations such as (n1-n2)[n2+array] work too. It is obfuscating not so much because it were not easy to understand, but because we simply are not used to see it written that way (because other languages usually do it in the other way around). To contrast with, the IMO most unpleasant way of approaching the index origin was done in APL. There, you could set the system variable _IO to either 0 or 1 (no other value accepted), which rules whether array the index of *any* array is from now on counted from 0 or from 1. True, you *could* localize this setting in a function, but at least in original APL (I don't know about APL2), these were not truly "local" variables like in Ruby, but more like those "local global" variables you would for example declare in Perl by writing 'local $v=....;', with the consequence that they the change to _IO would be visible in all functions called from within the function which had "locally" reset the index origin. This has the consequence that if you write *any* reusable function for APL (such as a library), you must use the value of this variable for indexing. For example, in order to access the Nth element of an array A, you would write something like A[N+_IO-1]. BTW: Though I - like most programmers - find it most convenient counting arrays from zero, there are cases where I would find it more natural if I could choose the upper and lower bound of an array by myself (as it is done in languages such as Ada). Such an approach would work well in a statically typed language (where you can in principle look up the variable declaration), but would make understanding a program unnecessarily hard in dynamic languages such as Ruby. Ronald