GNU bug report logs - #50290
Using `setf` on `map-elt` repeats evaluation for returning the value of `setf`

Previous Next

Package: emacs;

Reported by: Okamsn <okamsn <at> protonmail.com>

Date: Tue, 31 Aug 2021 02:59:01 UTC

Severity: normal

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Okamsn <okamsn <at> protonmail.com>
To: 50290 <at> 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
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.





This bug report was last modified 3 years and 348 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.