GNU bug report logs - #76472
nconc should fail for dotted lists

Previous Next

Package: emacs;

Reported by: Pip Cet <pipcet <at> protonmail.com>

Date: Fri, 21 Feb 2025 14:16:02 UTC

Severity: normal

Done: Pip Cet <pipcet <at> protonmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 76472 in the body.
You can then email your comments to 76472 AT debbugs.gnu.org in the normal way.

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#76472; Package emacs. (Fri, 21 Feb 2025 14:16:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Pip Cet <pipcet <at> protonmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 21 Feb 2025 14:16:02 GMT) Full text and rfc822 format available.

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

From: Pip Cet <pipcet <at> protonmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: nconc should fail for dotted lists
Date: Fri, 21 Feb 2025 14:14:44 +0000
The current behavior is:

(nconc '(1 . 2) '(3 4)) => (1 3 4)

This doesn't seem to me to match the documentation, because the cdr of
the first argument, 2, is discarded.  'append' signals in the equivalent
situation, and I think nconc should, too:

From 285a30392273552503fa6d66bf7a9bdb472f6a8e Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet <at> protonmail.com>
Subject: [PATCH] Make 'nconc' signal an error for dotted lists (bug#)

* src/fns.c (Fnconc): Call 'CHECK_LIST_END' for all but the last
element.
---
 src/fns.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/fns.c b/src/fns.c
index 0ba8e42a60f..720ddb666ca 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -3354,6 +3354,7 @@ DEFUN ("nconc", Fnconc, Snconc, 0, MANY, 0,
       Lisp_Object tail UNINIT;
       FOR_EACH_TAIL (tem)
 	tail = tem;
+      CHECK_LIST_END (tem, args[argnum]);
 
       tem = args[argnum + 1];
       Fsetcdr (tail, tem);
-- 
2.48.1

No indication in the git log that this behavior is intentional.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76472; Package emacs. (Fri, 21 Feb 2025 17:26:02 GMT) Full text and rfc822 format available.

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

From: Mattias Engdegård <mattias.engdegard <at> gmail.com>
To: 76472 <at> debbugs.gnu.org,
 Pip Cet <pipcet <at> protonmail.com>
Subject: bug#76472: nconc should fail for dotted lists
Date: Fri, 21 Feb 2025 18:25:21 +0100
> The current behavior is: (nconc '(1 . 2) '(3 4)) => (1 3 4) 

Actually that is probably intended and completely fine. It's what Common Lisp defines for this operation, and I don't think adding a nil check would be an improvement.





Reply sent to Pip Cet <pipcet <at> protonmail.com>:
You have taken responsibility. (Fri, 21 Feb 2025 18:04:02 GMT) Full text and rfc822 format available.

Notification sent to Pip Cet <pipcet <at> protonmail.com>:
bug acknowledged by developer. (Fri, 21 Feb 2025 18:04:03 GMT) Full text and rfc822 format available.

Message #13 received at 76472-done <at> debbugs.gnu.org (full text, mbox):

From: Pip Cet <pipcet <at> protonmail.com>
To: Mattias Engdegård <mattias.engdegard <at> gmail.com>
Cc: 76472-done <at> debbugs.gnu.org
Subject: Re: bug#76472: nconc should fail for dotted lists
Date: Fri, 21 Feb 2025 18:03:19 +0000
Mattias Engdegård <mattias.engdegard <at> gmail.com> writes:

>> The current behavior is: (nconc '(1 . 2) '(3 4)) => (1 3 4)
>
> Actually that is probably intended and completely fine. It's what
> Common Lisp defines for this operation, and I don't think adding a nil
> check would be an improvement.

Sorry for the noise, closing.

Pip





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#76472; Package emacs. (Sat, 22 Feb 2025 10:49:01 GMT) Full text and rfc822 format available.

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

From: "Basil L. Contovounesios" <basil <at> contovou.net>
To: Mattias Engdegård <mattias.engdegard <at> gmail.com>
Cc: Pip Cet <pipcet <at> protonmail.com>, 76472 <at> debbugs.gnu.org
Subject: Re: bug#76472: nconc should fail for dotted lists
Date: Sat, 22 Feb 2025 11:47:45 +0100
Mattias Engdegård [2025-02-21 18:25 +0100] wrote:

>> The current behavior is: (nconc '(1 . 2) '(3 4)) => (1 3 4) 
>
> Actually that is probably intended and completely fine. It's what Common Lisp
> defines for this operation, and I don't think adding a nil check would be an
> improvement.

Not just probably intended, but explicitly called out in the Elisp
manual:

     ...
     copied.  Instead, the last CDR of each of the LISTS is changed to
     refer to the following list.  The last of the LISTS is not altered.
     ...
     However, the other arguments (all but the last) should be mutable
     lists.  They can be dotted lists, whose last CDRs are then replaced
     with the next argument:

          (nconc (cons 1 2) (cons 3 (cons 4 5)) 'z)
               ⇒ (1 3 4 . z)

-- 
Basil




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 22 Mar 2025 11:24:17 GMT) Full text and rfc822 format available.

This bug report was last modified 140 days ago.

Previous Next


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