I shall assume that you want a compact syntax to make this practical to use.
I shall choose cs
, standing for compound symbol:
cs[x__] :=
ToHeldExpression @ ToString @ Row @ {x} /.
{_[s_Symbol] :> s, _ :> $Failed}
func_[a___, Unevaluated @ cs[x__], b___] ^:=
ToHeldExpression @ ToString @ Row @ {x} /.
{_[s_Symbol] :> func[a, s, b], _ :> $Failed}
Test:
i = 10;
cs["d", i] = 30;
d10
30
Any expressions can be used so long as their evaluated forms concatenate to a valid Symbol name:
cs[Pi, d10, "x"] = 86;
Pi30x
86
Reassignment is possible:
cs[Pi, d10, "x"] = 99;
Pi30x
99
If an invalid Symbol name is produced by the concatenation $Failed
is returned:
cs[5, "x"] = 30
$Failed
(Symbol names cannot start with numbers.)
Recommended reading:
Symbol["name"]
: "refers to a symbol with the specified name." $\endgroup$Evaluate[ToExpression["d"~~ToString[i]]] = 30
$\endgroup$x[i]
? It's not exactly what you asked for; but if you don't know you can usex[i]
as a variable, which representsx[10]
wheni
is10
, then you might not know to ask for it. $\endgroup$