# Get the name of symbol inside a function [duplicate]

I have a list t1Funcsv0={0.10000000000, 1.00000*10^-7} and I have a function

Maximum[functions_, min_, max_, type_] := (
Which[
Flatten[Position[functions, Max[functions]]],
Max[functions] == nt,
Flatten[Position[functions, nt]],
RankedMax[functions, 2] == nt,
Flatten[{Position[functions, Max[functions]],Position[functions,nt]}],
True,
Print["Error Maximum"]])


to which I pass t1Funcsv0 as well as other arguments. I would like to get the name of the symbol "t1Funcsv0" inside the function Maximum. I tried to use SymbolName[Unevaluated@functions] as I found in Obtaining the name of a variable as a string and Get the name of a symbol passed to a function but it doesn't work because "functions" is already evaluated

• In the post you linked you see that they give their function the attribute HoldFirst. Have you tried that? – Jason B. Sep 13 '18 at 19:45
• Yes I did. If I use Trace I get {t1Funcsv0,{0.10000000000, 1.00000*10^-7}} – Rby Sep 13 '18 at 20:24
• I think the answer here is better at and much clearer then the one here Get the name of a symbol passed to a function – Rby Sep 13 '18 at 23:39

You have to use a Hold attribute if you want access to the symbol name during evaluation:

Attributes[myfunc] = HoldFirst;
myfunc[arg1_, arg2_] := (
Print["The name of the first argument is ", SymbolName[Unevaluated[arg1]]];
Print["The value of the first argument is ", arg1];
Print["The max of the first argument is ", Max[arg1]];
Print["The second argument is ", arg2]
)

t1Funcsv0 = {0.10000000000, 1.00000*10^-7}
myfunc[t1Funcsv0, bob]


The name of the first argument is t1Funcsv0

The value of the first argument is {0.1,1.*10^-7}

The max of the first argument is 0.1

The second argument is bob