julia> type parameters
p1::Float64
p2::Float64
p3::Float64
end
julia> params = parameters(1,2,3)
parameters(1.0,2.0,3.0)
julia> label = "p1"
"p1"
julia> params.(symbol(label))
1.0
On Tuesday, September 30, 2014 2:43:57 PM UTC+2, [email protected] wrote:
>
> Dear all,
>
> This is somewhat the following of a previous topic:
> https://groups.google.com/forum/#!topic/julia-users/CvQMwq2rN9I but since
> the two issues have little in common, I thought it was better to create a
> new topic.
>
> I'd like to access the members of a type via a string, i.e. if I define:
>
> type parameters
> p1::Float64
> p2::Float64
> p3::Float64
> end
>
> p = parameters(3.6, 0.6, 600.0)
>
> label = "p1"
>
> is there a way to access p.p1 through something like:
>
> p.names(label)
>
> I guess this has to do with reflection in julia. I know there is a way to
> get the names through
>
> names(p)
>
> but there's nothing in the documentation about what I'm looking for. I did
> some research and I came across this reflection.jl file:
> https://github.com/JuliaLang/julia/blob/master/base/reflection.jl that I
> tried to decypher, but with little success. (Incidentally, I'd be
> interested in understanding what happens here if there's some resource
> helping to do so.)
>
> Thanks a lot,
>
> AS
>