GNU bug report logs - #51412
29.0.50; cl--mapcar-many fails inconsistently in the presence of circular lists; other shortcomings

Previous Next

Package: emacs;

Reported by: akater <nuclearspace <at> gmail.com>

Date: Tue, 26 Oct 2021 12:02:02 UTC

Severity: normal

Found in version 29.0.50

To reply to this bug, email your comments to 51412 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#51412; Package emacs. (Tue, 26 Oct 2021 12:02:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to akater <nuclearspace <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 26 Oct 2021 12:02:02 GMT) Full text and rfc822 format available.

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

From: akater <nuclearspace <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; cl--mapcar-many fails inconsistently in the presence of
 circular lists; other shortcomings
Date: Tue, 26 Oct 2021 11:50:00 +0000
cl--mapcar-many is used as a backend for implementing several cl-
functions in cl-extra.  To deal with arbitrary number of arguments
(passed to cl--mapcar-many as list cl-seq), it goes through them all
whenever there are more than 2, in advance, and attempts to compute the
minimal length.

This fails if any of the arguments is a circular list.

To reproduce, just evaluate (cl-map 'list #'identity '#1=(a . #1#) nil nil).

Note that (cl-map 'list #'identity '#1=(a . #1#) nil) doesn't fail so
this is at the very least inconsistent.  N.B.: CL spec says “Should be
prepared to signal an error” for improper lists for such functions.
Long story short, this means circular lists can be supported by CL
implementations according to CL spec.

Other shortcomings: going through all sequences in advance is very
inefficient.  mapcar-many also checks sequence types at runtime even
though they are known in advance which is also wasteful.

The mechanism used in recent suggested implementation of cl-map-into
https://lists.gnu.org/archive/html/emacs-devel/2021-10/msg00636.html
could be used to reimplement other sequence-oriented cl-extra functions
and resolve these issues, if it's merged.

I wrote some supporting macros there with a view towards this use; this
bug report is partially an apology for them.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#51412; Package emacs. (Wed, 14 Sep 2022 18:39:02 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: akater <nuclearspace <at> gmail.com>
Cc: 51412 <at> debbugs.gnu.org, Stefan Monnier <monnier <at> iro.umontreal.ca>
Subject: Re: bug#51412: 29.0.50; cl--mapcar-many fails inconsistently in the
 presence of circular lists; other shortcomings
Date: Wed, 14 Sep 2022 20:38:45 +0200
akater <nuclearspace <at> gmail.com> writes:

> cl--mapcar-many is used as a backend for implementing several cl-
> functions in cl-extra.  To deal with arbitrary number of arguments
> (passed to cl--mapcar-many as list cl-seq), it goes through them all
> whenever there are more than 2, in advance, and attempts to compute the
> minimal length.
>
> This fails if any of the arguments is a circular list.
>
> To reproduce, just evaluate (cl-map 'list #'identity '#1=(a . #1#) nil nil).

Debugger entered--Lisp error: (circular-list (a . #2))

> Note that (cl-map 'list #'identity '#1=(a . #1#) nil) doesn't fail so
> this is at the very least inconsistent.  N.B.: CL spec says “Should be
> prepared to signal an error” for improper lists for such functions.
> Long story short, this means circular lists can be supported by CL
> implementations according to CL spec.

It's inconsistent, so that should probably be fixed.  But isn't
signalling an error here the right thing to do?  But I guess as long as
not all the lists are circular, then it's fine to return something
here...

Perhaps Stafan has some comments; added to the CCs.




This bug report was last modified 2 years and 275 days ago.

Previous Next


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