1

I'd like to display only the variable (indexed variable) name (in symbol form, not in string form) instead of its value in Mathematica. Say I have a variable foo[i] with i being the index, How do I get something like {foo[1], foo[2]} as output?

I have tried i = 1; HoldForm[foo[i]] but Mathematica seems to hold all evaluations, including replacing the index i with its value. HoldForm[foo[i]] /. i -> i also won't work.

There exists another thread in SE that connects with this question, but it doesn't seem to work either.

Display variable name instead of value

1 Answers1

4

I believe this is what you're seeking:

HoldForm[foo] /@ Range[2]

and if you want individual elements:

(HoldForm[foo] /@ Range[2])[[1]]

and

(HoldForm[foo] /@ Range[2])[[2]]
David G. Stork
  • 41,180
  • 3
  • 34
  • 96