MathGroup Archive 2009

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

Search the Archive

Re: Bug in Pattern Matching with Condition?

  • To: mathgroup at
  • Subject: [mg97335] Re: Bug in Pattern Matching with Condition?
  • From: Albert Retey <awnl at>
  • Date: Wed, 11 Mar 2009 04:23:24 -0500 (EST)
  • References: <goqpe7$lrn$> <goqugt$ngp$> <gp5fjl$9j8$>


> can you elaborate a bit. According to the definition of Verbatim , 
> Verbatim[Condition][_, _]] should match literally "Condition][_, _]" and 
> 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 pattern:

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.



  • Prev by Date: Re: Unexpected zoom when rotating Plot3D
  • Next by Date: Re: Mathematica and some General Comments
  • Previous by thread: Re: Re: Bug in Pattern Matching with Condition?
  • Next by thread: Re: Bug in Pattern Matching with Condition?