Closed interval maybe a mistake?
Opened this issue · 5 comments
In my current experience, the expression 0..5
means that [0,1,2,3,4,5]
doesn't seem to work as well as [0,1,2,3,4]
, so the half-closed interval
I'm afraid it would be a huge breaking change.
What about the math version: [0..5]
for [0,1,2,3,4,5]
and [0..5[
for [0,1,2,3,4]
(if the syntax is possible)
The other option would be to use the Python equivalent [0:5]
Indeed, and I find some interesting uses of range:
> [1, 2, 3, 4][0 .. -1]
[1, 2, 3, 4]
> [1, 2, 3, 4][0 .. 0] # not an empty range
[1]
> [1, 2, 3, 4][0 .. -4]
[1]
> [1, 2, 3, 4][0 .. -5]
[]
You could also use Ruby syntax by adding another dot, but i can see how that would be confusing.
> [0..5]
[0,1,2,3,4,5]
> [0...5]
[0,1,2,3,4]
Another idea is having ..=
and ..<
to be more explicit, but it may look too ugly/verbose
> [0..=5]
[0,1,2,3,4,5]
> [0..<5]
[0,1,2,3,4]
The other option would be to use the Python equivalent
[0:5]
I agree with this.
Revisiting some old issues. Are you still in favor of this syntax for excluded last value?