I am unclear about the OwnValues for Set and SetDelayed.
Remove["Global`*"]
ySet = a; ySetDelayed := b;
{OwnValues[ySet], OwnValues[ySetDelayed]}
Out[10]= {{HoldPattern[ySet] :> a}, {HoldPattern[ySetDelayed] :> b}}
Let me clarify why using :>
seems strange to me.
The Wofram documentation for "How to | Create and Use Rules" says
In[11]:= x -> 3
Out[11]= x -> 3
By looking at the output for
x->3
, you can see that this rule does not do anything: the output is simply the rule itself. This is because rules do not do anything when they are alone. You must use a rule with an expression for it to be of any use.
Since Rules like
->
and:>
are used with/.
, why do they appear inOwnValues
sinceOwnValues
has to do with definitions? There must be some implied assumption for using them.Why does it store them as
RuleDelayed (:>)
for bothSet
andSetDelayed
?For
ySet = a;
, why is it{HoldPattern[ySet] :> a}
rather than{HoldPattern[ySet] -> a}
?
There is a discuss of this issue at "Question on Definition and values of symbols", but no one seems to know.
Why do I care? To properly understand and program Mathematica, one needs to understand the evaluation process. verbeia.com has a detailed granular outline of "The Evaluation Process" which is more detailed than the Wolfram documentation. Knowing how definitions are processed is important so knowing how Rule and RuleDelayed fit into the picture is necessary.
Replace
andReplaceAll
during evaluation. All the other functionality (like the concept ofFunction
) is emulated from this basic principle. $\endgroup$ – Henrik Schumacher Jan 3 '18 at 23:05