A lot of the time it is good to copy a structure to local variables and
then process on those for efficiency before storing the local values back
to a structure. To help out with this I'm trying to write a macro, so this
is what I would like the end result to be:
Point
x::Float64
y::Float64
end
function process (p::Point)
local x = p.x;
local y = p.y;
# do some processing on x and y
p.x = x
p.y = y
end
and I would like write a macro that does this so the end code would like
like:
function process (p::Point)
@fetch p
# do some processing on x and y
@store p
end
So far I've got this working at the REPL using:
point = Point (1, 2)
map (eval, ([:($name = point.$name) for name in names(point)]))
println("x=$(x) y=$(y)")
which prints out: x=1.0 y=2.0
Can someone please help out turning this into a macro?