Reading Ted Ersek's trickpage I stumbled upon the following problem:
http://www.verbeia.com/mathematica/tips/HTMLLinks/Tricks_P-Z_19.html (last example)
Clear[g,h];
g = h;
h[2] = 9;
{g[2], h[2]}
(* {9,9} *)
my question: is it possible to prevent g[2] to evaluate to a different value rather than h[2] and eventually 9. Furthermore can we assign g[2] different values?
My own tries led me to come up with the use of TagSet:
g/: HoldForm[g[2]] = 0;
SetAttributes[wrapper,HoldAll];
wrapper[x_]:= HoldForm@x;
Now with these definitions i can in a round-about way display different value for wrapper[g[2]]
{wrapper[g[2]], g[2]}
(* {0,9} *)
To change value I still need to use TagSet as shown below:
g/: HoldForm[g[2]] = 1;
{wrapper[g[2]], g[2]}
(* {1,9} *)
Reiterating, this is indeed a circular way to overcome the problem. Is there a better way to prevent g[2] to evaluate to h[2]?