Named tuples are a great way to work with sets of parameters where the type can be inferred. Compared to using a named structure with Parameters.jl
, the big thing missing seems to be creating them with default values.
So I wonder if there is a macro that can be written (and maybe added to Parameters.jl
) which can simplify the boilerplate for this? First, I just wanted to get a sanity check that this programming pattern is the right one:
using NamedTuples, Distributions
myparameterfactory(;a=1, b = Normal(0,1), c= [1; 3]) = @NT(a=a, b=b, c=c) #Drop the @NT in v0.7
#To use
paramset1 = myparameterfactory(a=2)
paramset2 = myparameterfactory(b=Exponential(0.2))
Is “factory” the right terminology here, or is there something better?
Next: while the boilerplate here for the factory is relatively simple and idiot-proof, I am curious if there is a macro to do it automatically for an arbitrary number of parameters? i.e.
myparameterfactory = @NTfactory(a = 1, b = Normal(0,1))
I wasn’t sure how to write this sort of macro, whether it is worth it, and what it should be called. Any thoughts?