Message Boards Message Boards

0
|
4826 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Pattern replacement rule - how to eliminate extra step

Posted 11 years ago
This one should be fairly easy for any Mathematica programmer:

I have

GP = GeoPoint[Name_, {East_Real, North_Real}, Elev_Real];
GP // FullForm


and need to get rid of al the patterns in order to use the expression on the rhs

This works:

GP /. Pattern -> axa
% /. axa[n_, _] -> n


and produces the desired output:
GeoPoint[Name, {East, North}, Elev]


Now - how do I get rid of the extra step?
The problem is that Mathematica is evaluating the Pattern and I don't know how to tell it not to do so - I can't figure out how to use any of the Hold, HoldPattern, HoldAll, HoldComplete etc constructs
POSTED BY: Todor Latev
3 Replies
Wrapping the pattern expression head Pattern in Verbatim is the type of hold you are looking for.
In[ ]:= GP /. Verbatim[Pattern][p_, _] :> p

Out[ ]= GeoPoint[Name, {East, North}, Elev]
Posted 11 years ago
Merci Iliane! Super e!
POSTED BY: Todor Latev
How about
In[4]:= GP /. p_Pattern :> First[p]

Out[4]= GeoPoint[Name, {East, North}, Elev]
POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract