Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > Rules & Patterns > Rules >

RuleDelayed

lhs:>rhs or lhsRuleDelayedrhs
represents a rule that transforms lhs to rhs, evaluating rhs only after the rule is used.
  • 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.
:> holds its right-hand side unevaluated:
The right-hand side is evaluated separately each time it is used:
:> holds its right-hand side unevaluated:
In[1]:=
Click for copyable input
Out[1]=
The right-hand side is evaluated separately each time it is used:
In[2]:=
Click for copyable input
Out[2]=
Increment n each time x is replaced:
Evaluate the StepMonitor expression separately each time it is to be used:
Generate a diagonal matrix with random elements:
-> evaluates when it is first entered; :> when it is used:
Module and With do not affect local variables of RuleDelayed:
Module effectively uses a renamed instance of y:
By evaluating the arguments to RuleDelayed, local scoping is avoided:
New in 1 | Last modified in 3
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team