Mendess
03/02/2022, 10:42 PMuntil
but the toString implementation prints as inclusive of both ends)Casey Brooks
03/02/2022, 10:53 PMList<T>.indices
for example).
So when you're working with list-type ranges of indices, the Range itself is just an implementation detail, or else you're just doing iteration over a list and can use a normal for
loop or List operators. But when you want to use ranges with ..
, you're more likely to be working with them in the mathematical or physical sense, not in relation to a List, so it's optimizing for that particular use-caseephemient
03/02/2022, 10:56 PMInt.MIN_VALUE .. Int.MAX_VALUE
while a closed interval representation isMendess
03/02/2022, 11:00 PMPaul Woitaschek
03/02/2022, 11:01 PM3 in 0..3
was false and 0 in 0..3
was true.Mendess
03/02/2022, 11:04 PMfor(..; i < N;..)
where i is never N. And slicing where I want to use that same logic so I can do s.slice(x..s.length)
and index math works better in general when using this schemeephemient
03/02/2022, 11:06 PMs.drop(x)
for exampleCasey Brooks
03/02/2022, 11:07 PM.lastIndex
instead of .length
ephemient
03/02/2022, 11:15 PMrepeat(N) { ... }
, etc.janvladimirmostert
03/03/2022, 8:44 PMephemient
03/03/2022, 9:28 PMa..z
is half-open, a..=z
is closed
in Swift, a..z
is closed, a..<z
is half-open
in Perl, a..z
and a...z
are closed
in Raku, a..z
is closed, a..^z
and a^..z
are half-open, a^..^z
is open
in Ruby, a..z
is closed, a...z
is half-open
in PHP, range(a, z)
is closed
in Python, range(a, z)
is half-open
in C++20, std::ranges::views::iota(a, z)
is half-open
so there's really not much agreement on thisephemient
03/03/2022, 9:32 PM..
is used to mean an inclusive rangejanvladimirmostert
03/04/2022, 8:40 AM1 <= until < 5
and 1 <= .. <= 5
, really makes life easier
Would be nice if the range operator could be expanded to make those actual operators (I think I did see such a proposal somewhere)
1 .. 5
1 <..< 5
1 <=..<=5 (default, same as 1 .. 5)
1 <=..< 5
1 <..<= 5
and then when you loop over it, for (i in 1..5)
that IntelliJ displays for (1 >= i <= 5) { ...}
maybe that itself is a nice-to-have syntax for a range iterator, 1 > i < 5
or 1 < i > 2
(1 > i <= 5).forEach { ... }
(1 > i <= 5 interval 2).forEach { ... }
Derek Peirce
03/05/2022, 2:31 AM1 until 5
is half-open.