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?
argumentsis a variable length tuple of positional parameters then they don't have names. If on the other hand, the definition isfunction test(;arguments...)which makesargumentsnamed parameters, thenDict(a[1]=>a[2] for a in arguments)should usually work (except for edge cases with argument names repeating etc).