How to inject unevaluated list of Unique into a RuleDelayed?
This can be a good case for a Block
trick:
Block[{Unique},
With[{x = Table[Unique[], {i, 1, 3}]}, rules = {patt :> x}]
]
(* {patt :> {Unique[], Unique[], Unique[]}} *)
$userInt = 5;
With[{
x = Table[Inactive@Unique[], {i, $userInt}]
},
rules = {_Integer :> x} // Activate
]
{_Integer :> {Unique[], Unique[], Unique[], Unique[], Unique[]}}
{1} /. rules
{{$27, $28, $29, $30, $31}}
So many ways:
Apply[Unique, (patt :> #) & @ Table[{}, {3}], {2}]
(patt :> Evaluate@Table[foo[], {3}]) /. foo -> Unique
Hold[Unique[]][[Range[3]^0]] /. _[x__] :> (patt :> {x})
(patt :> {##}) & @@ Table[Unevaluated @ Unevaluated @ Unique[], {3}]
(Function @@ {patt :> Evaluate@Table[#[], {3}]}) @ Unique
All produce:
patt :> {Unique[], Unique[], Unique[]}
But I must say I don't see why you wouldn't just use:
rule = patt :> Table[Unique[], {3}];
patt /. rule
patt /. rule
{$3, $4, $5} {$6, $7, $8}