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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 50290 in the body.
You can then email your comments to 50290 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#50290; Package emacs. (Tue, 31 Aug 2021 02:59:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Okamsn <okamsn <at> protonmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 31 Aug 2021 02:59:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Okamsn <okamsn <at> protonmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 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.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#50290; Package emacs. (Wed, 01 Sep 2021 08:34:01 GMT) Full text and rfc822 format available.

Message #8 received at 50290 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Okamsn <okamsn <at> protonmail.com>
Cc: 50290 <at> debbugs.gnu.org
Subject: Re: bug#50290: Using `setf` on `map-elt` repeats evaluation for
 returning the value of `setf`
Date: Wed, 01 Sep 2021 10:33:10 +0200
Okamsn <okamsn <at> 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




bug marked as fixed in version 28.1, send any further explanations to 50290 <at> debbugs.gnu.org and Okamsn <okamsn <at> protonmail.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 01 Sep 2021 08:34:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 29 Sep 2021 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 208 days ago.

Previous Next


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