Hi
I have just started using Mathematica,
I am trying to plot a bar graph with two data sets, resulting graph has two bar graphs with one appearing on top of the other.
We have a custom Mathematica package to do this job.
which has a function, with a module variable say (x)
this function gets called twice for the two data sets, and each time (x) is getting set to a different value by some calculation in this function.
is it possible to retain the value of (x) which gets set first time until it gets set to a different value second time
say in first time call x =1, I would like to some how persist this value of x when I call this function second time, so I can use it then
I have been going through Mathematica Language documentation online, and came to know about
PERSISTVALUE, which I understand is like a session variable, is this something I can use,
I did try to use PERSISTVALUE in our Mathematica code but I am unable to get it working,
when I first set PersistValue[‘myvar’] = 1, and then try to read it back in the same call it doesn’t show the value,
with this problem I cannot even expect it to be retained until the next call.
Firstly can you let me know if I can use PersistValue for retaining variable values between calls to a function.
Whenever you call f[x] it “knows” its former argument. This variable (oldArg) itself cannot be seen from outside, but from the functions (f[]) point of view it is global. This is a nice trick I learnt from @Leonid Shifrin (if I remember correctly).
Hi Henrik
Thanks, I will try this out. That is what I want, I want to remember the oldArg between two function calls,
supposing in first function call, we set oldArg =2, in the second function call I want to remember oldArg=2.