How to define many variables in few lines?

You can use metaprogramming:

for i = 1:100
    var_name = Symbol("a", i)
    @eval $var_name = Ref{Float64}(1.0)
end

But I agree with the other posters that this is probably not a good idea.

Edit:
x = Ref{Float64}() initializes x with an undefined (i.e. arbitrary, not reproducable) value. But this is dangerous.
An alternative would be to explicitly use missing: x = Ref{Union{Float64, Missing}}(missing)

2 Likes