MathGroup Archive 1998

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

Search the Archive

Re: Previous variable affects "/."



Vilis Nams wrote:
> 
> I am using "/." to change expressions, as follows:
> 
> In[1]:= = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; In[2]:= a /. {x_,
> y_} -> {x}
> Out[2]:={1}, {3}, {5}, {7}}
> The results are expected.
> 
> But, if I now define x to be something already, e.g. In[3]:= = 7;
> 
> Then, when I do the Replace, Mathematica uses my previously-defined x, as follows:
> 
> In[4]:= /. {x_, y_} -> {x}
> Out[4]:={7}, {7}, {7}, {7}}

Vilis
Usse :> instead of ->

In[1]:=
x = 7;
{{1, 2}, {3, 4}, {5, 6}, {7, 8}}; /. {x_, y_} :> {x}

Out[1]=
{{1},{3},{5},{7}}

-- 
Allan Hayes
Mathematica Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642




  • Prev by Date: Re: algebraic solutions
  • Next by Date: Re: combining graphics
  • Prev by thread: Re: Previous variable affects "/."
  • Next by thread: replacement rules in packages