From: Alex <agrambot@gmail.com>
To: 25154@debbugs.gnu.org
Subject: bug#25154: 25.1; Bindings in cl-letf are in reverse order
Date: Fri, 09 Dec 2016 22:29:36 -0600 [thread overview]
Message-ID: <87shpwbe4v.fsf@gmail.com> (raw)
In-Reply-To: <8737hwllow.fsf@gmail.com> (Alex's message of "Fri, 09 Dec 2016 17:36:15 -0600")
[-- Attachment #1: Type: text/plain, Size: 563 bytes --]
Alex <agrambot@gmail.com> writes:
> Compare the following:
>
> (let ((x 5)
> (x 6))
> (+ x 10))
>
> => 16
>
> (cl-letf ((x 5)
> (x 6))
> (+ x 10))
>
> => 15
>
>
> This also occurs when using non-trivial places:
>
> (setq v (vector 1 2 3 4 5))
>
> (cl-letf (((aref v 1) 10)
> ((aref v 1) 20))
> (aref v 1))
>
> => 10
>
>
> I ran into this when using two different setters that sometimes
> indirectly modify the same variable. The current behaviour makes the
> result of that unexpected.
I attached a patch that fixes this issue:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: cl-letf patch --]
[-- Type: text/x-patch, Size: 1223 bytes --]
From 9a74f1e7f8d8cc77b111473f8ee53e46af8a9957 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Fri, 9 Dec 2016 22:10:54 -0600
Subject: [PATCH] Preserve the order of bindings in cl--letf
Do not reverse the order of the bindings in cl-letf (Bug #25154).
* lisp/emacs-lisp/cl-macs.el (cl--letf): Use nreverse to restore the
order of bindings.
---
lisp/emacs-lisp/cl-macs.el | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index 210a208..34f124f 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -2388,7 +2388,10 @@ cl--letf
;; VAL1; VAL2; PLACE1; bind1; PLACE2; bind2
;; Common-Lisp's `psetf' does the first, so we'll do the same.
(if (null bindings)
- (if (and (null binds) (null simplebinds)) (macroexp-progn body)
+ (if (and (null binds) (null simplebinds))
+ (macroexp-progn body)
+ (setq binds (nreverse binds))
+ (setq simplebinds (nreverse simplebinds))
`(let* (,@(mapcar (lambda (x)
(pcase-let ((`(,vold ,getter ,_setter ,_vnew) x))
(list vold getter)))
--
2.10.2
next prev parent reply other threads:[~2016-12-10 4:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-09 23:36 bug#25154: 25.1; Bindings in cl-letf are in reverse order Alex
2016-12-10 4:29 ` Alex [this message]
2016-12-10 7:22 ` Eli Zaretskii
2016-12-10 7:43 ` Tino Calancha
2016-12-10 13:41 ` Philipp Stephani
2016-12-10 14:01 ` Tino Calancha
2016-12-10 14:09 ` Eli Zaretskii
2016-12-23 12:17 ` Philipp Stephani
2016-12-23 12:46 ` Tino Calancha
2016-12-23 13:53 ` Eli Zaretskii
2016-12-23 16:30 ` Philipp Stephani
2016-12-10 18:05 ` Alex
2016-12-10 18:14 ` npostavs
2016-12-10 19:41 ` Alex
2016-12-10 18:27 ` Eli Zaretskii
2016-12-10 19:52 ` Alex
2016-12-11 3:11 ` Tino Calancha
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87shpwbe4v.fsf@gmail.com \
--to=agrambot@gmail.com \
--cc=25154@debbugs.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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.