By reading your question once again, I realised that it may be not quite 
like mine.

If you are ok with using p.a, p.b, p.c, ... then the custom composite type 
is the solution.
A more flexible approach (as I do) is the dictionary with symbols as keys 
which would then be called by p[:a], p[:b], p[:c]...
It is expected that in future the dot operator is going to be overloadable 
(https://github.com/JuliaLang/julia/issues/1974), allowing the creation of 
dictionary types whose symbol keys can be accessed as p.a, p.b, p.c...

If you strictly want to call parameters by a, b, c... then maybe some macro 
can solve it, about this I cannot help.

On the other hand, I really need p to be a Vector, so it can be seen as 
such by optimisation and linear algebra routines. In that case some 
packing/unpacking functions need to be called and probably some copies will 
always have to happen. What I'm looking for is way to have generalized and 
yet well performing packing/unpacking functions, flexible enough to allow 
easy addition/reorder of parameters.

Please let me spoil a little the OP, and ask if someone can point some 
insights on my problem.


On Friday, March 7, 2014 2:15:58 PM UTC, Yuuki Soho wrote:
>
> 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.
>

Reply via email to