Re: Static variables
- To: mathgroup at smc.vnet.net
- Subject: [mg9344] Re: [mg9287] Static variables
- From: seanross at worldnet.att.net
- Date: Sat, 1 Nov 1997 03:33:30 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Gadi Oron wrote: > > Hi there, > > Does anybody knows how to (easily) define static variables in > Mathematica functions (i.e. variables which values are kept between two > calls to the function but are not global). > > Thank you. > > \/\\/\/\/>> Gadi ORON <<\/\/\/\/ o o > \_____/ > EMAIL : oron at pmmh.espci.fr /=O=O=\ _______ > Soyez braves - Be brave / ^ \ /\\\\\\\\ > \ \___/ / /\ ___ \ > \_ _/ /\ /\\\\ \ > \ \__/\ /\ @_/ / > \____\____\______/ > Homepage : http://www.pmmh.espci.fr/~oron/personal.html This is a guess. The following code works but I am not 100% sure it does exactly what you want. Use a private symbol name which defines a function that remembers its value. ie: myfunction[x_,.....]:=Module[{myprivatefunction,...}, functionbody; myprivatefunction[y_]:=myprivatefunction[y]=myprivatefunctiondefinition; etc. etc. Return[whatever]]; another idea is to define a private context and set up your symbols within that context, then read them in during the function.