[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#6583: 23.2; cl loop macro with `and' clause
From: |
npostavs |
Subject: |
bug#6583: 23.2; cl loop macro with `and' clause |
Date: |
Sat, 24 Jun 2017 20:22:09 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux) |
Alex <agrambot@gmail.com> writes:
>
> 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).
I can't claim to fully understand the loop macro implementation, but
your patch breaks this example from the manual `(cl) For Clauses':
(cl-loop for x below 5 for y = nil then x collect (list x y))
=> ((0 nil) (1 1) (2 2) (3 3) (4 4))
(cl-loop for x below 5 and y = nil then x collect (list x y))
=> ((0 nil) (1 0) (2 1) (3 2) (4 3))
With your patch the second loop gives ((0 nil) (1 1) (2 2) (3 3) (4 4))
like the first.