Unevaluated
is a function that I never truly understand, and here's one of the cases confusing me:
Unevaluated[1 + 1] -> 3
(* 2 -> 3 *)
Same thing happens on right side of Rule
and left side of RuleDelayed (:>)
i.e. Unevaluated
affects none of the unheld sides of Rule
/RuleDelayed
:
2 -> Unevaluated[1 + 2]
(* 2 -> 3 *)
Unevaluated[1 + 1] :> 3
(* 2 :> 3 *)
Trace
shows that Unevaluated
does seem to work for once, but after that,Rule
evaluates its left side again:
Unevaluated[1 + 1] -> 3 // Trace
No matter how many Unevaluated
exists, Rule
will tenaciously evaluate again and again, until the Unevaluated
s are all killed:
Unevaluated@Unevaluated@Unevaluated@Unevaluated[1 + 1] -> 3 // Trace
My questions are:
Is this just a individual case i.e. a special behavior of
Rule
/RuleDelayed
, or there's a class of function that shares the same behavior?Why
Rule
/RuleDelayed
is designed to behave like this? Is there any deep meaning?
Unevaluated
is only kept untilRule
recieves its arguments (as the documentation states), but afterwards arguments are evaluated normally asRule
does not have attributeHoldAll
or similar. Compare withf[x_] := x;f[Unevaluated[1 + 1]]
which also returns 2. $\endgroup$f[Unevaluated@Unevaluated[1 + 1]]
will returnUnevaluated[1 + 1]
. $\endgroup$Replace
family. Furthermore,Association
behaves similar (whileDirectedEdge
does not) $\endgroup$