# Hold all the symbols from a huge list?

The two following codes work similarly:

Num = 5;
symbols = Hold[X1, X2, X3, X4, X5];


or

Num = 5;
Xlists= StringJoin["X", #] & /@ Array[ToString, Num];
symbols = Hold[Xlists[[1]], Xlists[[2]], Xlists[[3]], Xlists[[4]], Xlists[[5]]];


Question:

When Num is large (for instance Num=200), I would not like to use the stupid way: write all the X1, X2, ..., X200 in the Hold[].

I wonder whether there are something like Hold[Xlists] for such problem. Well, I tried different ways but failed.

Thank you very much in advance!

Edit2:

Num=5;
data = {{0, 0, 0}, {1, 2, 3}, {2, 3, 4}, {4, 5, 6}, {0, 1, 2}};
For[ii = 1, ii <= Num, ii++,
symbols[[{ii}]] /. _[x_] :> (x = data[[ii]])
];


I know that the X1,X2,...X5 will have certain values such as X1 will be {0,0,0}. Then it seems that I cannot get the symbol X1 using the way symbols[[1]] because it will return {0,0,0} not X1 (except I directly write as X1).

So after giving values to X1,X2,..., how can I can the it form symbols instead of directly using X1,X2,...

Thank you!

• @xzczd, thank you for pointing out. I have modified it. – Marie Apr 28 '20 at 11:57
• When e.g. X1=12345, what behavior is desired? Hold[X1, X2, X3, X4, X5], or Hold[12345, X2, X3, X4, X5]? – xzczd Apr 28 '20 at 12:02
• @xzczd, X1 and all the Xn is a symbol which you can give values later. I think it is Hold[X1, X2, X3, X4, X5], and then give values to certain symbol. because I would like to use DumpSave for storing with the related symbol. Since DumpSave doesn't work for something like list[[1]]. – Marie Apr 28 '20 at 12:18
• Then why not Hold @@ (Symbol["X" <> ToString@#] & /@ Range[5])? – xzczd Apr 28 '20 at 12:29
• @xzczd, oh, thank you. I don't know this way. – Marie Apr 28 '20 at 12:37

You can use the fourth argument of Array as follows:

Array["X" <> ToString@# &, Num, 1, Hold[##] &]

 Hold["X1", "X2", "X3", "X4", "X5"]

Array[Symbol["X" <> ToString@#] &, Num, 1, Hold[##] &]

 Hold[X1, X2, X3, X4, X5]


If you want to wrap each element with Hold:

Array["X" <> ToString@# &, Num, 1, Hold /@ {##} &]

{Hold["X1"], Hold["X2"], Hold["X3"], Hold["X4"], Hold["X5"]}

Array[Symbol["X" <> ToString@#] &, Num, 1, Hold /@ {##} &]

{Hold[X1], Hold[X2], Hold[X3], Hold[X4], Hold[X5]}

• thank you again, kglr :) so helpful! – Marie Apr 28 '20 at 11:58
• @Xuemei, my pleasure. – kglr Apr 28 '20 at 12:02
• I edit one small question in the end: if i give values to X1,X2,... and then symbols[[index]] will not return the symbol X1,X2,... as I want but gives me the given values. Could you please have a look? Thank you very much! do you think it is possible? – Marie Apr 28 '20 at 13:19
• hey, kglr. the Edit2 part is something like "give values to variable and then get the name (or symbol) of variable" instead writing the variable itself (since there will be many variables in the form of X1, X2, X3,...). Thank you! – Marie Apr 28 '20 at 13:42
• I just thought to use Name["X*"]. thank you anyway :) – Marie Apr 28 '20 at 15:41