[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Updated uFAQ (Unofficial Lua FAQ)
- From: David Kastrup <dak@...>
- Date: Tue, 30 Aug 2011 16:26:46 +0200
Dirk Laurie <dpl@sun.ac.za> writes:
> On Tue, Aug 30, 2011 at 09:00:15AM +0200, steve donovan wrote:
>> On Tue, Aug 30, 2011 at 8:30 AM, Axel Kittenberger <axkibe@gmail.com> wrote:
>> > 1.5.1 Why do Lua arrays count from one not zero?
>> > The answer does not answer the question. Why?
>>
>> That's a good point. In my experience engineers and scientists (who
>> have been infected with the Excel virus and hack with VBA) don't get
>> arrays starting at zero. And they can't read curly-brace languages
>> either.
>
> Because *people* count from one, not zero.
The starting point for _counting_ is zero (the state before counting the
first element). The starting point for _numbering_ is one.
> A harder question would be "why do arrays in some other languages count
> from zero not one?" The answer for C is a good one: "so that *(A+k) and
> A[k] mean the same".
In a language not having dynamically sized multidimensional arrays, the
index arithmetic for simulating them manually is much more pleasant when
arrays are zero-based.
In many cases where the phrase "index arithmetic" applies, zero-based
indexing leads to more straightforward expressions.
--
David Kastrup