I have a question about FullDefinition
and how it interacts with the local variables of Module
.
I've created a few functions (with Module
) and I wanted to save their definitions, so I can use them later. These functions call other functions and so I wanted to use Save
to have their FullDefinition
saved.
The problem I have is that when I do this, it also saves whatever variable which happened to have the same name of that one of the local Module[]
variable.
A simple example would be :
g[t_] := 5*t;
f[t_] := Module[{c},
c = g[t];
Return[c]
]
I use another variable :
c = 2;
and now if I call FullDefinition[]
:
FullDefinition[f]
(*
f[t_] := Module[{c}, c = g[t]; Return[c]]
c = 2
g[t_] := 5 t *)
I don't really understand why FullDefinition
contains the global assignment of c, and it's really a problem if I don't want global variables to pollute my saved file. I don't want them to be loaded every time I load the functions.
c
in the module will be aliased to something likec$2546
when the definition off
is evaluated, this looks like a bug inFullDefition
to me. As an aside, theReturn[c]
in your definition off
is unnecessary becauseModule
returns the last expression it evaluates, and good practice dictates thatReturn
not be used when it isn't needed. $\endgroup$