Yep, an automated way of doing that is exactly what I want. Here is an
example structure that I want to fetch every member of before doing
intensive numeric processing for an iterative solver:
type CircuitModel
v1::Float64
v5::Float64
v7::Float64
v2::Float64
v3::Float64
v4::Float64
v9::Float64
v12::Float64
v15::Float64
v18::Float64
v19::Float64
v20::Float64
v21::Float64
v8::Float64
v22::Float64
v23::Float64
v24::Float64
i1::Float64
i2::Float64
i3::Float64
i4::Float64
i5::Float64
i6::Float64
i7::Float64
ic1eq::Float64
ic2eq::Float64
ic3eq::Float64
ic4eq::Float64
ic5eq::Float64
ic6eq::Float64
ic7eq::Float64
ic8eq::Float64
sr::Float64
srinv::Float64
pi::Float64
gmin::Float64
is1::Float64
nvtf1::Float64
is2::Float64
nvtf2::Float64
nvtinvf1::Float64
vcritf1::Float64
nvtinvf2::Float64
vcritf2::Float64
gc1::Float64
gr1::Float64
gr2::Float64
itxr2::Float64
gc2::Float64
gc3::Float64
gc4::Float64
gc5::Float64
gr7::Float64
gc6::Float64
gr3::Float64
itxr3::Float64
gc7::Float64
gr4::Float64
gc8::Float64
gr5::Float64
vpos::Float64
vneg::Float64
gin::Float64
gininv::Float64
vposcap::Float64
vnegcap::Float64
ginotacore::Float64
ginotares::Float64
ginotacoreinv::Float64
ginotaresinv::Float64
vc3lo::Float64
vc3hi::Float64
a4a4c::Float64
a5a5c::Float64
a6a6c::Float64
a14a14c::Float64
a16a16c::Float64
a17a17c::Float64
a17a17nrmc::Float64
a12a17c::Float64
a16a16nrmc::Float64
a15a16c::Float64
a14a14nrmc::Float64
a13a14c::Float64
a6a14c::Float64
a13a6c::Float64
a5a5nrmc::Float64
a4a5c::Float64
a2a5c::Float64
a2a4c::Float64
a4a4nrmc::Float64
a1a4c::Float64
v5c::Float64
v7c::Float64
end
function process1 (state::CircuitModel, input::Float64)
@fetch state
# loop over an algorithm using all the named items in state to solve
for the next input changing the state
@store state
end
function process1 (state::CircuitModel, input::Float64)
@fetch state
# loop over an algorithm using all the named items in state to solve
for the next input changing the state
@store state
end
function process2 (state::CircuitModel, input::Float64)
@fetch state
# loop over an algorithm using all the named items in state to solve
for the next input changing the state
@store state
end
function process3 (state::CircuitModel, input::Float64)
@fetch state
# loop over an algorithm using all the named items in state to solve
for the next input changing the state
@store state
end
So I don't want to have actual duplicate code doing all the copying of the
state to local variables since then if I add a new variable to the type
then I have to update the copy to local variables in all 3 functions, so
this makes things a bit brittle.
A better option would be to support a "using" statement, along the lines of:
function process4 (state::CircuitModel, input::Float64)
using state;
# loop over an algorithm using all the named items in state to solve
for the next input changing the state
end
But I was hoping I could write a macro as a workaround for now, but it
seems macros can't handle what I want.
On Monday, June 9, 2014 7:55:54 AM UTC+8, Ismael VC wrote:
>
> How about this?
>
> julia> function distance(point::Point)
> x = point.x
> y = point.y
> sqrt(x*x + y*y)
> end
>
>
>