--On Tuesday, May 20, 2008 18:05:03 +0100 Michael Kay wrote:
Because the language was designed for users, not for programmers, and
users still have this old-fashioned habit of referring to the first
chapter in a book as Chapter One. (Though I did once hear Dijkstra refer
to the fourth slide in someone's presentation as the third.)
Dijkstra wrote a note "Why numbering should start at zero":
<http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html>
The book "Informal introduction to ALGOL 68" numbers its chapters from
zero. I remember that as being unusual, amusing, and also appropriate given
the audience.
(I fully agree that when handling tables, or subscripting into strings,
zero-based addressing would often be much more convenient. There are
arguments both ways, and as always, I can't tell you what the actual
history of the decision was; I can only post-rationalize it.)
Since XSLT does not have multi-dimensional sequences, the issues that arise
when multi-dimensional arrays can be treated as one-dimensional arrays do
not arise. Zero-based indexing tends to make the index formulae simpler
when accessing a multi-dimensional array with a one-dimensional array
access expression but on the whole I think it is best to just not do that
sort of thing at all.
I don't think that the age of language or design for programmer or user
arguments stand up very well.
FORTRAN is a counterexample to the "old languages use zero" argument, it
uses 1. Modern versions of FORTRAN allow the lower bound to be specified
(as Algol did) but the default is still 1.
Dartmouth BASIC used zero-based indexing, I have no information about why,
but I doubt if it has anything to do with being close to assembly code or
concern for the last ounce of speed.
I think that both of these languages were originally aimed at people who
did not think of themselves as being or intending to become programmers.
One related point here is that those thinking in terms of other programming
languages may be misled by the syntactic similarity of the XPath expression
para[1] to an array indexing expression in various other languages.
Understanding that para[1] is just a shorthand for para[position()=1] moves
the issue to the question of why position() is defined the way it is.
Defining last() to be the context size means that context position has to
count from one unless you are going to cause either 'last' or 'size' to
have a very counterintuitive meaning.
--
Owen Rees
========================================================
Hewlett-Packard Limited. Registered No: 690597 England
Registered Office: Cain Road, Bracknell, Berks RG12 1HN