Re: Bug in Pattern Matching with Condition?
- To: mathgroup at smc.vnet.net
- Subject: [mg97335] Re: Bug in Pattern Matching with Condition?
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Wed, 11 Mar 2009 04:23:24 -0500 (EST)
- References: <goqpe7$lrn$1@smc.vnet.net> <goqugt$ngp$1@smc.vnet.net> <gp5fjl$9j8$1@smc.vnet.net>
Hi, > 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. hth, albert