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#6583: 23.2; cl loop macro with `and' clause Date: Sat, 10 Jun 2017 13:10:32 -0600 Message-ID: <87d1abu09j.fsf@gmail.com> References: <871vbedfzq.fsf@blah.blah> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1497121882 9838 195.159.176.226 (10 Jun 2017 19:11:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 10 Jun 2017 19:11:22 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: 6583@debbugs.gnu.org To: Kevin Ryde Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jun 10 21:11:13 2017 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 1dJlmz-00026G-13 for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Jun 2017 21:11:13 +0200 Original-Received: from localhost ([::1]:59955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJln4-00059L-44 for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Jun 2017 15:11:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dJlms-00057F-FW for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2017 15:11:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dJlmp-0007Yg-8l for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2017 15:11:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36687) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dJlmo-0007YY-UQ for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2017 15:11:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dJlmo-0000RS-Q3 for bug-gnu-emacs@gnu.org; Sat, 10 Jun 2017 15:11:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alex Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Jun 2017 19:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6583 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed Original-Received: via spool by 6583-submit@debbugs.gnu.org id=B6583.14971218581681 (code B ref 6583); Sat, 10 Jun 2017 19:11:02 +0000 Original-Received: (at 6583) by debbugs.gnu.org; 10 Jun 2017 19:10:58 +0000 Original-Received: from localhost ([127.0.0.1]:39363 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dJlmk-0000Qx-IN for submit@debbugs.gnu.org; Sat, 10 Jun 2017 15:10:58 -0400 Original-Received: from mail-io0-f193.google.com ([209.85.223.193]:36387) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dJlmh-0000QT-Sp; Sat, 10 Jun 2017 15:10:57 -0400 Original-Received: by mail-io0-f193.google.com with SMTP id i93so7589985iod.3; Sat, 10 Jun 2017 12:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=aGYHJ05nPb3Yfc+i+QfM6O6PdLLLuJ4dHIxAl5vr3LY=; b=t+sBRa9xKkRjArsSj5838M3KLZ2Xyl0RhqlL5teKS7RBJCnt3GV1M/nTNWyErPYLKE 4oRZ93PK3+LDZcV69BZIr2IVNvBNEPq5gDXyLI49pyC8ecqECr31a+wZHNAT7M5R7bfI suYl0c8067V9uoQJhsoo1oZhuYOiI4GOcmFwC2nwbTr06JsJM/KPc1gGfAP51XtEXN+R cuqQHu8Q5JjD4sh5ZKbTge7/7DcZfZvGvNulYzVBfaD0aHwD20CjxaAJBGSfQih9Qssh Mq6j9Z9EZchOmaosxqg0U9BkSBKwZSHJ51z7x9k/jneB18TmvT0cDCkCAd+LCHFLYr36 HN/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=aGYHJ05nPb3Yfc+i+QfM6O6PdLLLuJ4dHIxAl5vr3LY=; b=n47BVpgygtthMF+9XZkKFAiR/L1MpKaZaow8+3jr8WyoWX+neGV6wc4YzLwV3VP99P o4OFXkDdwm3bnusBzrSpBMbFRUcsTMVuHMbA46PSy1isTd69/AdSUXUsX4WSiooFn/dn gEo+CJCJN41j9cuRQaprX3qCrBgNiYEyhjX3KErzOrLtYOH3uyQ+z3yHJQYDF4GE7f9H gACU1xb0SKempbp3XchvvzNcSj7exxcxx5ljZd+MQhcrGq22F/9/f0M7yY2zeND0uCJw G8KjjtjM3XQNLaVypLCp5GfDyHL+WxNC8ejDqYohvCA2OtNaecNY2erlyIzvGI6vmKUR k1fA== X-Gm-Message-State: AODbwcDTNIRHlDZGtp4ECeLKcEYbTHbSJGbRk0ybpy6EyW4BEOQJlA/Q C4ZbYHNB+8oEUzxq X-Received: by 10.107.53.152 with SMTP id k24mr19585774ioo.7.1497121849883; Sat, 10 Jun 2017 12:10:49 -0700 (PDT) Original-Received: from lylat (S010664777d9cebe3.ss.shawcable.net. [70.64.85.59]) by smtp.gmail.com with ESMTPSA id e8sm2245255iod.56.2017.06.10.12.10.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 10 Jun 2017 12:10:48 -0700 (PDT) In-Reply-To: <871vbedfzq.fsf@blah.blah> (Kevin Ryde's message of "Thu, 08 Jul 2010 09:33:29 +1000") 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:133453 Archived-At: --=-=-= Content-Type: text/plain tags 6583 patch quit Kevin Ryde writes: > Evaluating > > (require 'cl) > (loop for elem in '(1 2 3) > for k = elem and j = 99 > do > (print k)) > > shows > > 1 > 1 > 2 > > where I thought it might be > > 1 > 2 > 3 > > I'm don't know much about the cl loop macro but thought the `for k' step > would be evaluated after the `for elem' step, "sequential" per the cl > info manual near the end of "For Clauses" > > If you include several `for' clauses in a row, they are treated > sequentially > > The 1,2,3 is what you get from pasting the same form into clisp, if that > suggests what an actual common lisp does or should do. And in Emacs > it's had if you omit the "and j", > > (loop for elem in '(1 2 3) > for k = elem > do > (print k)) > => > 1 2 3 > > Nosing around the macro expansion I wondered if the "step" of k/j gets > mispositioned if there's an `and', but it's hard to be sure. > > > I struck this when making a loop over an alist where I thought to take > apart the key and value with an `and' as they didn't need to be > sequential, > > (loop for elem in my-alist > for k = (car elem) and v = (cdr elem) > do > ... > > Alas the effect of the "1 1 2" was to double the first element and omit > the last. This problem appears to have been present even in the initial revision (fcd737693e8), specifically in the (eq word '=) clause. I see no reason for the (or ands (eq (car args) 'and)) consequent, as what it does when it detects an 'and is: * In the first iteration, set var (k) to the first form (elem) at the beginning of the iteration * In subsequent iterations, set var (k) to itself at the beginning of the iteration (noop) * At the end of every iteration, set var (k) to the second form (defaulting to the first form, elem). The last point is the main problem: you can't set the variable to the first form at the end of the iteration as it might depend on other loop variables (in this case elem) that are updated at the beginning of the iteration. I've attached a patch below that appears to solve this issue. With the patch, var is set to the first or second form at the beginning of the iteration (just like it is when no 'and is present). --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Fix-and-in-cl-loop-s-for-as-equals-then-subclause.patch Content-Description: loop >From 48c59a8609e325690d9568d991bea7fd199a1acd Mon Sep 17 00:00:00 2001 From: Alexander Gramiak Date: Sat, 10 Jun 2017 12:26:48 -0600 Subject: [PATCH] Fix 'and in cl-loop's for-as-equals-then subclause Update variables in the subclause correctly, and only once (Bug#6583). * lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause): Remove faulty conditional branch. --- lisp/emacs-lisp/cl-macs.el | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el index db1518ce61..8222f0dc34 100644 --- a/lisp/emacs-lisp/cl-macs.el +++ b/lisp/emacs-lisp/cl-macs.el @@ -1273,22 +1273,13 @@ cl--parse-loop-clause (then (if (eq (car cl--loop-args) 'then) (cl--pop2 cl--loop-args) start))) (push (list var nil) loop-for-bindings) - (if (or ands (eq (car cl--loop-args) 'and)) - (progn - (push `(,var - (if ,(or cl--loop-first-flag - (setq cl--loop-first-flag - (make-symbol "--cl-var--"))) - ,start ,var)) - loop-for-sets) - (push (list var then) loop-for-steps)) - (push (list var - (if (eq start then) start - `(if ,(or cl--loop-first-flag - (setq cl--loop-first-flag - (make-symbol "--cl-var--"))) - ,start ,then))) - loop-for-sets)))) + (push (list var + (if (eq start then) start + `(if ,(or cl--loop-first-flag + (setq cl--loop-first-flag + (make-symbol "--cl-var--"))) + ,start ,then))) + loop-for-sets))) ((memq word '(across across-ref)) (let ((temp-vec (make-symbol "--cl-vec--")) -- 2.11.0 --=-=-=--