1

Often we use Module to construct complicate function. Consider that Module create new vars every time we run the function, should I remove the initial values at the end of Module-function?Or should I worry about it?

I never thought of this problem until I browse this question. the first comment under the question suggested 'Try ending the Module with result =plapla; Clear[...]; result'. However,when I test Module on my Mma9, it cleared the value of initial values automatically. That is to say, I have no way to recover the initial values of initial vars after I run the Module(If I didn't Print value out). for example,define:

f[x_] :=
Module[{a, b},
Print@ToString@a;
a = Range[1000]; a[[4]]
]

run f[2] it print the initial symbols a$$4120, however run a$4120 it returns a$4120 as if it had not been set value. So it's not necessary to explicitly Remove the initial symbols of Module at the end of Module?Right?

Harry
  • 2,715
  • 14
  • 27

0 Answers0