[iterate-devel] for i in-vector downto 0 by 2 yields what?

Andreas Fuchs asf at boinkor.net
Fri Nov 12 15:20:27 UTC 2004


Today, Joerg-Cyril Hoehle <Joerg-Cyril.Hoehle at 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 at boinkor.net>, asf at jabber.at, antifuchs




More information about the iterate-devel mailing list