Hacker News new | past | comments | ask | show | jobs | submit login

Julia ranges are not composable, that's it

You cannot do easily [0...N) = [0...N/2) + [N/2...N)




Idk typing +1 seems easy enough... 1:N == union(1:(N÷2), (N÷2+1):N).

But really, these discussions are funny to me - each side pretending their convention is how God intended indexing to be done. You see it's naturally composable because N/2 shows up twice, which is really the perfect amount of times to show up, and as you recall I just defined composable in that way (not to mention it matches the fact that N/2 occurs twice in [0, N)!)


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


> 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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: