|
[Date Index]
[Thread Index]
[Author Index]
RE: [Q] Extracting patterns
- To: mathgroup at smc.vnet.net
- Subject: [mg18652] RE: [mg18607] [Q] Extracting patterns
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Thu, 15 Jul 1999 01:45:44 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Kevin, Use Vebatim.
You should also use :> instead of -> in this case (see below).
--------------------------------------
In[1]:=
Pattern[x, y] /. Verbatim[Pattern][a_, b_] -> a
Out[1]=
x
In[2]:=
a=47;
.....
.....
You do a lot of work, and forget (a) has a value.
.....
In[164]:=
Pattern[x, y] /. Verbatim[Pattern][a_, b_] -> a
Out[164]=
47
In[165]:=
Pattern[x, y] /. Verbatim[Pattern][a_, b_] :> a
Out[165]=
x
At Out[164] you don't get what you want. Use :> and you get what you want
no mater what vale (a) might have.
In general don't use (lhs->rhs) when (lhs) has a named pattern and the name
of the pattern is used in (rhs). Instead use (lhs:>rhs).
Regards,
Ted Ersek
-----Original Message-----
From: kj0 at mailcity.com
To: mathgroup at smc.vnet.net
Subject: [mg18652] [mg18607] [Q] Extracting patterns
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
Prev by Date:
RE: Binary System Problem
Next by Date:
Re: [Q] Extracting patterns
Previous by thread:
Re: [Q] Extracting patterns
Next by thread:
Re: [Q] Extracting patterns
|