GNU bug report logs - #40180
27.0.90; cl-concatenate returns wrong result

Previous Next

Package: emacs;

Reported by: Joost Kremers <joostkremers <at> fastmail.fm>

Date: Sun, 22 Mar 2020 09:02:01 UTC

Severity: normal

Tags: fixed, patch

Found in version 27.0.90

Fixed in version 27.1

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Stephen Berman <stephen.berman <at> gmx.net>
To: Joost Kremers <joostkremers <at> fastmail.fm>
Cc: 40180 <at> debbugs.gnu.org
Subject: bug#40180: 27.0.90; cl-concatenate returns wrong result
Date: Sun, 22 Mar 2020 12:07:29 +0100
[Message part 1 (text/plain, inline)]
On Sun, 22 Mar 2020 10:01:34 +0100 Joost Kremers <joostkremers <at> fastmail.fm> wrote:

> `cl-concatenate` seems to return the wrong result:
>
> ```
> ELISP> (cl-concatenate 'list '(a b c) '(d e f))
> ((a b c)  (d e f))
> ```
>
> In Emacs 26 the return value was `(a b c d e f)`, which I assume should still
> be the return value in Emacs 27, given that Common Lisp hasn't changed. :-)

Similarly, (cl-concatenate 'vector '[a b c] '[d e f]) returns `[[a b c]
[d e f]]' and worse, (cl-concatenate 'string "abc" "def") raises the
error: Wrong type argument: characterp, "abc".  This is because
cl-concatenate is now defined in terms of seq-concatenate, which is
defined by cl-defgeneric, which adds an extra pair of parens around the
SEQUENCES argument.  Hence, the following patch restores the correct
pre-27 behavior:

[Message part 2 (text/x-patch, inline)]
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index e3037a7190..adfb63dba8 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -289,11 +289,12 @@ seq-concatenate
 TYPE must be one of following symbols: vector, string or list.

 \n(fn TYPE SEQUENCE...)"
-  (pcase type
-    ('vector (apply #'vconcat sequences))
-    ('string (apply #'concat sequences))
-    ('list (apply #'append (append sequences '(nil))))
-    (_ (error "Not a sequence type name: %S" type))))
+  (let ((sequences (car sequences)))
+    (pcase type
+      ('vector (apply #'vconcat sequences))
+      ('string (apply #'concat sequences))
+      ('list (apply #'append (append sequences '(nil))))
+      (_ (error "Not a sequence type name: %S" type)))))

 (cl-defgeneric seq-into-sequence (sequence)
   "Convert SEQUENCE into a sequence.
[Message part 3 (text/plain, inline)]
Maybe cl-defgeneric should be fixed instead, but I don't understand it
well enough to do so.

Steve Berman

This bug report was last modified 5 years and 63 days ago.

Previous Next


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