Skip to main content
2 of 2
Corrected explanation
Leonid Shifrin
  • 115.8k
  • 16
  • 341
  • 435

This is the same issue as described here (and in references therein). I suggest to read that answer and the linked discussions for an explanation of why this happens.

The workaround can be also the same as mentioned there:

foo2[x_] := With[{rule = Rule}, Table[rule[(unk /. log[var_] -> var), x], {unk, unks}] ] 

So that now

foo2[5] (* {n -> 5} *) 

Basically, it fools RuleDelayed (the one that results from SetDelayed, in DownValues[foo2]), so that it does not recognise the inner rule as such, and so does not rename var in one part of the inner rule during the rule application.

Leonid Shifrin
  • 115.8k
  • 16
  • 341
  • 435