GNU bug report logs - #79330
misleading ring-convert-sequence-to-ring

Previous Next

Package: emacs;

Reported by: Liu Hui <liuhui1610 <at> gmail.com>

Date: Thu, 28 Aug 2025 10:48:02 UTC

Severity: normal

To reply to this bug, email your comments to 79330 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#79330; Package emacs. (Thu, 28 Aug 2025 10:48:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Liu Hui <liuhui1610 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 28 Aug 2025 10:48:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Liu Hui <liuhui1610 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: misleading ring-convert-sequence-to-ring
Date: Thu, 28 Aug 2025 18:47:00 +0800
The docstring of ring-convert-sequence-to-ring says it "convert
sequence SEQ to a ring", but it actually ignores any item equal to the
first item, which is not mentioned:

ELISP> (ring-convert-sequence-to-ring '(a a a))
(2 1 . [nil nil a])

ELISP> (ring-convert-sequence-to-ring '(a b c a b c))
(1 5 . [nil c b c b a])

I think either the function or the docstring need to be fixed.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79330; Package emacs. (Thu, 28 Aug 2025 11:00:04 GMT) Full text and rfc822 format available.

Message #8 received at 79330 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Liu Hui <liuhui1610 <at> gmail.com>
Cc: 79330 <at> debbugs.gnu.org
Subject: Re: bug#79330: misleading ring-convert-sequence-to-ring
Date: Thu, 28 Aug 2025 13:59:33 +0300
--text follows this line-
> From: Liu Hui <liuhui1610 <at> gmail.com>
> Date: Thu, 28 Aug 2025 18:47:00 +0800
> 
> The docstring of ring-convert-sequence-to-ring says it "convert
> sequence SEQ to a ring", but it actually ignores any item equal to the
> first item, which is not mentioned:
> 
> ELISP> (ring-convert-sequence-to-ring '(a a a))
> (2 1 . [nil nil a])
> 
> ELISP> (ring-convert-sequence-to-ring '(a b c a b c))
> (1 5 . [nil c b c b a])
> 
> I think either the function or the docstring need to be fixed.

To decide whether we can fix the code would need to look at the
existing users of this function (not only in our tree), since it works
like it works for the last 18 years.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79330; Package emacs. (Fri, 29 Aug 2025 03:36:01 GMT) Full text and rfc822 format available.

Message #11 received at 79330 <at> debbugs.gnu.org (full text, mbox):

From: Liu Hui <liuhui1610 <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 79330 <at> debbugs.gnu.org
Subject: Re: bug#79330: misleading ring-convert-sequence-to-ring
Date: Fri, 29 Aug 2025 11:35:11 +0800
On Thu, Aug 28, 2025 at 6:59 PM Eli Zaretskii <eliz <at> gnu.org> wrote:
>
> --text follows this line-
> > From: Liu Hui <liuhui1610 <at> gmail.com>
> > Date: Thu, 28 Aug 2025 18:47:00 +0800
> >
> > The docstring of ring-convert-sequence-to-ring says it "convert
> > sequence SEQ to a ring", but it actually ignores any item equal to the
> > first item, which is not mentioned:
> >
> > ELISP> (ring-convert-sequence-to-ring '(a a a))
> > (2 1 . [nil nil a])
> >
> > ELISP> (ring-convert-sequence-to-ring '(a b c a b c))
> > (1 5 . [nil c b c b a])
> >
> > I think either the function or the docstring need to be fixed.
>
> To decide whether we can fix the code would need to look at the
> existing users of this function (not only in our tree), since it works
> like it works for the last 18 years.

I have checked the only one usage (i.e. eshell-index-value) in emacs
and many other examples in github. I think all users don't expect to
ignore an item that is equal to the first item. For example:

1. emacs -Q
2. (setq eshell-history-file-name nil)
3. M-x eshell
4. type the following commands separately in eshell buffer

echo 1
echo 2
echo 1
echo 2
echo $eshell-history-ring[-4..]

There should be four items in the last output, but actually three
items due to ring-convert-sequence-to-ring.


In other cases, the SEQ usually contains different items, so it works
in these years.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79330; Package emacs. (Sat, 06 Sep 2025 08:40:01 GMT) Full text and rfc822 format available.

Message #14 received at 79330 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Liu Hui <liuhui1610 <at> gmail.com>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 79330 <at> debbugs.gnu.org
Subject: Re: bug#79330: misleading ring-convert-sequence-to-ring
Date: Sat, 06 Sep 2025 11:38:54 +0300
> From: Liu Hui <liuhui1610 <at> gmail.com>
> Date: Fri, 29 Aug 2025 11:35:11 +0800
> Cc: 79330 <at> debbugs.gnu.org
> 
> On Thu, Aug 28, 2025 at 6:59 PM Eli Zaretskii <eliz <at> gnu.org> wrote:
> >
> > --text follows this line-
> > > From: Liu Hui <liuhui1610 <at> gmail.com>
> > > Date: Thu, 28 Aug 2025 18:47:00 +0800
> > >
> > > The docstring of ring-convert-sequence-to-ring says it "convert
> > > sequence SEQ to a ring", but it actually ignores any item equal to the
> > > first item, which is not mentioned:
> > >
> > > ELISP> (ring-convert-sequence-to-ring '(a a a))
> > > (2 1 . [nil nil a])
> > >
> > > ELISP> (ring-convert-sequence-to-ring '(a b c a b c))
> > > (1 5 . [nil c b c b a])
> > >
> > > I think either the function or the docstring need to be fixed.
> >
> > To decide whether we can fix the code would need to look at the
> > existing users of this function (not only in our tree), since it works
> > like it works for the last 18 years.
> 
> I have checked the only one usage (i.e. eshell-index-value) in emacs
> and many other examples in github. I think all users don't expect to
> ignore an item that is equal to the first item. For example:
> 
> 1. emacs -Q
> 2. (setq eshell-history-file-name nil)
> 3. M-x eshell
> 4. type the following commands separately in eshell buffer
> 
> echo 1
> echo 2
> echo 1
> echo 2
> echo $eshell-history-ring[-4..]
> 
> There should be four items in the last output, but actually three
> items due to ring-convert-sequence-to-ring.
> 
> 
> In other cases, the SEQ usually contains different items, so it works
> in these years.

Thanks.

I have no idea what is the significance of the first element of the
ring, and why no other element should be inserted that is equal to
that.  I could understand it if any consecutive 'equal' elements were
inserted only once, but that is not what the function does.

Stefan, any ideas why the code works as it is, and what, if anything,
we should do here?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79330; Package emacs. (Sun, 07 Sep 2025 15:12:02 GMT) Full text and rfc822 format available.

Message #17 received at 79330 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Liu Hui <liuhui1610 <at> gmail.com>, 79330 <at> debbugs.gnu.org
Subject: Re: bug#79330: misleading ring-convert-sequence-to-ring
Date: Sun, 07 Sep 2025 11:11:18 -0400
> I have no idea what is the significance of the first element of the
> ring, and why no other element should be inserted that is equal to
> that.  I could understand it if any consecutive 'equal' elements were
> inserted only once, but that is not what the function does.
>
> Stefan, any ideas why the code works as it is, and what, if anything,
> we should do here?

It's a part of the ring code I do not understand either, I'm afraid.


        Stefan





This bug report was last modified 3 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.