4 ms·
There must be some interesting reason why ".." and not the more common "..." - I wonder what?
by cannam 10y ago
There must be some interesting reason why ".." and not the more common "..." - I wonder what?
- the_duke 10y agoThey probably 'copied' Haskell here, which also uses "..".
- pdexter 10y agoHaskell doesn't have this feature though. I mean it does, but you can just leave out the ones you don't want matched, you don't have to put in any dots.
- echelon 10y agoIt's less to type. The double period is already used for lots of other things in the language, so it feels like the correct choice.
- swsieber 10y agoReading through, they treat a range (like 1 .. 10 ) as pattern matching 1 2 3 4 5 6 7 8 9 10, with .. representing 2 3 4 5 6 7 8 9. In that light, it actually makes sense.
- cannam 10y agoAh of course, that is quite widely used (e.g. Perl). If you already have that, I can see why you'd reuse the same token. (edit: ok, I see from other replies that it's not that simple)
- anuragsoni 10y agoMinor correction, to match a range the syntax would be 1 ... 10
- tatterdemalion 10y agoNo particular reason. `..` and `...` both exist in the language, `..` is exclusive range and `...` is inclusive range. `..` is only in expressions right now, whereas `...` is only in patterns. Eventually, both will be available everywhere, possibly. At very least, `..` in patterns is getting added soon. Since this is a pattern thing, probably `..` was chosen when `...` was the only range available in patterns, to distinguish this from that range pattern more. However, `..` will now be available in patterns, so its just historical. (This is a longstanding feature, what's changed is just making it apply to more patterns.)
- anuragsoni 10y agoI've seen the "..." used for matching a range of values, whereas ".." is used in other places where we disregard a value while patter matching. I'm sure someone from the rust team can give a better answer, but to me this change looks like it was just bringing the pattern matching for structs to be consistent with other uses of ".." Relevant RFC: https://github.com/rust-lang/rfcs/blob/master/text/1492-dotdot-in-patterns.md https://github.com/rust-lang/rfcs/blob/master/text/1492-dotd...