Hacker News new | ask | show | jobs
by mkborregaard 3167 days ago
Julia supports indexing with arbitrary bases, and it generally works ecosystem-wide.
1 comments

Oh, it does? I've taken to saying that "zero-based indexing – that's how Julia broke my heart", because at the time, I didn't get the impression that there was anything else in sight. How do I index based on zero?
If you have a particular algorithm that is better expressed using 0-based indexing use https://github.com/JuliaArrays/OffsetArrays.jl
It's not just something particular I need it for; it's everything.
If you read the OP again carefully, you'll see that you can use offset arrays for every array you make and suffer no performance penalty, because the offset is compiled away. And the development overhead is a single library import call; I replace core language data-structures all the time in any language for features I want, this is no different.
See my other comment in the thread for the thing I've always wondered: How can you compile away an arbitrary calculation that might need to be made at run time?

(assuming we're not just arguing over arbitrary-array indexing to input predefined constants at the REPL/code level).

Could it be that the offset calculation to find the start of the array is needed in any case?
Yeeesh, that sounds like a maintenance nightmare...
Why? You don't have to write a package any differently to make it work with arbitrary indices.