lhs:>rhs or lhsrhs
represents a rule that transforms lhs to rhs, evaluating rhs only after the rule is used.
RuleDelayed 
lhs:>rhs or lhsrhs
represents a rule that transforms lhs to rhs, evaluating rhs only after the rule is used.
Details
- The character can be entered as
:>
or ∖[RuleDelayed]. - RuleDelayed has the attribute HoldRest.
- You can apply rules using Replace.
- The assignment lhs:=rhs specifies that the rule lhs:>rhs should be used whenever it applies.
- You can use Condition to specify when a particular rule applies.
- In StandardForm, RuleDelayed is printed using .
Examples
open all close allBasic Examples (1)
Applications (3)
Increment n each time x is replaced:
n = 1;{x, x, a, b, x, x, c, d} /. x :> n++Evaluate the StepMonitor expression separately each time it is to be used:
FindRoot[Cos[x] == x, {x, 1}, StepMonitor :> Print[x]]Generate a diagonal matrix with random elements:
SparseArray[{{i_, i_} :> RandomReal[]}, {4, 4}]//MatrixFormProperties & Relations (6)
-> evaluates when it is first entered; :> when it is used:
{x, x, x, x} /. x -> RandomReal[]{x, x, x, x} /. x :> RandomReal[]Module and With do not affect local variables of RuleDelayed:
With[{x = 1}, a /. x_ :> x + 1]Module effectively uses a renamed instance of y:
{incr[x], incr[y]} /. incr[x_] :> Module[{y = 1}, x + y]By evaluating the arguments to RuleDelayed, local scoping is avoided:
Module[{expr = x ^ 2}, a /. RuleDelayed@@{x_, expr}]KeyValuePattern can be used to transform a list of rules:
Replace[{a :> 1, b :> 2, c :> 3}, KeyValuePattern[{a :> x_, c :> y_}] -> {a :> f[x], c :> g[y]}]KeyValuePattern distinguishes between Rule and RuleDelayed:
Replace[{a :> 1, b :> 2, c :> 3}, KeyValuePattern[{a -> x_, c -> y_}] -> {a :> f[x], c :> g[y]}]Related Guides
History
Introduced in 1988 (1.0) | Updated in 1996 (3.0)
Text
Wolfram Research (1988), RuleDelayed, Wolfram Language function, https://reference.wolfram.com/language/ref/RuleDelayed.html (updated 1996).
CMS
Wolfram Language. 1988. "RuleDelayed." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/RuleDelayed.html.
APA
Wolfram Language. (1988). RuleDelayed. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RuleDelayed.html
BibTeX
@misc{reference.wolfram_2026_ruledelayed, author="Wolfram Research", title="{RuleDelayed}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/RuleDelayed.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_ruledelayed, organization={Wolfram Research}, title={RuleDelayed}, year={1996}, url={https://reference.wolfram.com/language/ref/RuleDelayed.html}, note=[Accessed: 12-June-2026]}