Add inclusive range operator

Steven Schveighoffer schveiguy at gmail.com
Sat Jul 26 01:04:12 UTC 2025


On Friday, 25 July 2025 at 19:42:53 UTC, Lance Bachmeier wrote:
> 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[]);
> }
> ```

```d
auto a = iota(1L, 5L).array;
```

But yeah, I would like to see `x .. y` become an expression that 
reduces to a specialized type, and then we could have things like 
`array(1L .. 5L)`

As for the OP's idea, I'm not fully against it. But what it 
replaces is quite sensible also. I'm not sure it's worth the 
extra feature:

```d
x ..= y
x .. y+1
```

In general, I have not found the lack of this syntax to be an 
impediment.

-Steve


More information about the dip.ideas mailing list