It's not clear why this needs to / should be done on tuples. Denoting one part of a range with a single tuple element and two other parts lumped together (with yet another tuple element) seems very confusing.
It also worries me how the range is being abused. The lower bound of the range now stands for a non-bounding value. That doesn't make much sense at all.
Is there a reason why (0..=10).step_by(2) isn't good enough? Is there a reason why you couldn't write your own struct with separate range and step size members, then implement Iterator for it?
Well, (1,2..n)is shorter, and if we use (0..=10).step_by(2), it's harder to get start and end of this range. And if we use (1,2..n), we can reuse it on slice syntax like numpy. If we further allow rust to do the same thing in numpy(not in std, just in matrix library), a more official syntax may be better.
And if we want to reverse range with step, it may write like for i in (0..100).rev().step(2):. But in my opinion for i in (100, 98..=0) is shorter and clearer.
And a, b ... n mathes math syntax for such sequence(range). Even though this syntax may overuse ranges, it is still understandable for people who are familiar with math. For better understanding, we may think the whole tuple as a range with step syntax, even though in implementation it is just a tuple.
For what it's worth, as a long-time Rust user, my first thought when looking at the syntax was "Huh? So we've got the range 2..10, but then there's a 0 modifying it somehow?" and it took me a whole minute to look through the examples and realize what was intended. So that's a point against the idea of this being "clearer". To be fair, someone who was newer to Rust might not have that reaction. But I'm also concerned that it would teach an imprecise understanding of syntax: in math notation, b ... n isn't a value with a type, so in programming languages, we have different priorities for clarity.
With this "step by example“ syntax, I've always wondered, if I can provide more than just 2 first elements of the sequence and how will that behave. Should that be a polynomial of the right order? What if I write?:
Honestly, I think this is probably "too cute". I'd rather someone just call a function. (For example, as discussed back in 2015, it'd be nice to have linspace to iterate a floating-point range.)
Maybe it is not a great idea, but in my profession, visual slam, there are a lot needs to manipulate images, matrices, point clouds, and sometimes neural networks. Although c++ has enough performance, it may occurs segment faults and other safety issues. Python does great job with matrix and neural networks. However, the loop performance is poor when dealing with point clouds.
In my opinion, the rust has a great chance to solve these problems all together. However, there is a realistic problem blocking me that the array/matrix librarys are not good enough. They are not clear and easy to use, comparing to the numpy and the eigen.
The closest library maybe the ndarray. However, it has to use a method and a macro to express slice with step. The slicing syntax also uses a non-official syntax (0..n;step), although it is in the macro. And it can not use indexing syntax like the numpy, or use function call like the eigen. It just seems like rust team does not want such matrix library to work like a first-class citizen.
Although this may be not a good idea, the slice syntax with step is a real need.
To add onto this the syntax in ndarray winds up looking like
my_array.slice(s![x..y;step, ..-1])
(negatives go from the end). It's quite convenient! It could be more convenient. I'm very sympathetic to this feature idea, generally; I don't think it has any place in the standard library.
What I would like to see in this space are minimal changes to rust that could make libraries like ndarray more convenient. Extra operators, maybe, or the really low hanging fruit of postfix macros, changing this example to
my_array.s![x..y;step, ..-1]
@xjkdev Along this vein, it might be worthwhile trying to get an iterable version of the s! macro into itertools. I could imagine myself using for (a, b) in s![..n; 3, ..m; 17] quite a lot.