({{, lhs:>rhs or lhs:>rhs
represents a rule that transforms lhs to rhs, evaluating rhs only after the rule is used. }})

OpenersNotesSection(Spacer1)Details

The character :> can be entered as (Key0[esc]) :> (Key0[esc]) or ∖[RuleDelayed].

(RefLink[RuleDelayed, paclet:ref/RuleDelayed]) has the attribute (RefLink[HoldRest, paclet:ref/HoldRest]).

You can apply rules using (RefLink[Replace, paclet:ref/Replace]).

The assignment lhs:=rhs specifies that the rule lhs:>rhs should be used whenever it applies.

You can use (RefLink[Condition, paclet:ref/Condition]) to specify when a particular rule applies.

In (RefLink[StandardForm, paclet:ref/StandardForm]), (RefLink[RuleDelayed, paclet:ref/RuleDelayed]) is printed using :>.

OpenersPrimaryExamplesSection(Spacer1)Examples  (10)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

:> holds its right-hand side unevaluated:

x:>RandomReal[]

The right-hand side is evaluated separately each time it is used:

{x,x,x}/.x:>RandomReal[]

OpenersExampleSection1(Spacer1)Applications  (3)

Increment n each time x is replaced:

n=1;{x,x,a,b,x,x,c,d}/.x:>n++

Evaluate the (RefLink[StepMonitor, paclet:ref/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}]//MatrixForm

OpenersExampleSection2(Spacer1)Properties & Relations  (6)

-> evaluates when it is first entered; :> when it is used:

{x,x,x,x}/.x->RandomReal[]

{x,x,x,x}/.x:>RandomReal[]

(RefLink[Module, paclet:ref/Module]) and (RefLink[With, paclet:ref/With]) do not affect local variables of (RefLink[RuleDelayed, paclet:ref/RuleDelayed]):

With[{x=1},a/.x_:>x+1]

(RefLink[Module, paclet:ref/Module]) effectively uses a renamed instance of y:

{incr[x],incr[y]}/.incr[x_]:>Module[{y=1},x+y]

By evaluating the arguments to (RefLink[RuleDelayed, paclet:ref/RuleDelayed]), local scoping is avoided:

Module[{expr=x^2},a/.RuleDelayed@@{x_,expr}]

(RefLink[KeyValuePattern, paclet:ref/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]}]

(RefLink[KeyValuePattern, paclet:ref/KeyValuePattern]) distinguishes between (RefLink[Rule, paclet:ref/Rule]) and (RefLink[RuleDelayed, paclet:ref/RuleDelayed]):

Replace[{a:>1,b:>2,c:>3},KeyValuePattern[{a->x_,c->y_}]->{a:>f[x],c:>g[y]}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Rule, paclet:ref/Rule])  ▪  (RefLink[Replace, paclet:ref/Replace])  ▪  (RefLink[SetDelayed, paclet:ref/SetDelayed])  ▪  (RefLink[Keys, paclet:ref/Keys])  ▪  (RefLink[Values, paclet:ref/Values])  ▪  (RefLink[Association, paclet:ref/Association])  ▪  (RefLink[KeyValuePattern, paclet:ref/KeyValuePattern])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Applying Transformation Rules, paclet:tutorial/ApplyingTransformationRules])}, {▪(RefLinkPlain[Some General Notations and Conventions, paclet:tutorial/SomeGeneralNotationsAndConventions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Programmable Linguistic Interface, paclet:guide/ProgrammableLinguisticInterface])}, {▪(RefLinkPlain[Wolfram Language Syntax, paclet:guide/Syntax])}, {▪(RefLinkPlain[Scoping Constructs, paclet:guide/ScopingConstructs])}, {▪(RefLinkPlain[Rules, paclet:guide/Rules])}, {▪(RefLinkPlain[Language Overview, paclet:guide/LanguageOverview])}, {▪(RefLinkPlain[Options Management, paclet:guide/OptionsManagement])}, {▪(RefLinkPlain[Rules & Patterns, paclet:guide/RulesAndPatterns])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-FastIntro.png(Spacer1)Fast Introduction for Programmers: Patterns, http://www.wolfram.com/language/fast-introduction-for-programmers/patterns/])}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/39-immediate-and-delayed-values.html])(WebLink[: Immediate and Delayed Values, https://www.wolfram.com/language/elementary-introduction/39-immediate-and-delayed-values.html])}})}})