Right now range is not extremely useful—it can yield an iterator from a to b (exclusive), and that’s it. Quite often more complex ranges are needed—ones that have no upper limit, ranges that need to be inclusive of the upper bound, steps other than 1, and so on. Macros are great for this! It’s quite simple to design a nice range macro:
This takes into account basically every type of range/counter I can think of, and it’s also got a very nice syntax (although the .. vs. ... distinction could be confusing, but Ruby uses it too IIRC). If this were added to std::macros, ranges would be a lot nicer to construct.
A strong +1 for me, this is exactly what macros are meant for. I particularly like the increment notation. The choice of ... vs .. seems arbitrary (and in fact a reverse of what it is in Ruby), but I think it will not be a problem in practice. My only (minor) worry is that ... is not a token, so range!(a.. . b) will be an accepted syntax, but it’s not the first time this would happen in Rust (range/*hi there*/!(a..b) is also accepted).
I don’t think the parser can handle that. A quick modification seems to suggest that macros aren’t powerful enough, and in any case I think it’s ambiguous (or at least would require infinite lookahead) with UFCS (where <T>::f() is a valid expression).
FWIW, reordering the rules so ..< is before ..expr is enough to make that work. Of course, this doesn’t address ambiguity or ugliness. And I guess it would be pretty annoying to type, especially if you’re like me and use thumbs exclusively for both . and <…
As a non-Rubyist, though, I think I’d be fairly likely to mistake whether something is inclusive or exclusive while skimming. I guess I can always stick with range(0, x).
The match syntax would already conflict with the proposed slicing syntax sugar. I think it would be simple to fix by simply making the match syntax use ....