how about
for 5 < i <= 10
for 5<= i < 10
or the other way around
for 10 > i >= 0
for 10 >= i > 0
and so on?
how about
for 5 < i <= 10
for 5<= i < 10
or the other way around
for 10 > i >= 0
for 10 >= i > 0
and so on?
I like this but it’s ambiguous outside a for loop. How would you declare a range?
let range = 5 < i <= 10; // what is i for?
for item in range { ... }
for item in (10 > i > 0) { ... } // what is i?
perhaps
for item in (10 > _ > 0) { ... }
would do?
Well I like the idea for ranges
let range2 = 10 > .. >= 6
so
let range1 = 5 <= .. < 16
is desugar for
let range1 = 5..16
but I still think that this separation in for is nice
for 10 > idx > 0 { ... }
is clear as water, even
for idx in 10 > .. > 0 { ...}
than instead (which doesnt work right now)
for idx in 9..-1 {
}
you need to write some like
let r1 = 1..10;
for idx in r1.rev() {
println!("{:?}", idx);
}
It'd work in C++ (overload operator <=(FullRange, T) to return RangeToInclusive<T>), but PartialOrd says <= can only return bool, via partial_cmp returning Option<Ordering>, so I assume it can't work in Rust. (And PartialOrd requires PartialEq, so it'd also allow silliness like 4 == .. == 2.) I assume it'd be completely doable as a macro, though. Then you could even make range!(0 <= r) turn RangeTo(5) into Range(0, 5).
Let me also plug the comment I posted on the other thread about ranges. TL/DR: From an algorithmic perspective, I think all std should provide is the Range [a,b) where b is 'reachable' from a by zero-or-more-but-finite applications of a successor function (aka, roughly, a ≤ b). Going beyond that feels like we're making an interval library, which is a totally different thing, and the current range is no better than a pair.
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.