WolframLang: Rule, RuleDelayed
A rule in WolframLang is a pair of values. It is used in:
- Rule is used as a find/replace pair for transformation of expressions, where the left-hand-side is a Pattern, and right-hand-side is replacement.
Rule is also used in:
- Rule is used to represent the key/value pairs in Association (Key Value Pairs).
- Rule is used to represent pairs of named parameter and its value (called options in WolframLang) for functions.
Rule[lhs, rhs]
-
🔸 SHORT SYNTAX:
lhs -> rhs
A pair of values, with left-hand-side lhs and right-hand-side rhs
Both lhs and rhs is evaluated at the time the rule is defined.
ReplaceAll[ {1, {2}, 3} , {x_} -> x+1] (* {1, 3, 3} *)
RuleDelayed[lhs, rhs]
-
🔸 SHORT SYNTAX:
lhs :> rhs
Same as
Rule
, but rhs is evaluated at the time the transformation happens.