Can anyone provide insight on what's going on here?
First I define a new Set
behavior for a symbol:
mySym /: Set[mySym[f_], v_] := v
mySym[1] = 2
(* Out *) 2
mySym[1]
(* Out *) mySym[1]
Works great
But if we provide an alias for this symbol the UpValues
never get called:
ms = mySym;
ms[1] = 2
(* Out *) 2
mySym[1]
(* Out *) 2
Even more, if we pre-Evaluate
that ms
we still have an issue:
Evaluate[ms][1] = 3
(* Out *) 3
mySym[1]
(* Out *) 3
Although With
does the appropriate thing:
With[{m = ms},
m[1] = 4
]
(* Out *) 4
mySym[1]
(* Out *) 3
What's the cause of that? It's single-handedly nixed an OO implementation I was working on.
Evaluate
is too deep inSet
to work, isn''t it? $\endgroup$Evaluate@Symbol["sym"][1] = 1
which is what made me think the other should work. $\endgroup$