# 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. Sep 21, 2017 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) Sep 21, 2017 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. Sep 21, 2017 at 17:27
• Why is the pattern evaluated? Sep 21, 2017 at 17:31
• I don't remember! Sep 21, 2017 at 17:36

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?

• Yup. This this what I ended up doing. Sep 22, 2017 at 17:00