RE: An operator called-- LocalRule
- To: mathgroup at smc.vnet.net
- Subject: [mg13836] RE: An operator called-- LocalRule
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Sat, 29 Aug 1998 04:41:14 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Allan Hayes had two remarks;
|
|The last Hold seems not to be needed - and Cases needs the option
|Heads->True:
|
|
Allan,
When you modified my program you took out the part If[q==={}, ........]
Without that the program doesn't work right when the left hand side has
no patterns. I think the code below incorporates you suggestions
without problem.
In[1]:=
LocalRule=RightArrow;
SetAttributes[RightArrow,HoldRest];
RightArrow[lhs_,rhs_]:=Module[{q},
q=Cases[lhs,_Pattern,{0,Infinity}, Heads->True];
If[q==={},(lhs:>Evaluate at rhs),(
q=Extract[#,1,Hold]& /@q;
q=Thread[q,Hold];
Block@@Join[q,Hold[lhs:>Evaluate at rhs] ] )]]
________________
Now the following will work.
In[2]:=
Clear[expr,x,a];
In[3]:=
LocalRule[expr,x+a^2]
Out[3]=
expr :> x+a^2
_______________
Ted