I've just seen the new `..<` operator. Will oth...
# language-proposals
a
I've just seen the new
..<
operator. Will other mathematical range operators considered in the future ? Like open started (
<..
?) Ranges, or fully open ranges (
<..<
?) ? I think both are not very common, but maybe it would make sense to be exhaustive in this matter ? Maybe some mathematical libraries would have use for it ?
P.S : I understand it would not be possible to use them for progression/iteration, only for comparison/contain tests, and that make them also less useful.
One example is version specification of library dependency. Or you could require a version strictly superior to a specific version with security breach or bug, and also inferior to the next major version.
s
wouldn’t open-started be
>..
instead of
<..
?
a
I don't think so, as the start value is strictly lower than values included in the interval (..)
đź‘Ť 1
e
https://docs.raku.org/type/Range Raku's ranges can be iterated over, even with open ends, as long as the type is incrementable
a
Yes, you're right. The difficulty with open started ranges is to define the first value of iteration. For types with a "natural" step (Ex: 1 for integers), an open started range can be iterable.
e
for types without a natural step, iteration doesn't make much sense whether it's open or closed
e.g.
Copy code
if (i in 1..3) // ok
for (i in 1..3) // ok
if (s in "a".."z") // ok
for (s in "a".."z") // not ok
..<
makes no difference, and neither should a hypothetical
<..
or
<..<
a
With open-ended ranges, specifying a step can make a non-incrementable type iterable, Ex :
1.0..<2.0 step 0.1
. However, for open started ranges, this is a different matter, because the step represent the amount between two included values, not an initial offset. So, open-started ranges add even more subtlety.
e
Raku's answer to that is pretty natural IMO: same the closed range, just skipping the open end (e.g. your example would be like
(1.0..2.0 step 0.1) - 1.0
)