From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Alex Newsgroups: gmane.emacs.bugs Subject: bug#25154: 25.1; Bindings in cl-letf are in reverse order Date: Sat, 10 Dec 2016 12:05:40 -0600 Message-ID: <87bmwjy80b.fsf@gmail.com> References: <8737hwllow.fsf@gmail.com> <83zik4fdug.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1481393174 2966 195.159.176.226 (10 Dec 2016 18:06:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 10 Dec 2016 18:06:14 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: 25154@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Dec 10 19:06:10 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cFm2C-0007oh-IM for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Dec 2016 19:06:08 +0100 Original-Received: from localhost ([::1]:52660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cFm2F-00043v-6u for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Dec 2016 13:06:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cFm29-00043o-9x for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2016 13:06:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cFm26-0007Qk-4h for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2016 13:06:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:50046) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cFm25-0007Qg-Uo for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2016 13:06:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cFm25-0005Bq-Lp for bug-gnu-emacs@gnu.org; Sat, 10 Dec 2016 13:06:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alex Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Dec 2016 18:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25154 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: notabug Original-Received: via spool by 25154-submit@debbugs.gnu.org id=B25154.148139315819937 (code B ref 25154); Sat, 10 Dec 2016 18:06:01 +0000 Original-Received: (at 25154) by debbugs.gnu.org; 10 Dec 2016 18:05:58 +0000 Original-Received: from localhost ([127.0.0.1]:37212 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cFm21-0005BV-Vd for submit@debbugs.gnu.org; Sat, 10 Dec 2016 13:05:58 -0500 Original-Received: from mail-io0-f178.google.com ([209.85.223.178]:33636) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cFm20-0005BI-Ew for 25154@debbugs.gnu.org; Sat, 10 Dec 2016 13:05:56 -0500 Original-Received: by mail-io0-f178.google.com with SMTP id d9so108408216ioe.0 for <25154@debbugs.gnu.org>; Sat, 10 Dec 2016 10:05:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:in-reply-to:references:user-agent:date :message-id:mime-version; bh=OaGq1bfP/trsUsoXmf2l55nJtGgfa85NozxzTREyoKU=; b=CAlDbFk9fVP8Bi1H2hvLBtN7XMGLviGmmFklR8blg4ev+xVw3vBr4jzaSKRbJbUPjv /uJbrXwdDiE2CLFWO8boK7hXmRdxKb+QTTrI2CA/QGNLqAcGA0mSQUlivVsocQ3ktbKi roSCc0murX8LJe+IGh+81ExlYNWwhQfdaNbI/Ek1FUeCpn8kdXiIi4yBvBLYSK5pFGqQ z9udc5VpUKD/Eha6veTrCIG3SxPKEPi/ExOvkGiyV0JeWWEdB+EcP0wiU725ZvdB713J /c8B+CjNaXJpeBtlrYYU2EA7bUiULXXbi1qbyalY1rm7+yXFkhBZ9vQ7jpbgyScTqGM3 +Qyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references :user-agent:date:message-id:mime-version; bh=OaGq1bfP/trsUsoXmf2l55nJtGgfa85NozxzTREyoKU=; b=Wj4AHe3nC6cO2AtWm5ufMnsvE3oYtLHPEAmnFB74dNbPBapILAQ8fuyWm123pe9PSs fl0ZkSBVbwZG4EkWhKyaTvcr53PsP6Oi8FzziMjLNZiwnLP5G4AItKVCUp3Ymq2t9Rz6 hyJwnHVe/8ljZUmvLhl8Dw8f/3P00G7Su5l336BwdiiHDpkjT3twuwNinKqhPvY81j9R 5BgkQvTGqvKCv2xWvVcOqeU+rx2JhnfJFUwiTNUjwyECXDxh2Qg937BxkAe19JPXjQec Oc7xSYD1dEFCWfmmNPFH5vOorAeRVVrzX9uiRg2xe+lEhPY3J8crgOA2FX+D5k27rYgS qPEg== X-Gm-Message-State: AKaTC03zV5MCaHg/dzWR4c2gwbzGndpLB+MHXe/kN8Y54PO0YECMVJGU8Vwt1xHuStb8SA== X-Received: by 10.107.183.148 with SMTP id h142mr71690539iof.190.1481393151065; Sat, 10 Dec 2016 10:05:51 -0800 (PST) Original-Received: from lylat (S01061859339e9903.ss.shawcable.net. [174.2.107.88]) by smtp.gmail.com with ESMTPSA id x190sm9093639ite.14.2016.12.10.10.05.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 10 Dec 2016 10:05:50 -0800 (PST) In-Reply-To: <83zik4fdug.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 10 Dec 2016 09:22:15 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:126821 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Alex >> Date: Fri, 09 Dec 2016 17:36:15 -0600 >> >> Compare the following: >> >> (let ((x 5) >> (x 6)) >> (+ x 10)) >> >> => 16 >> >> (cl-letf ((x 5) >> (x 6)) >> (+ x 10)) >> >> => 15 > > Isn't it true that the order of evaluation in a 'let' is unspecified? > If you want a particular order, use 'let*'. I don't think so. See (info "(elisp) Local Variables"): All of the VALUE-FORMs in BINDINGS are evaluated in the order they appear I believe it should follow for cl-letf. Besides, even if it was unspecified, evaluating in the order they appear would be adhering to the principle of least astonishment. Though I realize that I have made a mistake in naming this bug and patch. The bigger issue is that all (PLACE VALUE) pairs of each type (simple and more importantly complex) were being evaluated in reverse order. Take for example: (cl-letf (((aref v 1) 10) ((aref w 2) 20)) (aref v 1)) This approximately expands to: (let* ((v v) (v w) (old (aref v 2)) (old (aref v 1))) (unwind-protect (progn (aset v 2 20) (aset v 1 10) (aref v 1)) (aset v 2 old) (aset v 1 old))) As you can see, the arefs and asets are evaluated in reverse order. Again, even if you argue that the order of evaluation for (PLACE VALUE) pairs is unspecified, it's evaluating them in an unexpected way for no good reason. I have attached a reworded patch that expands the above into the more expected: (let* ((v v) (v w) (old (aref v 1)) (old (aref v 2))) (unwind-protect (progn (aset v 1 10) (aset v 2 20) (aref v 1)) (aset v 1 old) (aset v 2 old))) --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Preserve-the-order-of-PLACE-VALUE-pairs-in-cl-letf.patch Content-Description: cl-letf patch reworded >From 184fa8dcb738923994d4b287931849b182bdb522 Mon Sep 17 00:00:00 2001 From: Alexander Gramiak Date: Fri, 9 Dec 2016 22:10:54 -0600 Subject: [PATCH] Preserve the order of (PLACE VALUE) pairs in cl-letf Do not reverse the order of (PLACE VALUE) pairs in cl-letf (Bug #25154). * lisp/emacs-lisp/cl-macs.el (cl--letf): Use nreverse to restore the order of (PLACE VALUE) pairs. --- 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 --=-=-=--