From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Heerdegen via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#70524: [PATCH] Fix `map-elt` with `setf` for subplaces Date: Wed, 24 Apr 2024 08:06:11 +0200 Message-ID: <87a5lji9bg.fsf@web.de> References: Reply-To: Michael Heerdegen Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21567"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: okamsn@protonmail.com, Stefan Monnier To: 70524@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 24 08:07:28 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rzVmx-0005SL-Id for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 24 Apr 2024 08:07:27 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rzVmV-0001nf-0n; Wed, 24 Apr 2024 02:06:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rzVmS-0001nF-K0 for bug-gnu-emacs@gnu.org; Wed, 24 Apr 2024 02:06:56 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rzVmS-000178-C3 for bug-gnu-emacs@gnu.org; Wed, 24 Apr 2024 02:06:56 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rzVmi-0004ol-3Z; Wed, 24 Apr 2024 02:07:12 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Heerdegen Original-Sender: "Debbugs-submit" Resent-CC: monnier@iro.umontreal.ca, bug-gnu-emacs@gnu.org Resent-Date: Wed, 24 Apr 2024 06:07:11 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70524 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: Okamsn via "Bug reports for GNU Emacs, the Swiss army knife of text editors" X-Debbugs-Original-Cc: Okamsn , 70524@debbugs.gnu.org X-Debbugs-Original-Xcc: Stefan Monnier Original-Received: via spool by 70524-submit@debbugs.gnu.org id=B70524.171393877518042 (code B ref 70524); Wed, 24 Apr 2024 06:07:11 +0000 Original-Received: (at 70524) by debbugs.gnu.org; 24 Apr 2024 06:06:15 +0000 Original-Received: from localhost ([127.0.0.1]:56619 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rzVlg-0004fj-89 for submit@debbugs.gnu.org; Wed, 24 Apr 2024 02:06:13 -0400 Original-Received: from mout.web.de ([212.227.17.12]:55701) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rzVlV-0004d5-5d for 70524@debbugs.gnu.org; Wed, 24 Apr 2024 02:06:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=web.de; s=s29768273; t=1713938732; x=1714543532; i=michael_heerdegen@web.de; bh=S2fmGG7Yjxya7Nh2FYJlmaCziFwhBtkGYlQolngkbb8=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=Uw+ZIPSi5W7asrfedalC3m5bB//Q1bMFfI7oizpF7tqY2b0A/+KDxzpuLv6h03ex YkMgM4EC56oNpNJsynn6i+oTueDTK9XsFvmYyaQCVDcZJOisOd0PyLikOxL9T9/d8 sQMjPAHMSA8EeY4MKlZR4S3AR5WSfm1AB61Cs4RjRkjm15By3ziM9ZVAl75GUDhpg Pwv/C303xzkrGP4iS8fsJN8Pd1BGic5/zqLeOj/Pil77g4iiii1f7eZbyPSV876LU PtoYQO8efhROjBF9JMO1M+kNuzSoYOmhOV940Qu+NyxAvhvmkPlgt0IirnNPccxQl Rs3mmE+6drYEbFg/8A== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Original-Received: from drachen.dragon ([84.57.248.23]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1M2PdU-1ryyag168E-002FHm; Wed, 24 Apr 2024 08:05:32 +0200 In-Reply-To: (Okamsn via's message of "Tue, 23 Apr 2024 02:10:42 +0000") X-Provags-ID: V03:K1:yt94WHa47iCOv5QvRXzeHh3rUJUZdv84R/tHLRjRmUO778NoPYc Uukdpkrd5IJNsSSC7uFjfCtBp+5gxtAdjbifr7O9d1gygby6bSLvVVSpdjh+r5JUTtrq8ra j66en3P3nFCjWlfAzaak4q46fqkyVVojEbZpDSGARXwRgJrUoUHuJnXMaivoNjazX6y8jqC iVqLVDKjn8rEKcVaye/PA== UI-OutboundReport: notjunk:1;M01:P0:NCQwoI8XnHI=;oqv2dkSlihf+r43bGvqyYjuxjhb +Ghi58y28GzEEOwQkClM9BBtxWDHgpzQIHhs05ls1BfanTi1UetV8xl2Cnl0sIa7GSBJipMmr 8coIBBrxRgxs+G7tATi26RC+pLc8vnWrJWm7BdUYUU41gNjPT5b7CFggo7NFe0bsQamzBt0dw +TQTGL3vSZLE8VlAcp91j2/0kzYzGBKp05JYR8yPADlkal2KFgWUg1PLm0n/w1YBaOhOxCVjW lhOKKg7b86fe8hmh3VLjF3EaIWLX2nUtUD7DqyEWWBT3aMjQ1O3rtonAyEdYwxC7hZF/d8iEz XnZyrsA3lCL1e/VXvdJ6g2Rq1xtbqdChzMK+5VFPj+Sx9C5/r/O5vim4xPrVdwDsbeVeowN/e hijN+/RJzNVqHZUnIgQluAnUJrCirexG4p9hP6jksmjREtj7ZR0x4f01SsHgm3wg1ntaYVTqm olXPsmZLpt58mCWLtW8tVtXmXFuNt25hm5W5QReCzeqTjfcYMv0wm9lZZg4waM14zzsU0XY90 +3R4rKtB7SOf8E3tWjpIFQy7OU24Rq+t3viDkFThSvfBi6ZQjSh+FcEC25uSxXXlhWCkwp+VY bl3rVCnOVn57mJTepA6mJ3X/r+N5SrkoqC984o0l2GJwvZmTGGoXwcKgeP9Qwt68cJKdBEOkd jyOxkU9DCDvHQYrI9E7fhBWbN0BsBmg/COjo+ebXUChkBz5IMQdhLGRlZSjjNIZGFKotSpIv7 gJF8r71lDvgslEnBusmrI5kIpf7VBXvsrFhncnjyOHYJM5WvTMNkmYdQH5cxRtADSYYfTTy8 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:283903 Archived-At: Hello Okamsn, let's CC Stefan. Nice to see you are working on this stuff. > Hello, > > Currently, the use > > (let ((arr (vector 0 1 2 3 4 5 6))) > (setf (map-elt (cl-subseq arr 3) 0) > 27) > arr) > > expands to [...] But... I must admit I'm not really convinced that this has to be changed. First, it is not crystal clear what the semantics should be in this case, because `cl-subseq' as a function creates a new sequence. But it's also a gv so it's debatable, ok. But second - doesn't your patch lead to very inefficient code in this example, where nearly all elements of the original sequence get replaced by themselves in a loop (through the setter of `cl-subseq')? Maybe there are other examples. But cases where the first argument given to `map-elt' returns a part of the original structure (like e.g. a `car' call) work (and there the semantics is also clearer). So I wonder if this change is really an improvement. But if we install it, --- lisp/emacs-lisp/map.el | 6 +++++- test/lisp/emacs-lisp/map-tests.el | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el index d3d71a36ee4..facfdd8de7b 100644 --- a/lisp/emacs-lisp/map.el +++ b/lisp/emacs-lisp/map.el @@ -167,7 +167,11 @@ map-elt `(condition-case nil ;; Silence warnings about the hidden 4th arg. (with-no-warnings - (map-put! ,mgetter ,key ,v ,testfn)) + ,(macroexp-let2 nil m mgetter + `(progn + (map-put! ,m ,key ,v ,testfn) + ,(funcall msetter m) + ,v))) (map-not-inplace I guess you should move the `with-no-warnings' wrapper along with the comment to the inside, around the `map-put!' it is intended for. Michael.