Tutorial by Examples

Example of how ReplaceAll only applies a rule at most once, while ReplaceRepeated will do so in a loop but always restart application from the first rule. x + a /. { a_ + z :> (Print[0]; DoneA), a_ + x :> (Print[1]; y + z), a_ + y :> (Print[2]; DoneB)} (* Prints "1&quot...
Bubble sorting with rules and replacements: list = {1, 4, 2, 3, 6, 7, 8, 0, 1, 2, 5, 4} list //. {fsts___, x_, y_, lsts___} :> {fsts, y, x, lsts} /; y < x (* Out[1] := {1, 4, 2, 3, 6, 7, 8, 0, 1, 2, 5, 4} Out[1] := {0, 1, 1, 2, 2, 3, 4, 4, 5, 6, 7, 8} *)

Page 1 of 1