4 ms·
This is the exact opposite to ruby, which uses `0..n` as inclusive, and `0...n` as exclusive http://stackoverflow.com/questions/9690801/difference-between-doub
by borland 9y ago
This is the exact opposite to ruby, which uses `0..n` as inclusive, and `0...n` as exclusive
http://stackoverflow.com/questions/9690801/difference-between-double-dot-and-triple-dot-in-range-generation http://stackoverflow.com/questions/9690801/difference-betwee...
I always remembered it as "the third dot makes it bigger so it pushes the range and the last item falls off". I can't remember where that came from, perhaps related to the poignant guide:
http://poignant.guide/book/chapter-3.html#section2 http://poignant.guide/book/chapter-3.html#section2
I actually find in practice the swift ranges are the only ones I can reliably use without having to stop and look up the reference syntax every time.
For some reason, for me, `0..<n` reads as "0 through less than n" which signals to my brain a clear signal of an exclusive range.
Then I can work from there and if it doesn't have the < symbol it must be exclusive.
I suspect `0..=n` would work similarly well, but I've not seen a real language to ever do that yet
- deleted 9y ago[deleted]
- yorwba 9y ago> I suspect `0..=n` would work similarly well, but I've not seen a real language to ever do that yet This could be extended to cover `0=..=n`, `0<..=n`, `0<..<n` and `0<..=n`. You can actually define that syntax in Haskell: Prelude> let a =..= b = [a..b] Prelude> let a <..= b = [(a+1)..b] Prelude> let a <..< b = [(a+1)..(b-1)] Prelude> let a =..< b = [a..(b-1)] Prelude> (1 =..= 4, 1 <..= 4, 1 <..< 4, 1 =..< 4) ([1,2,3,4],[2,3,4],[2,3],[1,2,3])