Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Bug in Pattern Matching with Condition?

  • To: mathgroup at
  • Subject: [mg97362] Re: Bug in Pattern Matching with Condition?
  • From: cesar <caguerra at>
  • Date: Thu, 12 Mar 2009 02:15:03 -0500 (EST)
  • References: <goqpe7$lrn$> <goqugt$ngp$>

On Mar 11, 10:23 am, Albert Retey <a... at> wrote:
> Hi,
> > can you elaborate a bit. According to the definition of Verbatim ,
> > Verbatim[Condition][_, _]] should match literally "Condition][_, _]" an=
> > not Condition[a, b].
> you need to be very carefully to where the Verbatim ends. I think
> everything is in order (this time even the documentation, although it is
> rather on the short side):
> Match the Condition-Head verbatim, but treat its arguments _,_ as a patte=
> In[6]:= MatchQ[Condition[a,b],Verbatim[Condition][_,_]]
> Out[6]= True
> Match the whole expression Condition[_,_] verbatim:
> In[7]:= MatchQ[Condition[a,b],Verbatim[Condition[_,_]]]
> Out[7]= False
> In[8]:= MatchQ[Condition[_,_],Verbatim[Condition[_,_]]]
> Out[8]= True
> > Therefore it looks more like  another bug to me and
> > adds to the mystery of why MatchQ[Condition[a, b], Condition[_, _]]
> > evaluates to False.
> I can see no bug and no mystery here. The problem is that patterns in
> Mathematica are built as Mathematica expressions just like everything
> else. If you want to match one of building blocks for
> pattern-expressions (or expressions containing them) verbatim, you need
> to wrap them with Verbatim, which seems rather straightforward once one
> has seen it. It's a little like the escape characters in string patterns
> that are unavoidable if you use strings to describe the patterns, as has
> been discussed in another thread.
> hth,
> albert

Finally, I think this is the point. It happens with all pattern
(I recently realize that Condition is a pattern ):

MatchQ[Pattern[a, b], HoldPattern[Pattern][_, _]]
MatchQ[Except[a], HoldPattern[Except][_]]

They give False if we apply HoldPattern to all the second argument.

I also realized that when doing pattern matching, patterns are
inside the kernel even with HoldComplete wraped around.

MatchQ[HoldComplete[Except[a]], HoldComplete[Except[_]]]

of course, if we just hold the head we prevent evaluation:

MatchQ[Hold[Except][a], Hold[Except][_]]

Cheers and thanks all you,

  • Prev by Date: Re: Re: Mathematica and some General Comments
  • Next by Date: Re: String substitution system
  • Previous by thread: Re: Bug in Pattern Matching with Condition?
  • Next by thread: Creating own typesetting palettes