From: "Štěpán Němec" <stepnem@gmail.com>
To: Ivan Andrus <darthandrus@gmail.com>
Cc: 40692@debbugs.gnu.org
Subject: bug#40692: 28.0.50; Constant list modified inside function
Date: Sat, 18 Apr 2020 11:18:46 +0200 [thread overview]
Message-ID: <87ftd1883t.fsf@gmail.com> (raw)
In-Reply-To: <57990C74-5CA1-42E6-83EC-7F6858AFD0E7@gmail.com> (Ivan Andrus's message of "Fri, 17 Apr 2020 17:45:12 -0600")
On Fri, 17 Apr 2020 17:45:12 -0600
Ivan Andrus wrote:
> Starting from Emacs -Q (I am building off of trunk, but my brother verified the same behavior in 26.3), if I evaluate the following code I get an error the second time I call withdraw.
>
> (defmacro show (var)
> `(message ,(format "%S %%S" var) ,var))
>
> (defun my-test-fun (amount params)
> (when (memq 'tricked-ya params)
> (error "What happened here?"))
> (show amount)
> (show params)
> (setcdr (cdr params) (list 'tricked-ya))
> (show params))
>
> (defun fun-withdraw (amount)
> (my-test-fun amount
> `((amount . , amount)
> (const . some-constant))))
>
> (fun-withdraw 12)
>
> (fun-withdraw 12) ;; The second time it's called it will error because the "constant" list was modified.
>
>
> I believe this is the root cause of a bug in magit/forge https://github.com/magit/forge/issues/267 in which all subsequent pull requests created have the same name. The maintainer of magit/forge (tarsius) was unable to reproduce that bug, so I tried my hand at creating a minimal test case, and I was able to get it down to this.
>
> Now, I understand reference semantics of lists in general, but it
> seems like this should be different. If this behavior is intentional,
I think it is, although I admit I was confused by it, too, as I've
somehow come to believe that e.g. `(list) macroexpands to (list 'list),
but that's not the case: it expands to '(list).
> what's the best way to for creation of a new list every time so that
> functions using the alist don't have to worry about not changing the
> list?
If you change the backquoted form in `fun-withdraw' to
(list `(amount . ,amount)
'(const . some-constant))
it works as desired.
next prev parent reply other threads:[~2020-04-18 9:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-17 23:45 bug#40692: 28.0.50; Constant list modified inside function Ivan Andrus
2020-04-18 3:05 ` Ivan Andrus
2020-04-18 9:18 ` Štěpán Němec [this message]
2020-04-18 22:49 ` Michael Heerdegen
2020-04-19 7:08 ` Štěpán Němec
2021-08-29 22:18 ` Lars Ingebrigtsen
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ftd1883t.fsf@gmail.com \
--to=stepnem@gmail.com \
--cc=40692@debbugs.gnu.org \
--cc=darthandrus@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.