The first example on the page for SequenceReplace is the following:
SequenceReplace[{a, b, x, x, a, c}, {a, e_} :> e]
(*b,x,x,c*)
Why do they use RuleDelayed here, instead of ->? I tried it with -> and got the same answer.
The first example on the page for SequenceReplace is the following:
SequenceReplace[{a, b, x, x, a, c}, {a, e_} :> e]
(*b,x,x,c*)
Why do they use RuleDelayed here, instead of ->? I tried it with -> and got the same answer.
I remember this was asked before, but can't find it now. i.e. when to use :> vs ->. As @thorimur mentions, it is related to when right side is evaluated.
If you have Wagner book, look at page 148, he gives a nice example showing when to use and what problem it can cause if you use -> instead of :>
This book is now free to download. Thanks to this post Are you interested in purchasing David Wagner's "Power programming with Mathematica"?
->,eis only bound bye_if it is present in the rhs after evaluation. So for example,e = 1; SequenceReplace[{a, b, x, x, a, c}, {a, e_} -> e]gets you{1, x, x, 1}. So it's good practice to use:>just in caseeis defined somewhere else, I think. – thorimur Sep 05 '21 at 19:24