Group Abstract Group Abstract

Message Boards Message Boards

Pattern replacement rule - how to eliminate extra step

GROUPS:
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
Answer
11 months ago
How about
In[4]:= GP /. p_Pattern :> First[p]

Out[4]= GeoPoint[Name, {East, North}, Elev]
POSTED BY: Ilian Gachevski
Answer
11 months ago
Merci Iliane! Super e!
POSTED BY: Todor Latev
Answer
11 months ago
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 BY: Christopher French
Answer
11 months ago