www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Regarding iota

reply bearophile <bearophileHUGS lycos.com> writes:
David Simcha has kindly done work on this iota() bug:
http://d.puremagic.com/issues/show_bug.cgi?id=4603

Now iota(1, 0) produces a run-time error, this is better than before, but
coming from Python I see the usage of iota just as a loop:

So I expect this:
foreach (i; iota(1, 0)) {...}
to act as:
foreach (i; 1 .. 0) {...}
Or as:
for (int i = 1; i < 0; i++) {...}

In all three situations I expect the loop contents to just not being executed,
instead of receiving an error in just the first case.
This is also what Python range/xrange do in this case:
for in in xrange(1, 0): ...
and so far I've seen the iota() as similar to the xrange().

If foreach_reverse is scheduled for deprecation, and you have to use a:
foreach (i; retro(iota(a, b))) {}
Then I'd like it to act as foreach_reverse when the loop range intervals are
"wrong".

What do you think?

Bye,
bearophile
Aug 19 2010
parent bearophile <bearophileHUGS lycos.com> writes:
 http://d.puremagic.com/issues/show_bug.cgi?id=4603
In the meantime I have reopened it, so this discussion and problem doesn't get lost in the chaos. Bye, bearophile
Aug 20 2010