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
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]
1 Like

Macros can do this.

macro getname(name)
    return "$name"

mytuple = (1., 2.)

returns the string

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.