[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Updated uFAQ (Unofficial Lua FAQ)
- From: Florian Weimer <fw@...>
- Date: Sun, 04 Sep 2011 12:41:51 +0200
* Tony Finch:
> Roberto Ierusalimschy <email@example.com> 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? :-)
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).