unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Tassilo Horn <tsdh@gnu.org>
Cc: 35546@debbugs.gnu.org
Subject: bug#35546: 27.0.50; setf return value for new alist entries is wrong
Date: Tue, 07 May 2019 13:19:54 +0200	[thread overview]
Message-ID: <87ftpqmrz9.fsf@web.de> (raw)
In-Reply-To: <87lfznzm08.fsf@gnu.org> (Tassilo Horn's message of "Fri, 03 May 2019 15:49:11 +0200")

[-- Attachment #1: Type: text/plain, Size: 391 bytes --]

Tassilo Horn <tsdh@gnu.org> writes:

> According to the last sentence, I'd assume that
>
>   (setq my-alist nil)
>   (setf (alist-get 'foo my-alist) "foo-value")
>
> would return "foo-value", but infact it returns ((foo . "foo-value")).
> As soon as there is an association for 'foo, it returns the new value,
> i.e., "foo-value".

I agree.  I think fixing should be quite straightforward:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-alist-get-gv-setter-not-returning-VAL.patch --]
[-- Type: text/x-diff, Size: 2357 bytes --]

From 2fc149e3afa411f5b64c743de362378568f97bd6 Mon Sep 17 00:00:00 2001
From: Michael Heerdegen <michael_heerdegen@web.de>
Date: Mon, 6 May 2019 14:58:24 +0200
Subject: [PATCH] Fix alist-get gv setter not returning VAL

This fixes Bug#35546.

* lisp/emacs-lisp/gv.el (alist-get): Make setter return the set value
to preserve 'setf' semantics.
---
 lisp/emacs-lisp/gv.el | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el
index 4ea3ce84fc..bdd1574820 100644
--- a/lisp/emacs-lisp/gv.el
+++ b/lisp/emacs-lisp/gv.el
@@ -392,18 +392,20 @@ setf
                                  ,(funcall setter
                                            `(cons (setq ,p (cons ,k ,v))
                                                   ,getter)))))
-                         (cond
-                          ((null remove) set-exp)
-                          ((or (eql v default)
-                               (and (eq (car-safe v) 'quote)
-                                    (eq (car-safe default) 'quote)
-                                    (eql (cadr v) (cadr default))))
-                           `(if ,p ,(funcall setter `(delq ,p ,getter))))
-                          (t
-                           `(cond
-                             ((not (eql ,default ,v)) ,set-exp)
-                             (,p ,(funcall setter
-                                           `(delq ,p ,getter)))))))))))))))
+                         `(progn
+                            ,(cond
+                             ((null remove) set-exp)
+                             ((or (eql v default)
+                                  (and (eq (car-safe v) 'quote)
+                                       (eq (car-safe default) 'quote)
+                                       (eql (cadr v) (cadr default))))
+                              `(if ,p ,(funcall setter `(delq ,p ,getter))))
+                             (t
+                              `(cond
+                                ((not (eql ,default ,v)) ,set-exp)
+                                (,p ,(funcall setter
+                                              `(delq ,p ,getter))))))
+                            ,v))))))))))


 ;;; Some occasionally handy extensions.
--
2.20.1


[-- Attachment #3: Type: text/plain, Size: 11 bytes --]



Michael.

  reply	other threads:[~2019-05-07 11:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 13:49 bug#35546: 27.0.50; setf return value for new alist entries is wrong Tassilo Horn
2019-05-07 11:19 ` Michael Heerdegen [this message]
2019-05-07 13:43   ` Michael Heerdegen
2019-05-07 14:58     ` npostavs
2019-05-07 15:56       ` Michael Heerdegen
2019-05-07 16:50         ` npostavs
2020-04-12 12:26           ` Štěpán Němec
2020-04-12 12:34             ` Noam Postavsky
2020-04-12 12:47               ` Štěpán Němec
2020-04-13  1:01                 ` Michael Heerdegen
2020-08-19 10:34                   ` Lars Ingebrigtsen
2020-08-25 16:16                     ` Štěpán Němec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ftpqmrz9.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=35546@debbugs.gnu.org \
    --cc=tsdh@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).