Given a list of patterns {x, y, z} I want a pattern that matches if and only if each pattern matches. If instead of getting the intersection of patterns I wanted the union of patterns I could use Alternatives.
I managed to write the following. Is there a better alternative?
Except[Alternatives @@ Map[Except, {x, y, z}]]
MatchQ[Pi+1,Except[Except[a_?NumericQ],b_Plus]]and gotExcept::named: "Named pattern variables are not allowed in the first argument of Except[a_?NumericQ]."– Bruno Le Floch May 30 '16 at 19:38fwhich defaults toHoldand takes special values when several patterns (with named variables) match simultaneously), I can definef[a_]:=g[a,a]andg[a:pattern1, a:pattern2]:=valuewhich will only match if the argument matches bothpattern1andpattern2, but it looks somewhat ugly (and slow?). – Bruno Le Floch May 30 '16 at 19:44MatchQ[Pi + 1, Except[Except[a_?NumericQ], b_Plus]], butTrue. – Rolf Mertig May 30 '16 at 19:51Andfor patterns using only the pattern-matcher, and not using the evaluator (Condition,PatternTest, etc.). If we formulate it this way, then I don't see any other option except double -Except(pun intended). – Leonid Shifrin May 30 '16 at 20:00Exceptby Simon Rochester. Right now I'm trying to cook up some code that will allow rule-replacement, i.e. such thatx/.AndRuleDelayed[{patt1,patt2},replacement]is equivalent to{x,x}/.{patt1,patt2}:>replacementwhen both patterns match, and the replacement is allowed to involve named subpatterns from bothpatt1andpatt2. Not sure where I should post that code. – Bruno Le Floch May 30 '16 at 20:06