Here’s an idea for the syntax, straight from base math textbook:
0 <= .. <= 5 // inclusive, [0,1,2,3,4,5], same as ...
0 <= .. < 5 // left inclusive, [0,1,2,3,4], same as ..
0 < .. <= 5 // right inclusive, [1,2,3,4,5]
0 < .. < 5 // exclusive, [0,1,2,3,4,5]
1 < .. < 1 // []
1 <= .. < 1 // []
1 <= .. <= 1 // [1]
2 <= .. <= 1 // []
a..b
a...b
becomes sugar for
a<= .. < b
a<= .. <= b
Good thing, it can be used the other way round for range constructors where the bounds are reversed (a >= b).
for i in 5 >= .. >= 0 // [5,4,3,2,1,0]
for i in 5 > .. >= 0 // [4,3,2,1,0]
for i in 5 >= .. > 0 // [5,4,3,2,1]
for i in 5 > .. > 0 // [4,3,2,1]
- Reuses existing operators
- Always read as “math”, easy to figure out for outsiders
- Rust explicitness: both operators are mandatory, except when used in the “sugared” backwards compatible version
- Spacing/separation TBD (but not ambiguous)
- Looks like an extension of the existing syntax
- No problems with open/close bracket rules