It's a bit of a stupid question, but I don't really know how to deal with this efficiently.
So, in many application I have some model with parameters, and I want to the able to change the number of parameters, or they order easily.
For passing parameters to functions I want to pack them into a vector p, such that I don't have huge function definition, but inside
the function's body I'd prefer to have all the parameters given by their name, so I can use them in equations (instead of using p[1], p[2], ...).
I can write two functions p = pack(a,b,c) and (a,b,c) = unpack(p) but that's pretty restrictive because if you add or remove a parameters, I have to change all
my function calls and definition. If I add another model I also need to write another pack and unpack pairs.
Is there an better approach to do this in Julia ? I was thinking maybe doing a macro @unpack p that would spawn all the variables needed, but I'm not
sure that's the right way to do it.
a, b, c = 1:3
string((1:3)...)
Ivara = p[1]b = p[2]c = p[2]
function F1(n,p)
@unpack n preturn a*cos(b-c)
end
Is it possible to do something like defining a piece of code, and then just insert it when needed ? Something like:
@insertcodehere somecode
I'm trying to write an unpack macro, just to learn a bit about meta-programming (I get it's probably not the best idea,but sometimes you learn a lot doing stupid things)
quote
a = p[1]b = p[2]
end