Hello everyone,
I was playing around with Meta-programming and I was wondering if it is possible to facilitate writing long constructor call for a structure with many fields .
Suppose I have
struct s_example
arg_1
arg_2
...
arg_N
end
With a constructor
function define_s(parameters)
arg_1 = f(parameters)
...
arg_N = g(parameters)
object = s_example(arg_1,...,arg_N)
return object
end
Is it possible to make the call to s_example easier with metaprogramming ?
I tried this
function define_s_easen(parameters)
arg_1 = f(parameters)
...
arg_N = g(parameters)
object = eval(Expr(:call,s_example,fieldnames(s_example)...))
return object
end
But since eval look for arg_i in the global scope, we get arg_1 not defined. During compilation, how can I write the function to be defined as the trivial one define_s ?
( Or maybe It is an equivalent problem, is there a way in Julia to return all the variable defined inside a function ? )
Thank you in advance,
GD