I've struggled with this exact problem in python in the past (e.g.
https://stackoverflow.com/questions/16182898/unpacking-parameters-for-a-simulation).
It's exacerbated by the fact that interfaces to solvers, optimizers, etc.
often require the parameters be passed in as a vector, so using
Have you looked into using keyword arguments?
http://julia.readthedocs.org/en/latest/manual/functions/#keyword-arguments
On Friday, March 7, 2014 8:15:58 AM UTC-6, 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
Basically I want to define only once the name of my parameters, and never
write them down in function's arguments or declare them in function's body,
such that I can add, remove, rename, reorder parameters without having to
do anything, and still have all my parameters available in my functions
How amazing! I have been about to post the very same question to this list!
So, I wouldn't say it's a stupid question at all :)
I believe this kind of packing/unpacking of several heterogeneous (in
structure, not in type) parameters appear a lot in modeling and
optimization.
This probably is a
RE some kind of `@unpack` macro: have a look at this question on Stack
Overflow and its answers:
http://stackoverflow.com/questions/9345056/in-clojure-how-to-destructure-all-the-keys-of-a-map/11182432#11182432
Interestingly enough it is possible to an extent, but for many reasons ends
up being
Maybe I don't understand the problem well enough, but I think that an immutable
type could work pretty well. You will have to qualify your references to the
members, but you only have to declare the names and types once. I think it was
discussed to create default constructors with keyword
are you guys looking for something like attach in R?
(it's not clear to me what you want, although a reference to python sounds
like it might have been stickng values into an object's dict).
andrew
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],