From: Okamsn via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 50290@debbugs.gnu.org
Subject: bug#50290: Using `setf` on `map-elt` repeats evaluation for returning the value of `setf`
Date: Tue, 31 Aug 2021 02:58:11 +0000 [thread overview]
Message-ID: <2cb39382-4974-9d9e-8e9a-b222f51fa18c@protonmail.com> (raw)
Hello,
When I do `(setf (map-elt map key) (my-func))`, it expands to
(let* ((key key))
(condition-case nil
(with-no-warnings
(map-put! map key (my-func) nil))
(map-not-inplace
(setq map (map-insert map key (my-func)))
(my-func))))
The repetition of `(my-func)` raises warnings. Compare with using
`(setf (alist-get key map) (my-func))`, where the result of `(my-func)`
is bound to `v` so that it is only called once:
(let* ((p (if (and nil (not (eq nil 'eq)))
(assoc key map nil)
(assq key map)))
(v (my-func)))
(progn
(if p
(setcdr p v)
(setq map (cons (setq p (cons key v))
map)))
v))
This is on Emacs 28 with Map.el 3.1.
next reply other threads:[~2021-08-31 2:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-31 2:58 Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-09-01 8:33 ` bug#50290: Using `setf` on `map-elt` repeats evaluation for returning the value of `setf` 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=2cb39382-4974-9d9e-8e9a-b222f51fa18c@protonmail.com \
--to=bug-gnu-emacs@gnu.org \
--cc=50290@debbugs.gnu.org \
--cc=okamsn@protonmail.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.