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: [mg97331] Re: [mg97279] Re: Bug in Pattern Matching with Condition?
  • From: dh <dh at metrohm.com>
  • Date: Wed, 11 Mar 2009 04:22:38 -0500 (EST)
  • References: <goqpe7$lrn$1@smc.vnet.net> <goqugt$ngp$1@smc.vnet.net> <200903101032.FAA09839@smc.vnet.net> <1F28FF59-BB99-48DE-8C96-7D7D0393FB5B@mimuw.edu.pl> <49B68279.9000305@metrohm.com> <7B9EB166-BC9D-4E69-BF73-BCE2B3B5C43C@mimuw.edu.pl>

I agree, thanks again, Daniel

Andrzej Kozlowski wrote:
> Well, I can't answer this with any certainly but it seems to me 
> reasonable that  _/;True should match anything just as _ does and that 
> _/;False should not match anything. It seems logical that if you agree 
> with that than you get "strange" behaviour as below:
> 
> MatchQ[a /; False, _ /; False]
> False
> 
> MatchQ[a /; False, _ /; True]
> True
> 
> It's not really an explanation but it does make sense (to me) so I would 
> say it is a feature.
> 
> Andrzej
> 
> 
> 
> On 10 Mar 2009, at 16:08, dh wrote:
> 
>> Thanks Andrzej. But this still does not explain why "Condition" acts 
>> so strangely. Is it a bug or feature?
>> Daniel
>>
>> Andrzej Kozlowski wrote:
>>> 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
>>>>
>>>>>>
>>>>
>>>>>
>>>>
>>>>
>>>>
>>
>>
>> -- 
>>
>> Daniel Huber
>> Metrohm Ltd.
>> Oberdorfstr. 68
>> CH-9100 Herisau
>> Tel. +41 71 353 8585, Fax +41 71 353 8907
>> E-Mail:<mailto:dh at metrohm.com>
>> Internet:<http://www.metrohm.com>
>>
> 
> 
> 
> 


-- 

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:dh at metrohm.com>
Internet:<http://www.metrohm.com>



  • Prev by Date: Share symbols among packages
  • Next by Date: Re: Re: Notebook that auto-executes when opened?
  • Previous by thread: Re: Re: Bug in Pattern Matching with Condition?
  • Next by thread: Re: Bug in Pattern Matching with Condition?