RE: Variables Within Homemade Functions
- To: mathgroup at smc.vnet.net
- Subject: [mg69601] RE: [mg69590] Variables Within Homemade Functions
- From: "David Annetts" <davidannetts at aapt.net.au>
- Date: Sun, 17 Sep 2006 06:57:25 -0400 (EDT)
Hi Gregory, > How can I ensure that variables in my home made function do > not conflict with variables with the same name outside the > function? Say I have a variable, t, whose value in my > notebook is 17. I've brought in a function from another > notebook, myFunction, that contains a variable named t, and > in running the function, t will take on a value. > Unfortunately, both t's are the same. Is there any way to > make the t within the my function a local variable just like > index counters in the Table and Do functions? You can use either Module[] or Block[] to localise a variable. t = 20; newt[a_] := Module[ {t}, t = a ]; {t, newt[#]} & /@ Range[10] Regards, Dave.