Making a list of patterns of arbitrary length
Array[ToExpression["x" <> ToString @ # <> "_"] &, {5}]
{x1_, x2_, x3_, x4_, x5_}
FullForm @ %
List[Pattern[x1,Blank[]], Pattern[x2, Blank[]], Pattern[x3, Blank[]], Pattern[x4, Blank[]], Pattern[x5, Blank[]]]
Also
Thread[Pattern[Evaluate@Array[Symbol["x" <> ToString@#] &, {5}], Blank[]]]
{x1_, x2_, x3_, x4_, x5_}
and
ToExpression[Table["x" <> i <> "_", {i, ToString /@ Range[5]}]]
{x1_, x2_, x3_, x4_, x5_}
If you construct a list of strings instead, you can take advantage of the fact that ToExpression
is listable, and supports a 3rd argument that post-processes the output. For example:
ToExpression[
{"x1", "x2", "x3"},
StandardForm,
Pattern[#,Blank[]]&
]
{x1_, x2_, x3_}
Or, creating the list and converting:
ToExpression[
Table["x" <> ToString@i, {i, 5}],
StandardForm,
Pattern[#, Blank[]]&
]
{x1_, x2_, x3_, x4_, x5_}
Nothing new but shorter:
StringTemplate["x``_"] /@ Range[10] // ToExpression
{x1_, x2_, x3_, x4_, x5_, x6_, x7_, x8_, x9_, x10_}