Bug introduced 8.0 or earlier and persisting through 10.4.1 [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.