1 based (array) indexing

There’s no requirement to support arbitrary indexing in generic code. There is a reason Base.require_one_based_indexing exists. However, banning it altogether seems excessive, since domain-specific use cases exist.

4 Likes

I’m not exactly sure what that reason is, but I see, at least, that natural numbers can start with 0 or with 1. So it doesn’t solve that dispute.

I’m pretty sure, though, that we don’t call the other numbers ‘unnatural’.

2 Likes

Wait until they learn that you can define full-on functions called with []:wink:

julia> f = let
           struct Fun end
           Base.getindex(::Fun, θ) = exp(2π*im*θ)
           Fun()
       end
Fun()

julia> [f[x] for x = 0:0.1:0.5]
6-element Vector{ComplexF64}:
                  1.0 + 0.0im
   0.8090169943749475 + 0.5877852522924731im
  0.30901699437494745 + 0.9510565162951535im
 -0.30901699437494734 + 0.9510565162951536im
  -0.8090169943749473 + 0.5877852522924732im
                 -1.0 + 1.2246467991473532e-16im
5 Likes

They cannot be banned :slight_smile: One can always write specialised functions for domain specific applications.
My opinion is more like “idiomatic” Julia = 1-based indexing.

1 Like

Linguistic games that programmers play!

1 Like