unofficial mirror of bug-gnu-emacs@gnu.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

* bug#50290: Using `setf` on `map-elt` repeats evaluation for returning the value of `setf`
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2021-09-01  8:33 UTC (permalink / raw)
  To: Okamsn; +Cc: 50290

Okamsn <okamsn@protonmail.com> writes:

> 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. 

Yup.  This should now be fixed on the trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ 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 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).