Re: Variables Within Homemade Functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg69604] Re: [mg69590] Variables Within Homemade Functions*From*: Gregory Lypny <gregory.lypny at videotron.ca>*Date*: Sun, 17 Sep 2006 06:57:31 -0400 (EDT)*References*: <6348852.1158414510776.JavaMail.root@eastrmwml01.mgt.cox.net>

Thanks David Park (who framed his response as a Jeopardy question), Bob Hanlon, David Annetts, and Jean-Marc Gulliet for pointing me to the Module and Block functions. I had browsed Functions and Programs in the Help Browser's Mathematica book, and missed the sentence referring to modules under Functions as Procedures. Of course, below that was a number of examples. The Block function wasn't mentioned though, but I'll look it up. "When you write procedures in Mathematica, it is usually a good idea to make variables you use inside the procedures local, so that they do not interfere with things outside the procedures. You can do this by setting up your procedures as modules, in which you give a list of variables to be treated as local." Next time I'll dig through the documentation more carefully! Gregory On Sat, Sep 16, 2006, at 9:48 AM, Bob Hanlon wrote: > See Help browser for info on Module and Block. > > > Bob Hanlon > > ---- Gregory Lypny <gregory.lypny at videotron.ca> wrote: >> Hello everyone, >> >> 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? >> >> Regards, >> >> Greg >> >> t=17 >> >> myFunction[x_]:=(t=someOtherValue; rest of function here) >>