The problem that bothers me in x..y notation is that symmetric operator .. is used to express asymmetric range. The “use three instead of two dots to include last element” seems totally arbitrary. This is really confusing (that’s the reason this topic appeared), especially when there exist languages (such as Haskell) in which x..y includes y.
My proposition is to change .. token into ..,, so that you would write:
for x in 0..,n {}
if you want to exclude last element. The idea is for it to resemble ... operator, with a comma superimposed, so you can think of it as "range of values starting at 0, and then there’s n".
Why I prefer .., to other solutions proposed in this topic (@theme)?
-
..= for inclusive range: assymetric operator used for symmetric usecase; and I believe it would create ambiguity in grammar (could be parsed as x.. = y;
-
upto or ..upto for exclusive range: creates new keyword; for me as non-native english speaker it’s not obvious whether it excludes last element; and it’s just longer;
-
..< for exclusive range (Swift’s syntax): it’s actually a good idea, but it somehow looks weird to me.
Before I started writing this post I liked .., because it is visually a superset of ... (which, what I’ve found, is not the case in monospace font on this forum, but here it works: “…,”). Actually, I wanted to propose ., and revert .. to it’s old semantics, but I realised that (0.,n) would be ambigous.
(note that changes I’m talking about are completely ortogonal to unification of expression and pattern syntax for ranges)
No matter what syntax we will end up with, I would be really sad if current (.. and ...) syntax will stay for 1.0 and I just want assymetric range to be represented by an assymetric operator.