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. $\endgroup$ – Mariano Suárez-Álvarez Sep 21 '17 at 17:10w[x : (Times|ThisWillNeverMatch)[xs__]] := {x, xs}
does do the trick (andThisWillNeverMatch
can be meaningfully replaced byExcept[_]
, I guess) $\endgroup$ – Mariano Suárez-Álvarez Sep 21 '17 at 17:20Times[xs__]
immediately evaluates toSequence[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
. $\endgroup$ – march Sep 21 '17 at 17:27