# 1 based (array) indexing

**URL:** <https://discourse.julialang.org/t/1-based-array-indexing/90472>\
**Category:** New to Julia\
**Tags:** indexing, arrays\
**Created:** [November 18, 2022, 8:36pm UTC](https://discourse.julialang.org/t/1-based-array-indexing/90472 "2022-11-18T20:36:20Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [November 25, 2022, 6:48am UTC](https://discourse.julialang.org/t/1-based-array-indexing/90472/21 "2022-11-25T06:48:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [November 25, 2022, 7:52am UTC](https://discourse.julialang.org/t/1-based-array-indexing/90472/22 "2022-11-25T07:52:19Z")

</div>

> [@tchebycheff](#):
>
> There is a reason natural numbers are called natural.
> 
> Unnatural counting schemes are domain specific

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

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [November 28, 2022, 2:28am UTC](https://discourse.julialang.org/t/1-based-array-indexing/90472/23 "2022-11-28T02:28:44Z")

</div>

Wait until they learn that you can define full-on functions called with `[]`… 😉

```julia
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

```

---

<div class="post-metadata">

**Author:** ![tchebycheff](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@tchebycheff](https://discourse.julialang.org/u/tchebycheff)\
**Post date:** [November 28, 2022, 3:03am UTC](https://discourse.julialang.org/t/1-based-array-indexing/90472/24 "2022-11-28T03:03:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tchebycheff](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@tchebycheff](https://discourse.julialang.org/u/tchebycheff)\
**Post date:** [November 28, 2022, 3:18am UTC](https://discourse.julialang.org/t/1-based-array-indexing/90472/25 "2022-11-28T03:18:32Z")

</div>

Linguistic games that programmers play!

[Previous page](https://discourse.julialang.org/t/1-based-array-indexing/90472.md?page=1)
