Consider the simple code
r`outsideFormula = x;
Module[{f, g, insideFormula = 2 x},
f[x_] = r`outsideFormula;
Print@f@1(*works*);
g[x_] = insideFormula;
Print@g@1(*won't work*)
]
(*
1
2x
*)
When the formula defined outside the Module is used in the RHS of Set, it works upon successive evaluations as expected. However if a Module variable is used (insideFormula), it apparently remains unevaluated.
Why is this?
Print@DownValues@fto see what is going on and read avoiding-renamings to learn why – Kuba Jun 20 '22 at 10:482xbut forf[ x$_], notice$. – Kuba Jun 20 '22 at 11:03xis localized the Module in the second definition will renamex_tox$_making it different thanxfrom the RHS. That is explained in the topic linked in my first comment. – Kuba Jun 20 '22 at 11:20Global'complicatedNamehad a formula with symbols. I opened aModuleto evaluate it for different values of those symbols (instead of using /.symbol->value) and some other manipulations ...while doing all this, instead of rewriting everytime complicatedName, I thought I'll alias it inModulevars and that's when I found the difference. btw, yourx$explanation works – lineage Jun 20 '22 at 11:32