You were missing a ;
when calling the Param
keyword constructor. This now runs for me:
using Parameters: @with_kw
using NamedTuples
@with_kw struct Param
mean = 0.
variance = 1.
end
struct Solver
params::Dict{Symbol,Param}
end
function Solver(params...)
# build Dict for inner ctor
dict = Dict{Symbol,Param}()
for (varname, varparams) in params
# varparams is a NamedTuple
d = Dict(k => v for (k,v) in zip(fieldnames(typeof(varparams)), varparams))
push!(dict, varname => Param(; d...))
end
Solver(dict)
end
solver = Solver(
:var1 => @NT(mean=1.),
:var2 => @NT(variance=2)
)
Note that your lines above are still not an MWE, because GaussianVariogram
is not defined, and variogram
is not a field Param
knows about. I of course modified it accordingly, but when you are asking for help with code, posting a self-contained MWE in a single post will get you replies much faster.