[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Lua is about to become history
- From: Reuben Thomas <rrt@...>
- Date: Wed, 3 May 2006 12:55:26 +0100 (BST)
On Wed, 3 May 2006, John D. Ramsdell wrote:
I think you have to be very careful about making this case. How
tolerant of backwards-incompatibility do you thing the Lua user base
would be if the Lua authors modernized the language to support
zero-based array and string indexing? The greater difficulty of
writing correct code using one-based array indexing was obvious to all
when Fortran and C were two of the few major languages available, and
the lesson was not lost by the designers of the current popular
languages, such as Python. But at this stage, do you really think
that wart can be fixed?
Icon and Lua both demonstrate the benefit of 1-based indexing over
0-based: the ability to count forward from the start of a string and
backwards from the end symmetrically: 1 points to (just before) the
first character and -1 to (just before) the last. Hence, 0 points to
the end of the string, which seems a little odd, but if you use
zero-based addressing, you can no longer point to the end of the string.
There's another argument about whether you point at characters or the
gaps between them: if you insist on pointing at characters, you lose the
string.len(string.sub(s, a, b)) == b - a
for a, b of the same sign (and you STILL can't point at the end of a
It's not at all clear to me that 1-based indexing is inherently worse.
It gets you into trouble when you mix arrays and pointers, but who does
that nowadays? APL, a language whose numerical properties are most
carefully thought out, defaults to 1-based.
http://rrt.sc3d.org/ | Floc: an egregiously good aperitif