I want to initialize a Dict comprised of some #undef values. How can I do this?
I tried Dict{String, Float64}(undef, 3) but it throws the following error:
ERROR: MethodError: no method matching Dict{String, Float64}(::UndefInitializer, ::Int64)
I also tried Dict{String, Float64}(undef=>undef) but it threw the following error:
ERROR: MethodError: Cannot `convert` an object of type UndefInitializer to an object of type String
The function `convert` exists, but no method is defined for this combination of argument types.
There is no way to directly define a Dict{String, Float64} that contains a #undef value. But you can create an empty Dict by using Dict{String, Float64}().
Or you can create an undefined vector and string first, and then make them a Dict:
a=3 # or missing, nothing
b=string()
c=Dict{String, Float64}(b=>a)
It makes sense for arrays, but what would that do for dictionaries?
What do you want to use it for? Do you want to pre-allocate many slots in the dictionary so that you can incrementally add many elements to it with minimum allocations (see sizehint!)?
No, I want it to create an initialized dictionary that doesn’t contain certain values so the user won’t be able to interpret the created Dict. Like, “oh, this doesn’t contain any valuable information”.
I’d say that canonically a Dict “marks” absent values by not having the corresponding key. So imo there is no need to have another special marker for “absent” values.
Alternatively Julia offers missing which embodies exactly the absence of information. So you could use that to marke the absent values.