I think using < for exclusive and = for inclusive is a lot more intuitive.
inclusive-inclusive: sliceable[start=..=end],
inclusive-exclusive: sliceable[start=..<end],
exclusive-inclusive: sliceable[start<..=end],
exclusive-exclusive: sliceable[start<..<end].
That being said, for slicing, inclusive-exclusive is vastly more useful than most, and I find it quite intuitive. I don’t even remember encountering a case were I needed an exclusive start.
Out of the 4 possibilities, I’d argue it’s the most intuitive to work with.
e.g. it has the property that end - start gives you the length, which is something that people mess up in real life when using other systems (e.g. to calculate the number of days given inclusive start and end dates, many people resort to counting them on their calendar)
The only other system that has this property is left exclusive right inclusive, but that really makes no sense, since it would require -1 to slice things at 0.
It would add a new symbol to memorize though, and it’s also easy to miss when reading, and easy to forget when writing.
There is already a standard notation for inclusive/exclusive ranges. The downside is that conventional coding editors assume balanced brackets and the standard notation mixes them. We just need better editors.
The current state is to just do something like that;
const my_slice: []u8 = foo();
for (my_slice) |element| {
// use element
}
Why would [..] be needed?
In general I’m unsure about what and if anything you’re trying to achieve with this. The [inclusive..exclusive) range syntax and specification is common and widely used and understood in nearly all programming languages for reasons already explained above. The only major exception I can think about off the top of my head is Julia, which has inclusive bounds for both lower and upper.
for-loop ranges can be inconvenient.
I just had one again.
Imagine two u6 vars a and b with which you want to compute something inclusive.
In the loops there is a useless overflow danger, while we do not need the + 1 value.
fn calc(a: u6, b: u6) void {
if (a > b) {
for (b..a + 1) |v| {
}
}
else if (a < b) {
for (a..b + 1) |v| {
}
}
}