Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Actually, it is quite easy to implement 0 based indices or any other indexing scheme in julia, since all the array indexing code is implemented in julia itself.

https://github.com/JuliaLang/julia/blob/master/j/array.j#L15...

I personally would find multiple indexing schemes confusing both for usage as well as to develop and maintain. Given that 1 based indexing seems to be a popular choice among many similar languages, we just went ahead with that.



Have you looked at the Haskell Ix class? http://www.haskell.org/onlinereport/ix.html

It generalizes the choice of 0 or 1 to an arbitrary starting index. So when you create an array you specify not just where it ends but also where it begins. This lets you do neat things (consider a filter kernel with range [-s,+s]^n instead of [1,2s]^n) and the extra complexity it adds can be hidden when not needed using for-statements or higher order functions.

Nobody uses it because the implementation is not very efficient and Haskellers have a chip on their shoulder about performance. It subtracts the origin and computes strides on every index, but you could easily avoid this by storing the subtracted base pointer and strides with the array. Of course when you go to implement it you'll see light on 0-based indexing :)


The problem with changing it in the library is that you'd also have to change it everywhere arrays are used in Julia itself.

The only way I could think to manage it would be a pragma which switches 0-based on for a given file. But this is doubtlessly not trivial.

Or there is the less elegant option of introducing a new operator for 0-based arrays. But this is liable to cause confusion I think.




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

Search: