emacs-devel
[Top][All Lists]
Advanced

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

Re: Negative nth index


From: Pip Cet
Subject: Re: Negative nth index
Date: Wed, 25 Dec 2024 10:56:26 +0000

Mattias Engdegård <mattias.engdegard@gmail.com> writes:

> 24 dec. 2024 kl. 22.33 skrev Pip Cet via Emacs development discussions. 
> <emacs-devel@gnu.org>:
>
>> I think the OP meant that (nth -1 '(1 2)) is 1 on current Emacs, which
>> is definitely unexpected.
>
> It's a straight consequence of (nth N L) = (car (nthcdr N L)).

s/nth/nthcdr/g in my email, then.  Of course the two should behave
analogously, the question is whether they should both throw an error (my
opinion) or shouldn't.

(My apologies for actually writing about nthcdr but calling it nth in
the last mail).

>>> I don't see a strong argument in favor of making it index from the end
>>> rather than signal an error.  What would the implementation look like?
>>
>> I agree, but the current implementation does not signal an error.  It
>> should, and I think that's what the suggestion was.
>
> It is true that signalling an error for negative arguments might catch
> some bugs but doing so would also risk breaking working code that
> relies on the current (well-defined) behaviour.

If it were merely undocumented, I might agree, but the current behavior
doesn't match the documentation, because taking cdr -1 times is
obviously an impossible thing to do.

> And there's not much performance to gain from it

This isn't about performance.

Pip




reply via email to

[Prev in Thread] Current Thread [Next in Thread]