From: Joseph Turner via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 63509@debbugs.gnu.org
Subject: bug#63509: [PATCH] Make copy-tree work with records
Date: Sun, 14 May 2023 20:57:17 -0700 [thread overview]
Message-ID: <87fs7yfdg2.fsf@breatheoutbreathe.in> (raw)
[-- Attachment #1: Type: text/plain, Size: 367 bytes --]
Hello,
copy-tree does not currently work with records:
(cl-defstruct foo bar)
(let* ((rec (make-foo :bar "hello"))
(copy (copy-tree rec t)))
(setf (foo-bar copy) "goodbye")
(foo-bar rec))
Expected "hello"; actual "goodbye".
Attached patch fixes this behavior.
Please tell me if I misunderstand the intended behavior of copy-tree.
Thank you,
Joseph
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-copy-tree-work-with-records.patch --]
[-- Type: text/x-diff, Size: 1440 bytes --]
From a20e119a0f60f85039726bf6ebcbe441060f9ef2 Mon Sep 17 00:00:00 2001
From: Joseph Turner <joseph@breatheoutbreathe.in>
Date: Sun, 14 May 2023 21:02:15 -0700
Subject: [PATCH] Make copy-tree work with records
---
lisp/subr.el | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lisp/subr.el b/lisp/subr.el
index 03d3324f3d8..9573b19ae7e 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -828,7 +828,7 @@ of course, also replace TO with a slightly larger value
"Make a copy of TREE.
If TREE is a cons cell, this recursively copies both its car and its cdr.
Contrast to `copy-sequence', which copies only along the cdrs. With second
-argument VECP, this copies vectors as well as conses."
+argument VECP, this copies vectors and records as well as conses."
(declare (side-effect-free error-free))
(if (consp tree)
(let (result)
@@ -839,8 +839,8 @@ argument VECP, this copies vectors as well as conses."
(push newcar result))
(setq tree (cdr tree)))
(nconc (nreverse result)
- (if (and vecp (vectorp tree)) (copy-tree tree vecp) tree)))
- (if (and vecp (vectorp tree))
+ (if (and vecp (or (vectorp tree) (recordp tree))) (copy-tree tree vecp) tree)))
+ (if (and vecp (or (vectorp tree) (recordp tree)))
(let ((i (length (setq tree (copy-sequence tree)))))
(while (>= (setq i (1- i)) 0)
(aset tree i (copy-tree (aref tree i) vecp)))
--
2.40.1
next reply other threads:[~2023-05-15 3:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-15 3:57 Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-05-15 11:26 ` bug#63509: [PATCH] Make copy-tree work with records Eli Zaretskii
2023-05-15 14:42 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-15 17:59 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-18 10:53 ` Eli Zaretskii
2023-05-18 19:05 ` Joseph Turner via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-05-19 6:07 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fs7yfdg2.fsf@breatheoutbreathe.in \
--to=bug-gnu-emacs@gnu.org \
--cc=63509@debbugs.gnu.org \
--cc=joseph@breatheoutbreathe.in \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).