WolframLang: Rule
A rule in WolframLang is a pair of values. It is used in:
- Rule is used to represent the key/value pairs in Association (Key Value Pairs)
- Rule is used to represent named parameters (called options in WolframLang) for functions.
- 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 what it should be changed to.
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.
RuleReplaceAll[ {a, b, c} , x_ -> x+1] === {1 + a, 1 + b, 1 + c}
RuleDelayed[lhs,rhs]
- (Short syntax:
lhs :> rhs
)
Same as
RuleDelayedRule
, but rhs is evaluated at the time the transformation happens.