Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Re: Bug in Pattern Matching with Condition?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97323] Re: [mg97279] Re: Bug in Pattern Matching with Condition?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Wed, 11 Mar 2009 04:21:10 -0500 (EST)
  • References: <goqpe7$lrn$1@smc.vnet.net> <goqugt$ngp$1@smc.vnet.net> <200903101032.FAA09839@smc.vnet.net>

No, the Varbatim is wrapped around the Head, Condition not around the  
entire expression. You can do it also with HoldPattern:

MatchQ[a /; b, HoldPattern[Condition][_, _]]
True

Once you hold the Head of the pattern expression it no longer has its  
special meaning. You can check that Condition behaves is a very  
special way  when used in a pattern, e.g.



MatchQ[x, Condition[_, True]]
True

MatchQ[x, Condition[_, False]]
False

Of course if you replace Condition by Verbatim[Condition] or  
HoldPattern[Condition] you will always get False.


Andrzej Kozlowski


On 10 Mar 2009, at 11:32, dh wrote:

>
>
> Hi Jens,
>
> can you elaborate a bit. According to the definition of Verbatim ,
>
> Verbatim[Condition][_, _]] should match literally "Condition][_, _]"  
> and
>
> not Condition[a, b]. Therefore it looks more like  another bug to me  
> and
>
> adds to the mystery of why MatchQ[Condition[a, b], Condition[_, _]]
>
> evaluates to False.
>
> Daniel
>
>
>
> Jens-Peer Kuska wrote:
>
>> Hi,
>
>>
>
>> but
>
>>
>
>> MatchQ[Condition[a, b], Verbatim[Condition][_, _]]
>
>>
>
>> Regards
>
>>   Jens
>
>>
>
>> cesar wrote:
>
>>> Hi Mathematica group, do you get any idea of
>
>>> why the following sentences don't give true?
>
>>>
>
>>> MatchQ[Condition[a, b], Condition[_,_]]
>
>>> MatchQ[Condition[a, b], Condition[__]]
>
>>> MatchQ[Condition[a, b], HoldPattern[Condition[__]]]
>
>>>
>
>>> Is this a bug?
>
>>>
>
>>> Cheers,
>
>>> Cesar
>
>>>
>
>>
>
>
>



  • Prev by Date: Re: MatrixRank[m, Modulus -> 5] is broken
  • Next by Date: Re: Notebook that auto-executes when opened?
  • Previous by thread: Re: Bug in Pattern Matching with Condition?
  • Next by thread: Re: Re: Bug in Pattern Matching with Condition?