[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
- Re: Negative nth index, (continued)
- 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, 2024/12/25
- Re: Negative nth index,
Pip Cet <=
- 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