using a name macro for variables from a functions inputs

Viewed 167

If I have 2 variables, a=[.3, .2, .4]; b=[.1, .2, .3]; I can create a string with the name of the variable using a macro:

macro varname(arg)
    string(arg)
end

@varname(a)

now say I have a function and I want to pass it an arbitrary number of arguments and use the actual variable names that are being given to function to create dictionary keys:

function test(arguments...)
    Dict(Symbol(@varname(i)) => i for i in arguments)
end

this won't work because @varname will take i and create "i", so for example:

out=test(a,b)

the output I would like is:

Dict("a" => [.3, .2, .4], "b" => [.1, .2, .3])

Is there a way to achieve this behavior?

1 Answers
Related