We’ve currently adopted ..
as syntax for exclusive ranges and ...
as the syntax for inclusive ranges. In the current implementation, ..
is only legal in expressions and ...
is only legal in patterns, but that’s expected to change. However, there are some very valid concerns about using the number of dots to distinguish these two cases:
- Hard to remember.
- We do the opposite of Ruby (because “more dots more numbers” seems strictly better, but still).
- Easy to make a typo.
- Easy to overlook when proof-reading code.
It is my opinion that inclusive rangers are a relatively rare thing. They are used primarily for match patterns (e.g., match ch {
f’ … ‘x’ => … }and possibly some edge cases involving integer rangers (e.g.,
0…uint::max`). But in general they might make code cleaner on occasion so it seems like a fine thing to have.
Swift adopted ..<
as the notation for an exclusive range. I don’t like this because I see exclusive rangers as the common case and that syntax is somewhat awkward. However, I find ..=
for inclusive ranges to be reasonable – inclusive rangers are uncommon so the fact that it’s a bit strange doesn’t bug me so much. And it is quite clear (or at least obviously distinct from ..
).
Normally I’m pretty opposed to arbitrary syntactic changes at this point, but given the fact that this syntax is relatively young and seems to have some relatively serious downsides beyond aesthetic preference, I’m inclined to consider a change. I’d like to get a feeling for what other people think, though.
(If I can ask a favor, please restrict your comments to the specific question at hand. I would prefer not to have this thread derailed with a generic discussion of whether ..
or ...
is preferable in other cases (e.g. patterns), nor the question of whether ..
in patterns ought to destructure a range vs matching a range. Those seem like independent things to consider.)