# Array indexing with begin

**URL:** <https://discourse.julialang.org/t/array-indexing-with-begin/51495>\
**Category:** General Usage\
**Created:** [December 9, 2020, 4:44am UTC](https://discourse.julialang.org/t/array-indexing-with-begin/51495 "2020-12-09T04:44:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OlivierHnt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olivierhnt/32/6227_2.png) [@OlivierHnt](https://discourse.julialang.org/u/OlivierHnt)\
**Post date:** [December 9, 2020, 4:44am UTC](https://discourse.julialang.org/t/array-indexing-with-begin/51495/1 "2020-12-09T04:44:09Z")

</div>

I ran into the following (Julia v1.5.3):

```julia
julia> A = rand(2,2);

julia> Meta.@lower A[end,1]
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope'
1 ─ %1 = Base.lastindex(A, 1)
│ %2 = Base.getindex(A, %1, 1)
└── return %2
))))

julia> Meta.@lower A[begin,1]
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope'
1 ─ %1 = Base.axes(A, 1)
│ %2 = Base.first(%1)
│ %3 = Base.getindex(A, %2, 1)
└── return %3
))))

```

It seems that when using two indices for a matrix `begin` and `end` lowers to different implementations. Is there any reason for this? (I would have expected `A[begin,1]` to call `Base.firstindex(A, i)` the same way `end` calls `Base.lastindex(A, i)`.

Note that if we simply use `A[begin]` then it calls `Base.firstindex(A)` (and similarly `A[end]` calls `Base.lastindex(A)`).

---

<div class="post-metadata">

**Author:** ![Keno](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/keno/32/285_2.png) [@Keno](https://discourse.julialang.org/u/Keno)\
**Post date:** [December 9, 2020, 4:47am UTC](https://discourse.julialang.org/t/array-indexing-with-begin/51495/2 "2020-12-09T04:47:14Z")

</div>

This was changed in [https://github.com/JuliaLang/julia/pull/35779](https://github.com/JuliaLang/julia/pull/35779), which will be in 1.6.

---

<div class="post-metadata">

**Author:** ![OlivierHnt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/olivierhnt/32/6227_2.png) [@OlivierHnt](https://discourse.julialang.org/u/OlivierHnt)\
**Post date:** [December 9, 2020, 4:52am UTC](https://discourse.julialang.org/t/array-indexing-with-begin/51495/3 "2020-12-09T04:52:18Z")

</div>

Ah I actually tried to search for an Issue before asking but my GitHub search skills are not so good 🙂
