# A pattern involving Times

If I define (this is 10.0.0.0)

w[x : Times[xs__]] := {x, xs}
w[x : h[xs__]] := {x, xs}


Definition[w] gives me

w[x : h[xs__]] := {x, xs}
w[x : xs__] := {x, xs}


and the Times got lost. The two equations got reversed —because the one involving the Times did not see it and is more general than the other.

Is this expected behaviour? The second equation given by Definition definitely does something difference from my first equation, as xs matches the product and not the sequence of its factors.

My guess is this comes from Times being Flat. How does one do what the above definition tried to do?

• w[x_Times] := {x, Sequence @@ x} does seem to work. – Mariano Suárez-Álvarez Sep 21 '17 at 17:10
• Similarly, something like w[x : (Times|ThisWillNeverMatch)[xs__]] := {x, xs} does do the trick (and ThisWillNeverMatch can be meaningfully replaced by Except[_], I guess) – Mariano Suárez-Álvarez Sep 21 '17 at 17:20
• Times[xs__] immediately evaluates to Sequence[xs]. Try this: Clear@w; w[x : HoldPattern[Times[xs__]]] := {x, xs}; w[x : h[xs__]] := {x, xs} or this: Clear@w; SetAttributes[w, HoldAll]; w[x : Times[xs__]] := {x, xs}; w[x : h[xs__]] := {x, xs}. In either case, then do ?w. – march Sep 21 '17 at 17:27
• Why is the pattern evaluated? – Mariano Suárez-Álvarez Sep 21 '17 at 17:31
• I don't remember! – march Sep 21 '17 at 17:36

## 1 Answer

Consider

Clear[w]
w[x : HoldPattern[Times[xs__]]] := {x, xs}
Definition @ w


w[x : HoldPattern[Times[xs__]]] := {x, xs}

w[a b c]

{a b c, a, b, c}

Does this approach work for you?