digitalmars.dip.ideas - Add inclusive range operator
- Brother Bill (7/7) Jul 25 We have range 10..15 which has elements: 10, 11, 12, 13, 14 but
- jmh530 (2/4) Jul 25 What languages?
- Lance Bachmeier (2/6) Jul 25 The operator being proposed is taken from Rust.
- monkyyy (3/11) Jul 25 I suggested a `x..y+1` special case before this section even
- Lance Bachmeier (21/29) Jul 25 Given the poor design of the language for this type of thing, I
- Steven Schveighoffer (17/37) Jul 25 ```d
- Atila Neves (3/11) Jul 31 It's not a bad idea, it's just that it's a nice-to-have that I
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.
Jul 25
On Friday, 25 July 2025 at 18:41:12 UTC, Brother Bill wrote:These operators are in other languages.What languages?
Jul 25
On Friday, 25 July 2025 at 18:46:04 UTC, jmh530 wrote:On Friday, 25 July 2025 at 18:41:12 UTC, Brother Bill wrote:The operator being proposed is taken from Rust.These operators are in other languages.What languages?
Jul 25
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.I suggested a `x..y+1` special case before this section even existed; was told to use the enum members trait or iota!"[]"
Jul 25
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[]); } ```
Jul 25
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
Jul 25
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.It's not a bad idea, it's just that it's a nice-to-have that I particularly don't find that important.
Jul 31









Lance Bachmeier <no spam.net> 