Can you have alias in Julia?

Viewed 76

Suppose that I have plenty of different variables:

t_time, m_time, s_time, TL_reached, gap, UB, LB, nopt_cons, nsubtour_cons, nconnectivity_cuts, nhubs, m_cost, sp_cost

Can I allias them and instead of writing:

t_time, m_time, s_time, TL_reached, gap, UB, LB, nopt_cons, nsubtour_cons, nconnectivity_cuts, nhubs, m_cost, sp_cost = [t_time, m_time, s_time, TL_reached, gap, UB, LB, nopt_cons, nsubtour_cons, nconnectivity_cuts, nhubs, m_cost, sp_cost]./5

write something that would be similar to:

alias vars = 't_time, m_time, s_time, TL_reached, gap, UB, LB, nopt_cons, nsubtour_cons, nconnectivity_cuts, nhubs, m_cost, sp_cost'

And finally:

vars = [vars]./5

1 Answers

There isn't a language feature for anything like this. You could probably do it with a macro but it seems a bit ill advised. It might make more sense to capture all thees fields in data structure; if they're all the same type (e.g. Float64) then you could use AxisArrays to associate names to the dimensions of a vector of values. If they're of heterogenous types, then you could make a custom struct type and define the arithmetic operations that you want to perform on the type.

Related