Hi all,
I just wanted to know if it is possible to unpack named tuples in the following context. I know that Parameters.jl
addresses some related issues, but I have not been able to figure out if it can handle the following case. Define a named tuple using @with_kw
:
ParamsNamedTuple = @with_kw (
T = 1.0,
K = 0.5,
M = T + K,
v = zeros(2),
d = 0.1,
t = [i * d for i in 0:10]
)
We can unpack particular components of a particular instance using:
julia> params = ParamsNamedTuple();
julia> @unpack T, K = params;
julia> T
1.0
julia> K
0.5
julia> M
ERROR: UndefVarError: M not defined
However, I would like to unpack them all:
@unpack params
Is this possible?
On the other hand, I know that we can unpack all the objects if instead of defining a named tuple we define a struct, such as:
@with_kw struct ParamsStruct{T1, T2, T3, T4, T5, T6}
T::T1 = 1.0
K::T2 = 0.5
M::T3 = T + K
v::T4 = zeros(2)
d::T5 = 0.1
t::T6 = [i * d for i in 0:10]
end
Then:
params = ParamsStruct()
@unpack_ParamsStruct params
Any unpacking strategy would be ok. There is no need to use a macro in Parameters.jl
or any other package.
Thank you!