[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Negative nth index
From: |
Mattias Engdegård |
Subject: |
Re: Negative nth index |
Date: |
Wed, 25 Dec 2024 11:30:20 +0100 |
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)).
>> 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.
And there's not much performance to gain from it: while a good compiler might
use it for value range propagation, as in
(use (nth n lis))
(if (< n 0) ...) ; dead if nth signals on negative n
it doesn't really justify a change.
- Re: Negative nth index, (continued)
- Re: Negative nth index, Eli Zaretskii, 2024/12/22
- Re: Negative nth index, Tassilo Horn, 2024/12/22
- Re: Negative nth index, Teemu Likonen, 2024/12/24
- Re: Negative nth index, Stefan Monnier, 2024/12/24
- Re: Negative nth index, Sebastián Monía, 2024/12/24
- Re: Negative nth index, Pip Cet, 2024/12/24
- Re: Negative nth index,
Mattias Engdegård <=
- Re: Negative nth index, Pip Cet, 2024/12/25
- Re: Negative nth index, Mattias Engdegård, 2024/12/25
- Re: Negative nth index, Pip Cet, 2024/12/25
- Re: Negative nth index, Stefan Kangas, 2024/12/25
- Re: Negative nth index, Stefan Monnier, 2024/12/25
- Re: Negative nth index, Stefan Kangas, 2024/12/25
Re: Negative nth index, Andreas Schwab, 2024/12/22