MathGroup Archive 2011

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

Search the Archive

Re: Problem combining patterns

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119291] Re: Problem combining patterns
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Sun, 29 May 2011 07:37:01 -0400 (EDT)
  • References: <irqlng$e7i$1@smc.vnet.net>

On 28/05/2011 12:19, Leonid Shifrin wrote:
> You can do
>
> ClassPattern[] := _?(Length[#] === 1&);
>
> or
>
> ClassPattern[] := _ [ _ ]
>
> Regards,
> Leonid
>
>
> On Fri, May 27, 2011 at 2:12 PM, Rui<rui.rojo at gmail.com>  wrote:
>
>> Hey people.
>> I want to have an expression that evaluates to a pattern. Imagine
>> something simple
>>
>> ClassPattern[]:=HoldPattern[i_/;Length[i]===1];
>> So far so good. But then I'd like to use it in compound expressions
>> like
>>
>> MatchQ[{b[3], c[5]}, {ClassPattern[], ClassPattern[]}]
>>
>> When I do so, the label "i" inside the pattern is treated as the same
>> in both ClassPatterns, so I get false. But I wanna get True in cases
>> like the one before
>>
>> Any ideas?
>>
>>
I think that ClassPattern may be a cut down example, and naming the 
pattern variables may be useful in the real problem, so how about:

ClassPattern[] :=Module[{pp}, HoldPattern[i_ /; Length[i] === 1] /. i -> pp]

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Simple question: is it possible to take a derivative and solve for x ?
  • Next by Date: Re: how to calculate an index and vice versa
  • Previous by thread: Re: Problem combining patterns
  • Next by thread: Trouble Constructing Continuous Wavelet Transform in Mathematica 8