[iterate-devel] for i in-vector downto 0 by 2 yields what?
Hi, I'm adding a few test cases to iterate-test.lisp. I wonder about the interaction of in-vector and by when moving backwards. ITER> (iter (for i index-of-vector #(0 1 2 3 4) downto 0 by 2) (collect i)) (3 1) I'd have expected (4 2 0) here. What do you think? By analogy: ITER> (iter(for x downfrom 4 by 2)(repeat 3)(collect x)) (4 2 0) ITER> (loop for x downfrom 4 by 2 repeat 3 collect x) (4 2 0) ITER> (iter (for i index-of-vector #(0 1 2 3 4) downto 0 by 1) (collect i)) (4 3 2 1 0) That is fine with me. I'd expect behaviour like (iter (for x rom (1- (length array)) downto 0 [by N]) (collect x)) (4 2 0) ; when by 2 Rationale: the first index/element it the rightmost, then walk by N. The current behaviour looks to me like an unintended side effect of the implementation, moving down from (length array)=5 by 2 to yield 3,1. Regards, Jörg Höhle.
Today, Joerg-Cyril Hoehle <Joerg-Cyril.Hoehle@t-systems.com> wrote:
I'm adding a few test cases to iterate-test.lisp. I wonder about the interaction of in-vector and by when moving backwards.
ITER> (iter (for i index-of-vector #(0 1 2 3 4) downto 0 by 2) (collect i)) (3 1)
I'd have expected (4 2 0) here. What do you think?
Sounds sensible. The analogy to (for x downfrom ...) sounds sensible. There is another interpretation, though: (index-of-vector ... downto x) should go through the vector in the same way that the downto-less form would, in reverse order. So these forms could also return: (iter (for i index-of-vector #(0 1 2 3 4) downto 0 by 2) (collect i)) ; (4 2 0) (iter (for i index-of-vector #(0 1 2 3 4) downto 0 by 3) (collect i)) ; (3 0) I'm undecided as to which is preferable. Your interpretation has the advantage that it's more in line with the behavior of the counting FOR driver, so I'm tending towards that.
Rationale: the first index/element it the rightmost, then walk by N.
The current behaviour looks to me like an unintended side effect of the implementation, moving down from (length array)=5 by 2 to yield 3,1.
Yeah, I can't imagine an interpretation where the current result makes much sense, either. (-: Cheers, -- Andreas Fuchs, <asf@boinkor.net>, asf@jabber.at, antifuchs
Andreas Fuchs wrote:
(iter (for i index-of-vector #(0 1 2 3 4) downto 0 by 2) (collect i)) ; (4 2 0)
(iter (for i index-of-vector #(0 1 2 3 4) downto 0 by 3) (collect i)) ; (3 0)
I'm undecided as to which is preferable. Your interpretation has the advantage that it's more in line with the behavior of the counting FOR driver, so I'm tending towards that.
FWIW, I totally agree with Joerg's interpretation. (iter (for i from 4 downto 0 by 3) (collect i)) returns (4 1), so I would expect that (iter (for i index-of-vector #(0 1 2 3 4) downto 0 by 3) also returns (4 1), NOT (3 0). Regards, Arthur Lemmens
participants (3)
-
Andreas Fuchs
-
Arthur Lemmens
-
Hoehle, Joerg-Cyril