Is there a way to display the variable name instead of its value? for example, I need something likevarname = 1; function[varname]; and the output is varname instead of 1
Asked
Active
Viewed 2,595 times
2 Answers
7
There's also Defer to accomplish this:
varname = 1;
Defer @ varname
varname
RunnyKine
- 33,088
- 3
- 109
- 176
2
varname = 1;
SetAttributes[ShowName, HoldAll]
ShowName[name_] :=
Row[{"The name is ", HoldForm @ varname, " and its value is ", ReleaseHold @ varname}]
ShowName @ varname
The name is varname and its value is 1
Or simply
HoldForm @ varname
varname
eldo
- 67,911
- 5
- 60
- 168
HoldForm? There are many threads onHolding around, please have a look. – Yves Klett Sep 16 '14 at 13:13