Re: How to change the argument of a function?
- To: mathgroup@smc.vnet.net
- Subject: [mg10827] Re: How to change the argument of a function?
- From: Allan Hayes <hay@haystack.demon.co.uk>
- Date: Tue, 10 Feb 1998 21:01:40 -0500
- References: <6baeau$bno@smc.vnet.net>
Vilis Nams wrote: > > I want to define a function that in the course of doing something, also > changes the value of its argument, for example: f[x_]:=Module[{}, > x=2*x; > x > ] > When I run the function, I get the error: "Set::setraw : Cannot assign > to raw object ...." Can this be done in some way? > Vilis: Could you explain more fully what you wish to do please? I'm not sure what "changes the value of its argument" means. The trouble with In[1]:= f[x_]:=Module[{}, x=2*x; x ] In[2]:= f[2] >From In[2]:= Set::setraw: Cannot assign to raw object 2. Out[2]= 2 is that every x on the right is replaced by 2, so that Mathematica is asked to evaluate Module[{}, 2 = 2 2, 2], and can't assign to 2. But, f[x_] := 2 x does what you seem to have been aiming. Allan Hayes 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