unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#51412: 29.0.50; cl--mapcar-many fails inconsistently in the presence of circular lists; other shortcomings
@ 2021-10-26 11:50 akater
  2022-09-14 18:38 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: akater @ 2021-10-26 11:50 UTC (permalink / raw)
  To: 51412

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.





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#51412: 29.0.50; cl--mapcar-many fails inconsistently in the presence of circular lists; other shortcomings
  2021-10-26 11:50 bug#51412: 29.0.50; cl--mapcar-many fails inconsistently in the presence of circular lists; other shortcomings akater
@ 2022-09-14 18:38 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-14 18:38 UTC (permalink / raw)
  To: akater; +Cc: 51412, Stefan Monnier

akater <nuclearspace@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.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-14 18:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 11:50 bug#51412: 29.0.50; cl--mapcar-many fails inconsistently in the presence of circular lists; other shortcomings akater
2022-09-14 18:38 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).