First class lazy Interval
Don
nospam at nospam.com
Fri Feb 27 05:52:39 PST 2009
bearophile wrote:
> D2 supports the interval syntax in the foreach:
> foreach (i; 1..1000) {...}
>
> Such intervals are useful in a very large number of situations. So, with the new Range support, it may be useful to allow the interval syntax to be used in other contexts as well.
> So x..y may become a first-class lazy interval from x to y-1, that can be passed to functions too, etc, and not just used into foreach (the compiler can recognize it, and often optimize it away in many situations, replacing it with a normal for() loop).
How do you specify a uint range that includes uint.max?
(This is a general problem with "[)" ranges).
> Optional possibilities:
>
> 1) x..y..s
> where s is a step/stride, so you can define odd numbers, etc.
> 1..10..3 ==> 1 4 7
> 10..1..-2 ==> 10 8 6 4 2
> 1..5..1 ==> 1 2 3 4
> I don't like this syntax much, but I think it's acceptable.
This is a perfect example of what Andrei recently posted: proposal of a
language change for a pathetically limited special case. Your stride is
not powerful enough to be worthwhile.
More information about the Digitalmars-d
mailing list