From unknown Thu Sep 11 06:33:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#50290: Using `setf` on `map-elt` repeats evaluation for returning the value of `setf` Resent-From: Okamsn Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 31 Aug 2021 02:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50290 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 50290@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Reply-To: Okamsn Received: via spool by submit@debbugs.gnu.org id=B.16303787089717 (code B ref -1); Tue, 31 Aug 2021 02:59:01 +0000 Received: (at submit) by debbugs.gnu.org; 31 Aug 2021 02:58:28 +0000 Received: from localhost ([127.0.0.1]:60806 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mKtyl-0002We-Kh for submit@debbugs.gnu.org; Mon, 30 Aug 2021 22:58:27 -0400 Received: from lists.gnu.org ([209.51.188.17]:45572) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mKtyh-0002WT-P8 for submit@debbugs.gnu.org; Mon, 30 Aug 2021 22:58:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKtyh-0005dt-9V for bug-gnu-emacs@gnu.org; Mon, 30 Aug 2021 22:58:23 -0400 Received: from mail-40131.protonmail.ch ([185.70.40.131]:36517) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mKtyd-00074N-Rc for bug-gnu-emacs@gnu.org; Mon, 30 Aug 2021 22:58:22 -0400 Date: Tue, 31 Aug 2021 02:58:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1630378695; bh=OpYhLJFG7pS6gZ2nSgZJSAqj/QBSYjs0TYOdRU58jcs=; h=Date:To:From:Reply-To:Subject:From; b=KSnxbmVXyNd9+Fbf6EsI2FzG5m2kBDtWZHX+hCjNxwUgFytIMgkAJzOsGv5HOa+Tq bnJztbC4X5x/7tmocO5lC4iypT1AP+9GU7ztFdhX61Zb4e09OzSYzKBQNVAFN7ysDg OZcGJSJivIofypPW9shmJm976hKTkf54972Mhtt4= From: Okamsn Message-ID: <2cb39382-4974-9d9e-8e9a-b222f51fa18c@protonmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Received-SPF: pass client-ip=185.70.40.131; envelope-from=okamsn@protonmail.com; helo=mail-40131.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) 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. From unknown Thu Sep 11 06:33:40 2025 X-Loop: help-debbugs@gnu.org Subject: bug#50290: Using `setf` on `map-elt` repeats evaluation for returning the value of `setf` Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 01 Sep 2021 08:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50290 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Okamsn Cc: 50290@debbugs.gnu.org Received: via spool by 50290-submit@debbugs.gnu.org id=B50290.163048520418699 (code B ref 50290); Wed, 01 Sep 2021 08:34:01 +0000 Received: (at 50290) by debbugs.gnu.org; 1 Sep 2021 08:33:24 +0000 Received: from localhost ([127.0.0.1]:36211 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mLLgR-0004rX-Q4 for submit@debbugs.gnu.org; Wed, 01 Sep 2021 04:33:23 -0400 Received: from quimby.gnus.org ([95.216.78.240]:57556) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mLLgP-0004rJ-L6 for 50290@debbugs.gnu.org; Wed, 01 Sep 2021 04:33:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=TQDkpp+ZueJXcXF63T/oZ/FYWCj+rH/t/iHeAi1uIqI=; b=StDLJxxOSfdZaMdNafy8Jkx0SM IRXQb/ue1w64F7ZsrBcRarXCD+p0uUFFq/tWKzKrjcMYpmBLNdZz4QIoqTDpBRSNdi/NJGZog+YFJ xUrt3dPrjyak4aXiKabf1xTdEBtzlJWQwbRmbFl1F8PBX9lrbtgOemLNY8kYkivHXT4A=; Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mLLgE-00031C-Qf; Wed, 01 Sep 2021 10:33:15 +0200 From: Lars Ingebrigtsen References: <2cb39382-4974-9d9e-8e9a-b222f51fa18c@protonmail.com> Date: Wed, 01 Sep 2021 10:33:10 +0200 In-Reply-To: <2cb39382-4974-9d9e-8e9a-b222f51fa18c@protonmail.com> (okamsn@protonmail.com's message of "Tue, 31 Aug 2021 02:58:11 +0000") Message-ID: <8735qohf09.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Okamsn 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- [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Okamsn 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 From debbugs-submit-bounces@debbugs.gnu.org Wed Sep 01 04:33:31 2021 Received: (at control) by debbugs.gnu.org; 1 Sep 2021 08:33:31 +0000 Received: from localhost ([127.0.0.1]:36214 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mLLgZ-0004rq-1o for submit@debbugs.gnu.org; Wed, 01 Sep 2021 04:33:31 -0400 Received: from quimby.gnus.org ([95.216.78.240]:57570) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mLLgW-0004rW-R2 for control@debbugs.gnu.org; Wed, 01 Sep 2021 04:33:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Subject:From:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=58SYJSuOyYmAVKOmBUt3rh+tDWZ/IkDyp8xmXBBmOR8=; b=J0ANzxJbCvtkgFLHQdTPQQXGTJ SEYDsBcRjvgIYLuwIk1aNgYFDx0HTqLKs/NqlwExfdGV+lnN3ZCHX8EjbFcKWQOcBjZNO6xwYCyzs FU/5Jo8SPuLS3o2C7cNxq4b3HJziZ/o5iBUM4RYXC7m+qLTthOKxw7YysYnmIfFulT3I=; Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mLLgO-000325-Vw for control@debbugs.gnu.org; Wed, 01 Sep 2021 10:33:23 +0200 Date: Wed, 01 Sep 2021 10:33:16 +0200 Message-Id: <871r68hf03.fsf@gnus.org> To: control@debbugs.gnu.org From: Lars Ingebrigtsen Subject: control message for bug #50290 X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: close 50290 28.1 quit Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) close 50290 28.1 quit