Re: [Q] Extracting patterns
- To: mathgroup at smc.vnet.net
- Subject: [mg18724] Re: [Q] Extracting patterns
- From: dreeves at flip.eecs.umich.edu (Daniel Reeves)
- Date: Sat, 17 Jul 1999 02:36:43 -0400
- References: <7meikl$9gj@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
If you have a list, you can get the first element with Part or First.
Like {x, y}[[1]]
But {x, y} is really List[x, y] and it turns out there's nothing special
about the head List.
You can get the first element from other things the same way, eg,
Pattern[x, y][[1]]
-- -- -- -- -- -- -- -- -- -- -- --
Daniel Reeves http://ai.eecs.umich.edu/people/dreeves/
It's not enough to be Hungarian; you must have talent too.
-- Alexander Korda
On 13 Jul 1999, Kevin Jaffe wrote:
>
>
> How can I extract the first argument of expressions having the form
> Pattern[x, y]? I know how to do something like this in other
> situations, e.g.:
>
>
> In[1]:= Plus[x, y] /. Plus[a_, b_] -> a
>
> Out[1]= x
>
>
> But this strategy fails when the head of the lhs expression is Pattern:
>
> In[2]:= Pattern[x, y] /. Pattern[a_, b_] -> a
>
> Pattern::patsym: First element in pattern Pattern[a_, b_] is not a symbol.
>
> Out[2]= x:y
>
>
> In a last-gasp effort, I also tried:
>
> In[3]:= Pattern[x, y] /. HoldPattern[Pattern[a_, b_]] -> a
>
> Pattern::patsym: First element in pattern Pattern[a_, b_] is not a symbol.
>
> Out[3]= x:y
>
> to no avail. Is there a way to do this?
>
> Thanks,
>
> kj0 at mailcity.com
>
>
>
> Get your FREE Email at http://mailcity.lycos.com
> Get your PERSONALIZED START PAGE at http://my.lycos.com
> .
>