Ref expression receivers

In a ref expression such as
a[:x] =5
a[1] = 12

what can a be?
a dictionary, an array and what else?

Thanks

Anything that defines setindex! on it.

You can look with methods(setindex!) to see the one in Base.

julia> methods(setindex!)
# 81 methods for generic function "setindex!":
[1] setindex!(::Base.EnvDict, v, k::AbstractString) in Base at env.jl:83
[2] setindex!(x::Base.Threads.Atomic{Int8}, v::Int8) in Base.Threads at atomics.jl:356
[3] setindex!(x::Base.Threads.Atomic{Int16}, v::Int16) in Base.Threads at atomics.jl:356
[4] setindex!(x::Base.Threads.Atomic{Int32}, v::Int32) in Base.Threads at atomics.jl:356
[5] setindex!(x::Base.Threads.Atomic{Int64}, v::Int64) in Base.Threads at atomics.jl:356
[6] setindex!(x::Base.Threads.Atomic{Int128}, v::Int128) in Base.Threads at atomics.jl:356
[7] setindex!(x::Base.Threads.Atomic{UInt8}, v::UInt8) in Base.Threads at atomics.jl:356
[8] setindex!(x::Base.Threads.Atomic{UInt16}, v::UInt16) in Base.Threads at atomics.jl:356
[9] setindex!(x::Base.Threads.Atomic{UInt32}, v::UInt32) in Base.Threads at atomics.jl:356
[10] setindex!(x::Base.Threads.Atomic{UInt64}, v::UInt64) in Base.Threads at atomics.jl:356
[11] setindex!(x::Base.Threads.Atomic{UInt128}, v::UInt128) in Base.Threads at atomics.jl:356
[12] setindex!(x::Base.Threads.Atomic{Float16}, v::Float16) in Base.Threads at atomics.jl:356
[13] setindex!(x::Base.Threads.Atomic{Float32}, v::Float32) in Base.Threads at atomics.jl:356
[14] setindex!(x::Base.Threads.Atomic{Float64}, v::Float64) in Base.Threads at atomics.jl:356
[15] setindex!(x::Base.Threads.Atomic{Bool}, v::Bool) in Base.Threads at atomics.jl:356
[16] setindex!(buffer::Base64.Buffer, v::UInt8, i::Integer) in Base64 at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Base64/src/buffer.jl:17
[17] setindex!(md::Markdown.MD, args...) in Markdown at /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.0/Markdown/src/parse/parse.jl:25
[18] setindex!(A::Array{Any,N} where N, x, i::Int64) in Base at essentials.jl:440
[19] setindex!(b::Base.RefValue, x) in Base at refvalue.jl:33
[20] setindex!(b::Base.RefArray, x) in Base at refpointer.jl:120
[21] setindex!(A::Array{T,N} where N, x, i1::Int64) where T in Base at array.jl:769
...
[77] setindex!(h::Dict{K,V}, v0, key::K) where {K, V} in Base at dict.jl:381
[78] setindex!(h::Dict{K,V}, v0, key0) where {K, V} in Base at dict.jl:373
[79] setindex!(wkh::WeakKeyDict{K,V} where V, v, key) where K in Base at weakkeydict.jl:79
[80] setindex!(t::AbstractDict, v, k1, k2, ks...) in Base at abstractdict.jl:480
[81] setindex!(x::Base.Threads.Atomic{T}, v) where T in Base.Threads at atomics.jl:321
```

Thanks for the answer.

is there a way to check whether a[:x], a[:x,1] ,a[1,1,1] or a[1] is already assigned? without knowing the type of a.

Thanks

You have to define what “assigned” means a bit more closely.

assigned means there is a[:x], a[1,1,1] will not return an runtime error, such as BoundsError, KeyError
and etc

Not in general.

For arrays you would have to check checkbounds (and isassigned if the element type is a non bitstype) and for dicts haskey.