I am stuck writing a macro to create variables from an array of names (as strings) and an array of values to be assigned.
So this is what I start with:
Names = ["R", "k", "y"] Values = [1.01, 4.7, 1.3]
what I would like to have is a macro which translates to the following (or equivalent) in the local scope:
R, k, y = [1.01, 4.7, 1.3]
I read the documentation section on metaprogramming, went through tutorials, and searched on the forum but it is still not clear to me how to solve this. Parameters.jl does not handle and unknown number of variables as I understand it.
The best I could come up with is this:
macro assign_loop(nms,vls) expr = quote local ii = 1 for NMS in $nms NMS = $vls[ii] ii += 1 end end return esc(expr) end
but when I test it, the “assigned” variable is not recognised.
function test(a, b) @assign_loop(a, b) print(y) end test(Symbol.(Names), Values)
Any help would be much appreciated.