Can I overload []?

Here is one way to see how these type of syntaxes work (and thus also what you need to overload):

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

julia> Meta.@lower a[i, j] = x
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope'
1 ─     Base.setindex!(a, x, i, j)
└──     return x
))))
9 Likes