From: Arthur Miller <arthur.miller@live.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Noob question: why sequences, lists in particular start at index 0 in Elisp?
Date: Sun, 08 Nov 2020 17:04:44 +0100 [thread overview]
Message-ID: <VI1PR06MB4526260B8DE550FB0A5EDE2796EB0@VI1PR06MB4526.eurprd06.prod.outlook.com> (raw)
In-Reply-To: <jwvlffb52uj.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sun, 08 Nov 2020 09:42:42 -0500")
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> I understand why they do so in C; but why in Elisp?
>
> Why should it be different in ELisp?
Because ELisp is not designed to be machine-close language easily
implemented in almost a one-pass compiler that translates it's references to
memory addresses directly? I am not sure it even makes sence for C; what
does it save? An extra addition? Is it worth?
But more because we humans thing in terms of first, second, etc.
Algorithms look much nicer when we can write [1,length] instead of
[0,length-1]. I could even find Pascal indexing to be useful sometimes.
Numerical Recipes had nice practice for their code; they would type
pointer-- on base pointer so they could write algorithms as in
[1,length] (and yes I know they abandoned the practice in C++ edition).
I have red Dijkstra's paper on the issue from 1982, and I am not sure I
agree. He writes:
"the subscript range ( ... ); starting with 0, however, gives the nicer
range 0<= i < N". Well, yes; but only when iterating so we can write i <
N, instead of i <= N, or i != N. Yes he derives it from the mathematical
notion of smallest natural number; but then is 0 a number? More
important does it really matter?
When accessing the element in subscript one has to write array[N-1]; so
I am not sure that is so much nicer then to type i <= N. As I
understand, that is his main argument, and I don't think it is
strong enough. Actually I think it is more practical to use [1,N] then
[0,N-1] in a higher level language. Yes, we can also just define
something like "first" and "last" in our program; but then it is just
our "local" convention, which opens for missunderstanding and misstakes.
If it is supported on the language level, then users of that language should
have it as a rule, rather then just a package convention (opposite what
Dijkstra argues in his paper).
> AFAIK, indexing should always be 0-based, so we don't get into silly "is
> 1900 in the 19th century or the 20th century".
I am sure we can construct examples that support both arguments, since
bot versions make sense in different scenarios.
> And indeed computer
> science got this mostly right,
I dunno what to say; I am probably too pragmatic to support statements
of kind that there is always one right way. I find it a bit dogmatic to
say computer science got it right.
> except for Fortran arrays and
> Emacs buffers.
Njah, I prefer moving to first line, not 0th line. I would refer to
Monnier's first paper, not 0th paper, I would probably direct someone to
first street to the right, not the 0th street. No?
Please, forgive me if I am annoying; I am just trying to understand it
better. Personally I think that higher level languages should probably
be closer to natural language and human reasoning, while assemblers or
maybe a language like C, very close to machine should probably be closer
to the machine.
next prev parent reply other threads:[~2020-11-08 16:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-08 13:32 Noob question: why sequences, lists in particular start at index 0 in Elisp? Arthur Miller
2020-11-08 14:42 ` Stefan Monnier
2020-11-08 16:04 ` Arthur Miller [this message]
2020-11-08 16:16 ` Eli Zaretskii
2020-11-08 15:42 ` Philipp Stephani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=VI1PR06MB4526260B8DE550FB0A5EDE2796EB0@VI1PR06MB4526.eurprd06.prod.outlook.com \
--to=arthur.miller@live.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.