From: "Štěpán Němec" <stepnem@gmail.com>
To: npostavs@gmail.com
Cc: Michael Heerdegen <michael_heerdegen@web.de>,
35546@debbugs.gnu.org, Tassilo Horn <tsdh@gnu.org>
Subject: bug#35546: 27.0.50; setf return value for new alist entries is wrong
Date: Sun, 12 Apr 2020 14:26:52 +0200 [thread overview]
Message-ID: <87blnwdh4j.fsf@gmail.com> (raw)
In-Reply-To: <85woj2xl7l.fsf@gmail.com> (npostavs@gmail.com's message of "Tue, 07 May 2019 12:50:38 -0400")
[-- Attachment #1: Type: text/plain, Size: 662 bytes --]
tags 35546 + patch
thanks
On Tue, 07 May 2019 12:50:38 -0400
npostavs@gmail.com wrote:
> Michael Heerdegen <michael_heerdegen@web.de> writes:
>
>>> (setf (logand PLACE #x0F) V)
>
>> Anyway, there is no reason that the setter currently does not
>> return V, right?
>
> I can't see any compelling reason to return the whole PLACE value after
> update, so I guess it's just oversight. So yeah, it should return V
> just like the setters for `cl-subseq' and `nth' return the new value,
> not the whole sequence.
I noticed `substring' had the same problem.
Patch fixing that, together with cond and logand, attached.
--
Štěpán
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Preserve-setf-semantics-in-substring-cons-logand-exp.patch --]
[-- Type: text/x-patch, Size: 3528 bytes --]
From 90fcc412e85716ff348c3cc6fdcc06eb08b1f6ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= <stepnem@gmail.com>
Date: Sun, 12 Apr 2020 00:27:51 +0200
Subject: [PATCH] Preserve setf semantics in 'substring', 'cons', 'logand'
expanders
* doc/lispref/variables.texi (Adding Generalized Variables): Fix example.
* lisp/emacs-lisp/cl-lib.el (substring)
* lisp/emacs-lisp/gv.el (cons, logand): Return the value being
assigned, as specified for 'setf'. (bug#35546)
---
doc/lispref/variables.texi | 7 +++++--
lisp/emacs-lisp/cl-lib.el | 7 +++++--
lisp/emacs-lisp/gv.el | 18 ++++++++++++------
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index abcd4bbd0f..94c8c88796 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -2585,8 +2585,11 @@ Adding Generalized Variables
(macroexp-let2* nil ((start from) (end to))
(funcall do `(substring ,getter ,start ,end)
(lambda (v)
- (funcall setter `(cl--set-substring
- ,getter ,start ,end ,v))))))))
+ (macroexp-let2 nil v v
+ `(progn
+ ,(funcall setter `(cl--set-substring
+ ,getter ,start ,end ,v))
+ ,v))))))))
@end example
@end defmac
diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el
index 7a26d9a90f..7a4d3c9c3e 100644
--- a/lisp/emacs-lisp/cl-lib.el
+++ b/lisp/emacs-lisp/cl-lib.el
@@ -619,8 +619,11 @@ substring
(macroexp-let2* nil ((start from) (end to))
(funcall do `(substring ,getter ,start ,end)
(lambda (v)
- (funcall setter `(cl--set-substring
- ,getter ,start ,end ,v))))))))
+ (macroexp-let2 nil v v
+ `(progn
+ ,(funcall setter `(cl--set-substring
+ ,getter ,start ,end ,v))
+ ,v))))))))
;;; Miscellaneous.
diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el
index 065a968877..aa1516cc5e 100644
--- a/lisp/emacs-lisp/gv.el
+++ b/lisp/emacs-lisp/gv.el
@@ -517,9 +517,12 @@ gv-delay-error
(gv-letplace (dgetter dsetter) d
(funcall do
`(cons ,agetter ,dgetter)
- (lambda (v) `(progn
- ,(funcall asetter `(car ,v))
- ,(funcall dsetter `(cdr ,v)))))))))
+ (lambda (v)
+ (macroexp-let2 nil v v
+ `(progn
+ ,(funcall asetter `(car ,v))
+ ,(funcall dsetter `(cdr ,v))
+ ,v))))))))
(put 'logand 'gv-expander
(lambda (do place &rest masks)
@@ -529,9 +532,12 @@ gv-delay-error
(funcall
do `(logand ,getter ,mask)
(lambda (v)
- (funcall setter
- `(logior (logand ,v ,mask)
- (logand ,getter (lognot ,mask))))))))))
+ (macroexp-let2 nil v v
+ `(progn
+ ,(funcall setter
+ `(logior (logand ,v ,mask)
+ (logand ,getter (lognot ,mask))))
+ ,v))))))))
;;; References
--
2.26.0
next prev parent reply other threads:[~2020-04-12 12:26 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
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 [this message]
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=87blnwdh4j.fsf@gmail.com \
--to=stepnem@gmail.com \
--cc=35546@debbugs.gnu.org \
--cc=michael_heerdegen@web.de \
--cc=npostavs@gmail.com \
--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).