x -> Int64
,那么这就没有意义了:initilizer不需要参数,它应该返回一个值,而不是一个类型。你可能想用的是
() -> Int64[]
:
julia> genome = DefaultDict{Tuple{String, String}, Array{Int64, 1}}(() -> Int64[])
DefaultDict{Tuple{String,String},Array{Int64,1},getfield(Main, Symbol("##7#8"))} with 0 entries
julia> genome["a", "b"]
0-element Array{Int64,1}
julia> push!(genome["a", "c"], 5)
1-element Array{Int64,1}:
5
julia> genome
DefaultDict{Tuple{String,String},Array{Int64,1},getfield(Main, Symbol("##7#8"))} with 2 entries:
("a", "c") => [5]
("a", "b") => Int64[]
julia> push!(genome["a", "b"], 4)
1-element Array{Int64,1}:
4
julia> genome
DefaultDict{Tuple{String,String},Array{Int64,1},getfield(Main, Symbol("##7#8"))} with 2 entries:
("a", "c") => [5]
("a", "b") => [4]
如果要基于尝试过的键创建默认值,可以使用
passkey = true
以及一个以键为参数的初始化函数;看见
the docs
所有选项。