Because of "Thou shalt not copypaste", I'd like to change my pair of replacements
F[foo_,foo_+1]:=bar;F[foo_,foo_-1]:=bar;
(it's MUCH longer, so it actually saves :-) to something like this:
If[Abs[foo_-fooo_]==1,F[foo_,fooo_]:=bar];
Alas, If doesn't work that way...
Bonus points if the Abs condition holds in a whole larger block because then I can reuse it for more F[] replacement rules. (I tried With, but that didn't work as expected either.)
Condition
. $\endgroup$Condition
is a quick way out:F[foo_, bar_] /; Abs[foo - bar] == 1 := replacement
. I don't understand your bonus question though. Perhaps a less-minimal example is needed? $\endgroup$Condition
and I also don't understand your bonus-question. I'm going to close this as a duplicate to the post Marco mentioned. If you still have problems after reading the documentation, please feel free to edit your question and make clear what you try to achieve and why it doesn't work. $\endgroup$