Question: why save to .m fie do not update variable in file?

I wanted to keep a running total over a number of independent batch mode Maple scripts.

So I figured I use .m file.   

Each run will read the old variable from .m file, update it, and write it again.

All what it need to do is just check if the .m file exist or not to account for the very first run.

But to my surprise, I found the variable content do not update after doing SAVE A,"TMP.m"

It seems Maple sees A variable already in TMP.m and does not save the new value of A again?. Just guessing. I was expecting that after I do  read "TMP.m" that the variable in the file will overwrite same variable value in the local proc. 

After one time update, each time I read the variable, its value is same.

First time using save myself, so may be I am doing something wrong but do not see it. I was expecting to see   10,20,30,40,50,..... running total, but I see 10,20,20,20,20,...../

What Am I doing wrong? do I need to make the variable global for this to work?

Here is worksheet. Maple 2024 on windows 10.


 

24344

restart;

24344

currentdir("G:/public_html/my_notes/solving_ODE/new_version/tests/");
try  #remove TMP.m first time
    FileTools:-Remove("TMP.m");
catch:
    NULL;
end try;

#this function is called many times.
foo:=proc()
 local A:=0,B;
 A:=A+10;
 if FileTools:-Exists("TMP.m") then
     print("TMP.m exists, will read its content");
     B:=A; #save copy
     read "TMP.m";
     print("Read old value of A from file",A);
     A:= A + B; #update running total
     print("Now A is ",A," will now save this new value");     
     save A,"TMP.m";
  else
     print("TMP.m do not exist, first time saving to it");
     save A,"TMP.m";
  fi;
  print("A=",A);
end proc:
 

"C:\Program Files\Maple 2024"

foo();

"TMP.m do not exist, first time saving to it"

"A=", 10

foo();

"TMP.m exists, will read its content"

"Read old value of A from file", 10

"Now A is ", 20, " will now save this new value"

"A=", 20

foo();

"TMP.m exists, will read its content"

"Read old value of A from file", 10

"Now A is ", 20, " will now save this new value"

"A=", 20

foo();

"TMP.m exists, will read its content"

"Read old value of A from file", 10

"Now A is ", 20, " will now save this new value"

"A=", 20

foo();

"TMP.m exists, will read its content"

"Read old value of A from file", 10

"Now A is ", 20, " will now save this new value"

"A=", 20

 


 

Download T.mw

Please Wait...