When I start a new notebook, I enter
Names["Global`*"]
I get this
{"list", "msgs", "rhs", "z"}
Then I enter,
mydummy[x_, y_, model_] := Module[
{ans, j},
ans = Sum[x[[j]], {j, 1, y}]
];
Names["Global`*"]
I get this:
{"ans", "ans$", "j", "j$", "list", "model", "model$", "msgs", "mydummy", "rhs", "x", "x$", "y", "y$", "z"}
I dont really know the difference between x
and x$
here. I don't know any of the difference between the variables and the one with an extra $
.
I check
?j
?j$
Ok, one of them is 'Temporary'.
Here are my questions:
1 - Are they all saved in RAM during the session? 2 - What's the point of saving these 'Temporary' (Global) variables? I thought when declaring them to be local using Module[], they would be thrown away after my execution.
3 - Why do we have x
and y
at first place? I only defined mydummy
, which is a function. So I only want the 'final' value when it's evaluated.
4 - If the x
and y
are of any use, how do I access them? I tried
x
It does not tell me anything?
5 - If I define a new function,
mydummy2[x_, y_, model_] := Module[
{ans, j},
ans = Sum[x[[j]], {j, 1, y}]
]
Now
Names["Global`*"]
which 'x' is which?
6 - Sometimes, I get Global variables like
tmp$1
tmp$20
tmp$300
To me, they are all 'local' to a Module. But it's in the list when I use 'Names["Global`*"]', why are they there? Can I remove them during a long calculation? How to remove and what's the downside of removing them?
7 - Do I need to declare $j$ within a Module, if it's a dummary index value, like this
ans=Table[Sum[j],{j,1,3}]
(* or *)
ans=Sum[x[[j]],{j,1,3}]
8 - Lastly, when i first started Mathematica, what are the "list,msgs,rhs,z" variables?
Sorry if this seems really silly. But I do want to understand this, as I have long codes, it seems sometimes it's using too much memory. I am not sure if it's caused by those 'local' variables.