all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#50290: Using `setf` on `map-elt` repeats evaluation for returning the value of `setf`
@ 2021-08-31  2:58 Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2021-09-01  8:33 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-08-31  2:58 UTC (permalink / raw)
  To: 50290

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.






^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-01  8:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-31  2:58 bug#50290: Using `setf` on `map-elt` repeats evaluation for returning the value of `setf` Okamsn via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-09-01  8:33 ` Lars Ingebrigtsen

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.