lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


* Tony Finch:

> Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>>
>> I am going to discuss a little about 0-based x 1-based in my talk at the
>> Lua workshop, and my slides have exactly these arguments!!
>
> Do you have Dijkstra's note on the subject? :-)
> http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html

There's a little bit more to it.  If the language does not offer
slicing as a basic operation (like Lua or Java), most of the time, you
have to carry around indices denoting slices, and then it does not
really matter if the native starting index is 0 or 1.

With slicing support, you should better settle on 0 as the start
index.  Go does this, but Ada didn't, and the result is rather clumsy.
Ada is even more strange because slices preserve the original indices;
indexing is not relative to the start of the slice.

There's also the question whether to represent slices as start+length
or first+last indices.  I guess Alexander Stepanov showed that
first+last generalizes better to other data structures which are not
derived from arrays.  However, there is now some movement towards
direct representation of slices, even in C++ (e.g., Boost.Range).