Hacker News new | ask | show | jobs
by Iwan-Zotow 1136 days ago
In python this is natural way to do ranges, and in Julia you have to remember this pesky +1

In Python (C, C++ with whole STL) you could split in the middle, or at any M

[0...N)=[0...M)+[M...N)

You could split it k times at any boundaries, still

[0...N)=[0...M1)+...+[Mk...N)

Another important thing is that number of elements to process is exactly the difference between last and first index of the range

https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF

1 comments

> number of elements to process is exactly the difference between last and first index of the range

And in Julia, it’s

  length(a:b)
which also works with non-unit step sizes like

  length(a:x:b)
The intent of these expressions seems clearer than the intent of `b-a` and `ceiling((b-a)/x)` with your proposed approach in a zero-indexed language.