Bug introduced 8.0 or earlier and persisting through 11.0 [CASE:3631078]
In Mathematica 8 and 9, defining this rule:
rule =
func[a | b, c_][PatternSequence[x_, z_] | PatternSequence[{x_}, z_]] :> {c, x, z}
leads to Pattern::patvar
error messages. But it seems to apply correctly:
func[a, 2][1, 3] /. rule
(* {2, 1, 3} *)
In Mathematica 10, defining the rule works without error messages, but applying the rule gives Pattern::patvar
error messages, although it returns the correct result.
I think I'm doing something wrong in making this pattern. Question: What is the correct way to construct it without getting error messages?
By the way, changing the c_
to a _
in rule
makes the error go away:
rule =
func[a | b, _][PatternSequence[x_, z_] | PatternSequence[{x_}, z_]] :> {c, x, z}
But I need the c
in the LHS because it appears in the RHS.
By the way #2, if I use this pattern:
rule = func[var : PatternSequence[a | b, c_]][
PatternSequence[x_, z_] | PatternSequence[{x_}, z_]] :> {c, x, z}
General::mbox
errors are generated. In Mathematica 10, the error messages reveal that c_
is getting internally converted to Pattern[1,_]
HELP!
EDIT
I just realized that I can define the rule like this without problems:
rule = func[a | b, c_][{x_}|x_, z_] :> {c, x, z}
But this is an unfortunate case of stripping down too much from my real case which has variable number of arguments on each side of the Alternatives
, like this:
rule =
func[a | b, c_][PatternSequence[x_, z_] | PatternSequence[{x_, z_}]] :> {c, x, z}
This still leads to Pattern::patvar
error messages.
patvar
messages also only appear on the first/.
, not subsequent ones (OS X 10.11.5, MMA 10.0.2.0)... $\endgroup$PatternSequence[ ...] | PatternSequence[ ... ]
part, and that it's actually one ofPatternSequence[x_, z_]
orPatternSequence[{x_}, z_]
that's getting converted toPattern[1,_]
. $\endgroup$c_
is replaced by_
while thePatternSequence
-stuff is the same? $\endgroup$func[a | b, c_] :> ...
, there's no problem. There's some strange interaction going on here. $\endgroup$