Hi everyone, 

As the title suggests, I am trying to create local variables to a function 
for a supplied dictionary argument. The Dict would be of type {Symbol, Any} 
and the goal is to create a variable for each symbol that has the 
corresponding value. I am aware that I could use eval in something like:

for (k, v) in dict
    eval(:($k = $v))
end

However, eval defined its variables in the global scope which has 
performance repercussions if I understand correctly, so I am trying to 
avoid that.

I will add a bit of context in case you have suggestions that are 
drastically different than the path I am going for. I am doing this as I am 
implementing a wrapper around the JuMP JuliaOpt module allowing the users 
to dynamically create optimization models with arbitrary constraint 
expressions. Since the constraint expressions are defined using symbols, 
and JuMP requires those symbols to be defined in the current scope, I want 
the user to provide those symbols and their values in a dictionary to the 
function. Defining the symbols globally would be cumbersome as the user 
should ideally be able to run the function multiple times with the same 
constraint expressions (i.e. same symbols) but different values. 

I appreciate your help!

Reply via email to