[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua is about to become history
- From: Chris Marrin <chris@...>
- Date: Wed, 03 May 2006 07:53:43 -0700
Reuben Thomas wrote:
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
property
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
string!).
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.
Please lets not start this religious war. The only important thing to
note here is that Lua is NOT an inherantly 1-based language. I use 0
based arrays all the time. I even occasionally create arrays that start
at -3 or 7. The only part of the language that cares about this is in
the construction of numerically indexed table literals, whose first
element is placed at one. Neither 0 nor 1 based arrays are better or
worse. You just need to understand the language constructs and use them
correctly.
--
chris marrin ,""$,
chris@marrin.com b` $ ,,.
mP b' , 1$'
,.` ,b` ,` :$$'
,|` mP ,` ,mm
,b" b" ,` ,mm m$$ ,m ,`P$$
m$` ,b` .` ,mm ,'|$P ,|"1$` ,b$P ,` :$1
b$` ,$: :,`` |$$ ,` $$` ,|` ,$$,,`"$$ .` :$|
b$| _m$`,:` :$1 ,` ,$Pm|` ` :$$,..;"' |$:
P$b, _;b$$b$1" |$$ ,` ,$$" ``' $$
```"```'" `"` `""` ""` ,P`
"As a general rule,don't solve puzzles that open portals to Hell"'