Creating an anonymous function taking as arguments the elements in a vector

You can use ... to expand a collection (in this case vector_symbol) to multiple function arguments:

julia> vector_symbol = [ :temp, :press, :mass, :speed ]
4-element Array{Symbol,1}:
 :temp
 :press
 :mass
 :speed

julia> ex = :( temp * temp * mass)
:(temp * temp * mass)

julia> @eval f($(vector_symbol...)) = $ex
f (generic function with 1 method)

julia> f(1, 2, 3, 4)
3
6 Likes