First class lazy Interval

Lutger lutger.blijdestijn at gmail.com
Fri Feb 27 04:56:20 PST 2009


bearophile wrote:

> Michel Fortin:
...
>> Perhaps we could make 3 dots mean an inclusive interval (including the 
>> second value in the interval), and 2 dots an exclusive one (excluding 
>> the second value).
> 
> Ruby follows your idea, but for the eye it's easy to miss the extra dot, 
so I don't like this much (but I think an optional stride syntax may be 
useful, especially if such stride can be negative too. You can also perform 
a little optimization if the stride is known at compile time, as it often 
happens).
> 
> Bye,
> bearophile

Except in Ruby the meaning is reversed (.. is inclusive and ... is 
exclusive). 

About the stride, in ruby this is done as (0..10).step(2), which is very 
readable imho. With extension methods if these ever get in D, will the same  
syntax be possible with std.range? 

I do like the stride in std.range (and step in ruby) because it's 
straightforward and readable:

stride( a, 2 )

could become: stride( 0..10, 2 ) or: (0..10).stride(2)






More information about the Digitalmars-d mailing list