Add inclusive range operator

Lance Bachmeier no at spam.net
Fri Jul 25 19:42:53 UTC 2025


On Friday, 25 July 2025 at 18:41:12 UTC, Brother Bill wrote:
> We have range 10..15 which has elements: 10, 11, 12, 13, 14 but 
> not 15
>
> Recommend operator ..= as in 10..=15 or operator ... as in 
> 10...15
> This would produce inclusive range of elements: 10, 11, 12, 13, 
> 14, 15
>
> These operators are in other languages.
>
> I am sure that I am not the first to recommend this.

Given the poor design of the language for this type of thing, I 
don't think it would be worth adding new syntax until that's 
cleared up.

```
void main() {
     // Nope
     // long[] a = 1..4;
     // Nope
     // long[] a = [ 1..4 ];
     import std.range: iota;
     // Nope
     // long[] a = iota(1, 5);
     import std.array: array;
     // Nope
     // long[] a = iota(1, 5).array;
     import std.conv: to;
     // Finally!
     long[] a = iota(1, 5).array.to!(long[]);
}
```



More information about the dip.ideas mailing list