What is the reason that case 3 fails? And how to avoid this?
How can I initialize a Dict to enable values of different type?
Here is my snippet:
function MyDictFill(_a::Dict = Dict())
if ~haskey(_a, "a")
_a["a"] = true
end
if ~haskey(_a, "b")
_a["b"] = 1.0
end
if ~haskey(_a, "c")
_a["c"] = "str"
end
return _a
end
# case 1: ok
MyDictFill()
# case 2: ok
begin
dict_a = Dict()
dict_a["d"] = "star"
dict_a["e"] = 1
dict_a["f"] = true
MyDictFill(dict_a)
end
# case 3: fails
begin
dict_b = Dict()
dict_b = Dict("d" => 2)
dict_b = Dict("f" => "julia")
MyDictFill(dict_b)
end