Hi, as I would like to use dict’s dict to storage and visiting data, but I can not find the correct grammar to stat the dict’s dict, initiate it and visiting it.
Can anybody give some examples about how to do it in julia? In perl, we use a lot similar features like hash’hash; hash’s array.
julia> dict = Dict()
Dict{Any,Any} with 0 entries
julia> dict["b"] = Dict("a" => "This is a test")
Dict{String,String} with 1 entry:
"a" => "This is a test"
julia> dict["b"]["a"]
"This is a test"
Why not simply use Dict{String, Dict{String, String}}?
dic = Dict(
"b" => Dict("a", "This is a test of dict of dict")
)
default(::Type{Dict{K, V}}) where {K, V} = Dict{K, V}()
default(::Type{Int}) = 0
default(::Type{String}) = ""
setter(k) = v -> dic -> dic[k] = v
getter(k :: K) where K = function (dic :: Dict{K, V}) where V
get!(dic, k) do
default(V)
end
end
set1(v) = setter("a")(v) \circ getter("b")
set1("dict.b.a")(dic)
set2(v) = setter("c")(v) \circ getter("b")
set2("dict.b.c")(dic)