Some of the big mysteries of Universe Mathematica for me is the application of UpValues.
I know about this question and know the very poor Mathematica documentation on that. I'm very curious to know if someone that not @Leonid uses this too.
Just to get some clue on how it works, I would like to know what's the difference between TagSet
and UpSet
. Can I say that UpSet
is subset of TagSet
?
For instance, I can say these examples are equivalent.
name[alien]^= "Alf"
alien /: name[alien] = "Alf"
In what situations should I apply each case?
UpValues
in general. $\endgroup$UpSet
vsTagSet
- the only practical difference I am aware of is thatTagSet
is more precise, and will only add anUpValue
to a symbol you specify, whileUpSet
will addUpValues
for all symbols at the first level in the l.h.s. of the rule. Re: email change - the funny this is, I didn't change it! Apparently, SE changed the algorithm they use to compute at least some gravatars. I've noticed it and some other users seem to have been affected by it as well (although not all, it seems). $\endgroup$ClearAll[a, b, c, d]; f[a, b, c] ^= d;
, all of thea,b,c
getUpValues
, whereas when you executeClearAll[a, b, c, d]; a /: f[a, b, c] = d;
, onlya
does. With more complicated patterns involving blanks, it may matter. Generally, you want to be as precise as possible, to not produce extra global rules besides those you need, because they may fire in unforeseen situations. Actually, we pay for locality of overloading based onUpValues
with making it harder to see why a given rule fired. No reason to make it harder still. $\endgroup$