How to output the name of a tuple?

julia> aTuple = (1,2,3,4)
(1, 2, 3, 4)

julia> string(aTuple)
"(1, 2, 3, 4)"

julia> println(aTuple)
(1, 2, 3, 4)

How can I just get the name “aTuple”, instead of its content?

“aTuple” is not the name of the tuple. Its a variable named “aTuple” which holds as a value a tuple.

As far as I know, there is no “easy” way to output the name of a variable as a string.
You may look at


for some ideas on how to achieve that anyways.

And maybe this
https://docs.julialang.org/en/v1/manual/functions/#Tuples-1
is worth a reading for general information about “named tuples”.

Maybe you want something like a named tuple?
In Julia 1.0:

named_tuple = (aTuple = (1,2,3,4),)
julia> named_tuple.aTuple
(1, 2, 3, 4)
julia> keys(named_tuple)[1]
:aTuple
1 Like

Macros can do this.

macro getname(name)
    return "$name"
end

mytuple = (1., 2.)
@getname(mytuple)

returns the string

"mytuple"
1 Like

Thanks to all. NamedTuple seems a better fit.

What is wrong with "aTuple"?

I was looping through a bunch of tuples and the names were not handy. Now NamedTuple solves the problem easily.