<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; using LinearAlgebra

julia&gt; LinearAlgebra.hello()
ERROR: UndefVarError: hello not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base ./Base.jl:26
 [2] top-level scope
   @ REPL[2]:1"><pre class="notranslate">julia<span class="pl-k">&gt;</span> <span class="pl-k">using</span> LinearAlgebra

julia<span class="pl-k">&gt;</span> LinearAlgebra<span class="pl-k">.</span><span class="pl-c1">hello</span>()
ERROR<span class="pl-k">:</span> UndefVarError<span class="pl-k">:</span> hello not defined
Stacktrace<span class="pl-k">:</span>
 [<span class="pl-c1">1</span>] <span class="pl-c1">getproperty</span>(x<span class="pl-k">::</span><span class="pl-c1">Module</span>, f<span class="pl-k">::</span><span class="pl-c1">Symbol</span>)
   @ Base <span class="pl-k">./</span>Base<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">26</span>
 [<span class="pl-c1">2</span>] top<span class="pl-k">-</span>level scope
   @ REPL[<span class="pl-c1">2</span>]<span class="pl-k">:</span><span class="pl-c1">1</span></pre></div>
<p dir="auto">The error could be more helpful with <code class="notranslate">ERROR: UndefVarError: no binding hello defined in module LinearAlgebra</code></p>
<p dir="auto">Following this LoopVectorization issue asking for <code class="notranslate">begin</code>/<code class="notranslate">end</code> support: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="863088807" data-permission-text="Title is private" data-url="https://github.com/JuliaSIMD/LoopVectorization.jl/issues/246" data-hovercard-type="issue" data-hovercard-url="/JuliaSIMD/LoopVectorization.jl/issues/246/hovercard" href="https://github.com/JuliaSIMD/LoopVectorization.jl/issues/246">JuliaSIMD/LoopVectorization.jl#246</a></p>
<p dir="auto">I was curious how Base Julia correctly handled <code class="notranslate">begin</code>/<code class="notranslate">end</code> with <code class="notranslate">CartesianIndex</code>.</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; i = CartesianIndex((1,2))
CartesianIndex(1, 2)

julia&gt; A = rand(6,5,4,3,2);

julia&gt; A[i,begin,end,2]
ERROR: BoundsError: attempt to access 6×5×4×3×2 Array{Float64, 5} at index [1, 2, 1, 4, 2]
Stacktrace:
 [1] getindex
   @ ./array.jl:834 [inlined]
 [2] getindex(::Array{Float64, 5}, ::CartesianIndex{2}, ::Int64, ::Int64, ::Int64)
   @ Base ./multidimensional.jl:638
 [3] top-level scope
   @ REPL[17]:1

julia&gt; A[i,begin,begin,begin]
0.5712471105637651

julia&gt; A[i,begin,begin,end]
ERROR: BoundsError: attempt to access 6×5×4×3×2 Array{Float64, 5} at index [1, 2, 1, 1, 3]
Stacktrace:
 [1] getindex
   @ ./array.jl:834 [inlined]
 [2] getindex(::Array{Float64, 5}, ::CartesianIndex{2}, ::Int64, ::Int64, ::Int64)
   @ Base ./multidimensional.jl:638
 [3] top-level scope
   @ REPL[19]:1"><pre class="notranslate">julia<span class="pl-k">&gt;</span> i <span class="pl-k">=</span> <span class="pl-c1">CartesianIndex</span>((<span class="pl-c1">1</span>,<span class="pl-c1">2</span>))
<span class="pl-c1">CartesianIndex</span>(<span class="pl-c1">1</span>, <span class="pl-c1">2</span>)

julia<span class="pl-k">&gt;</span> A <span class="pl-k">=</span> <span class="pl-c1">rand</span>(<span class="pl-c1">6</span>,<span class="pl-c1">5</span>,<span class="pl-c1">4</span>,<span class="pl-c1">3</span>,<span class="pl-c1">2</span>);

julia<span class="pl-k">&gt;</span> A[i,<span class="pl-c1">begin</span>,<span class="pl-c1">end</span>,<span class="pl-c1">2</span>]
ERROR<span class="pl-k">:</span> BoundsError<span class="pl-k">:</span> attempt to access <span class="pl-c1">6</span><span class="pl-k">×</span><span class="pl-c1">5</span><span class="pl-k">×</span><span class="pl-c1">4</span><span class="pl-k">×</span><span class="pl-c1">3</span><span class="pl-k">×</span><span class="pl-c1">2</span> Array{Float64, <span class="pl-c1">5</span>} at index [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">1</span>, <span class="pl-c1">4</span>, <span class="pl-c1">2</span>]
Stacktrace<span class="pl-k">:</span>
 [<span class="pl-c1">1</span>] getindex
   @ <span class="pl-k">./</span>array<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">834</span> [inlined]
 [<span class="pl-c1">2</span>] <span class="pl-c1">getindex</span>(<span class="pl-k">::</span><span class="pl-c1">Array{Float64, 5}</span>, <span class="pl-k">::</span><span class="pl-c1">CartesianIndex{2}</span>, <span class="pl-k">::</span><span class="pl-c1">Int64</span>, <span class="pl-k">::</span><span class="pl-c1">Int64</span>, <span class="pl-k">::</span><span class="pl-c1">Int64</span>)
   @ Base <span class="pl-k">./</span>multidimensional<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">638</span>
 [<span class="pl-c1">3</span>] top<span class="pl-k">-</span>level scope
   @ REPL[<span class="pl-c1">17</span>]<span class="pl-k">:</span><span class="pl-c1">1</span>

julia<span class="pl-k">&gt;</span> A[i,<span class="pl-c1">begin</span>,<span class="pl-c1">begin</span>,<span class="pl-c1">begin</span>]
<span class="pl-c1">0.5712471105637651</span>

julia<span class="pl-k">&gt;</span> A[i,<span class="pl-c1">begin</span>,<span class="pl-c1">begin</span>,<span class="pl-c1">end</span>]
ERROR<span class="pl-k">:</span> BoundsError<span class="pl-k">:</span> attempt to access <span class="pl-c1">6</span><span class="pl-k">×</span><span class="pl-c1">5</span><span class="pl-k">×</span><span class="pl-c1">4</span><span class="pl-k">×</span><span class="pl-c1">3</span><span class="pl-k">×</span><span class="pl-c1">2</span> Array{Float64, <span class="pl-c1">5</span>} at index [<span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">3</span>]
Stacktrace<span class="pl-k">:</span>
 [<span class="pl-c1">1</span>] getindex
   @ <span class="pl-k">./</span>array<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">834</span> [inlined]
 [<span class="pl-c1">2</span>] <span class="pl-c1">getindex</span>(<span class="pl-k">::</span><span class="pl-c1">Array{Float64, 5}</span>, <span class="pl-k">::</span><span class="pl-c1">CartesianIndex{2}</span>, <span class="pl-k">::</span><span class="pl-c1">Int64</span>, <span class="pl-k">::</span><span class="pl-c1">Int64</span>, <span class="pl-k">::</span><span class="pl-c1">Int64</span>)
   @ Base <span class="pl-k">./</span>multidimensional<span class="pl-k">.</span>jl<span class="pl-k">:</span><span class="pl-c1">638</span>
 [<span class="pl-c1">3</span>] top<span class="pl-k">-</span>level scope
   @ REPL[<span class="pl-c1">19</span>]<span class="pl-k">:</span><span class="pl-c1">1</span></pre></div>
<p dir="auto">The <code class="notranslate">Meta.@lower</code>, shown separately because it messes up highlighting of all downstream code (edit: edited it to close the opening "`"):</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="julia&gt; Meta.@lower A[i,begin,end,2]
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope`
1 ─ %1 = Base.firstindex(A, 2)
│   %2 = Base.lastindex(A, 3)
│   %3 = Base.getindex(A, i, %1, %2, 2)
└──      return %3
))))"><pre class="notranslate">julia<span class="pl-k">&gt;</span> Meta<span class="pl-k">.</span><span class="pl-c1">@lower</span> A[i,<span class="pl-c1">begin</span>,<span class="pl-c1">end</span>,<span class="pl-c1">2</span>]
:(<span class="pl-k">$</span>(<span class="pl-c1">Expr</span>(<span class="pl-c1">:thunk</span>, <span class="pl-c1">CodeInfo</span>(
    @ none within <span class="pl-s"><span class="pl-pds">`</span>top-level scope<span class="pl-pds">`</span></span>
<span class="pl-c1">1</span> ─ <span class="pl-k">%</span><span class="pl-c1">1</span> <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">firstindex</span>(A, <span class="pl-c1">2</span>)
│   <span class="pl-k">%</span><span class="pl-c1">2</span> <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">lastindex</span>(A, <span class="pl-c1">3</span>)
│   <span class="pl-k">%</span><span class="pl-c1">3</span> <span class="pl-k">=</span> Base<span class="pl-k">.</span><span class="pl-c1">getindex</span>(A, i, <span class="pl-k">%</span><span class="pl-c1">1</span>, <span class="pl-k">%</span><span class="pl-c1">2</span>, <span class="pl-c1">2</span>)
└──      <span class="pl-k">return</span> <span class="pl-k">%</span><span class="pl-c1">3</span>
))))</pre></div>
<p dir="auto"><code class="notranslate">begin</code>/<code class="notranslate">end</code> is syntax based, so the second index -&gt; <code class="notranslate">firstindex(A,2)</code>/<code class="notranslate">lastindex(A,2)</code>, without considering that the first index could be of varying dimension.</p>