lua-users home
lua-l archive

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


018-03-29 17:30 GMT+02:00 Dong Feng <middle.fengdong@gmail.com>:
>
>
> On Thu, 29 Mar 2018 at 01:52 Axel Kittenberger <axkibe@gmail.com> wrote:
>>
>> > Moreover, it is not strictly correct to say that Lua has 1-based
>> > indexing.
>>
>> Mixed 1-based and 0-based indexing is the worst possible state of affairs
>> regarding this for a programming system.
>>
>
> It's not if there is proper justification. 0-based indexing should be an
> "offset". It's justified in C because C array indexing is always an
> "offset". You can write:
>
> int a[3];
> 1[a] = 5;
> *(a+2) = 6;
>
> Not the case for all languages' arrays.

This comment is perceptive.

For files, it's always an offset, since a file has a position.

When it comes to ordinals, most natural languages call things first,
second, third, fourth etc, which naturally map to 1,2,3,4 etc.

There is just one place in Lua besides file offsets where base-0
should have been used: the position pattern (). It should have
captured the position just before the current position.
(''):match"()" should have been 0, not 1; ('abcd'):match'().*()'
should have been 0 and 4, not 1 and 5, etc. It annoys me in LPEG too.
But it's too late now.