Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

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


  • Prev by Date: An operator called-- LocalSet
  • Next by Date: Re: MacOS vs. Windows PC for Mathematica?
  • Previous by thread: An operator called-- LocalRule
  • Next by thread: A Most Annoying Problem