MathGroup Archive 1997

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

Search the Archive

Re: variable problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9545] Re: [mg9512] variable problems
  • From: jpk at max.mpae.gwdg.de
  • Date: Thu, 13 Nov 1997 01:40:09 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Hi, 

  at first in
   
  f[x_,y_]:= ..
  
   is *not*, NOT a parameter of a function x_ is a pattern and total
different
   from a function parameter. It mix the pattern matching totaly up if
You
   assign a value to it. You can still use a local variable.

f[x_,y_]:=
  Module[
    {xx=x, a1, a2, a3},
    a1=x+y;
    xx=1;  (* this will be ok *)
  ];
    
A pattern is assigned dynamical during Mathematica evaluation process
and it is not a real variable it stands for an arbitarry expression. It
is clear that You can not assign the value 1 to any expression.

If You want change the value of x as a side effect of the function 
evaluation You can do the following

SetAttributes[test,HoldAll]
test[x_Symbol,y_]:=Module[{z},
		z=x+y;
		(x=1)
	]

Hope that helps

Jens

> Hello,
> I am I wrote a package on mathematica for strain computations  and
> diagrams in mechanics but I have a problem.
> 
> Does anyone know how can I modify the value of a parameter  of a
> function inside the declaration of the function? Here is an example:
> 
> f[x_,y_]:=Module[
> {a1,a2,a3},
> a1=x+y;
> x=1;  <------- this line causes an error message  ];
> 
> Note that I could use a local variable a1 for this putting a line
> a1=x;a1=1;  but because of the complexity  of the source code i wrote ,
> it's not possible to rewrite  every line of code.
> 
> 
> Thanks you..
> 
> If it is possible send me this answer to my email: mtousis at rodopi.cc.du
> 
> Manolis Toussis 
> Student of the Civil Engineer Department of Democritus University Of
> Thrace.
> 


  • Prev by Date: Loading Packages
  • Next by Date: Re: Frontend bug
  • Previous by thread: variable problems
  • Next by thread: Re: variable problems