The documentation on RuleDelayed
states that lhs :> rhs represents a rule that transforms lhs to rhs, evaluating rhs only after the rule is used.
Consider the following rule:
a/;condition :> (condition=False; RandomReal[])
When this rule is used, it sets the variable condition
to False
, and therefore the lefthand side of the rule cannot be matched any more. So I expected that in the following command only the first symbol a
would be replaced by a real number.
condition=True;
{a,a,a} /. a/;condition :> (condition=False; RandomReal[])
(* {0.420057,0.183578,0.751358} *)
But all three are replaced, so the rule is used three times. What is going on here?