Hi Julians
I have a vector vector_symbol that contains a variable number of elements of type Symbol. I also have the variable ex of type Expr that is an expression of the Symbol elements in vector_symbol.
For example:
vector_symbol = [ :temp, :press, :mass, :speed ]
ex = : ( temp * temp * mass)
I want to create an anonymous function f_anon that takes as arguments the elements in vector_symbol and that maps these arguments as coded in the expression ex.
I was hoping that something like this would work:
@eval f_anon( $i for i in vector_symbol ) = $ex
but I get the error
ERROR: UndefVarError: i not defined.
I could write:
@eval f_anon( $(vector_symbol[1]), $(vector_symbol[2]), $(vector_symbol[3]), $(vector_symbol[4]) ) = $ex
but this is hard coded; it will not work when vector_symbol has a length different from 4.
I was not able to find a solution in the documentation of Julia about metaprogramming and also the internet didnāt help me out.
Anybody ideas?
Many thanks!