In order to keep my code modular, I have defined some functions in "Foo.wl" file, which I source with Needs["Foo`"]
.
When I modify a single function in Foo, I quit the kernel and reload Foo in order to ensure that the modified functions are reloaded. Is there a way to ensure that Mathematica automatically reloads only the changes? I don't want to have to request Mathematica to specifically clear some function.
EDIT: To clarify, my package has multiple functions (to be numerically evaluated). I think Mathematica does a good job of optimizing repeated calculations by caching the values of function calls.
So I do not want to reload the whole package. I want Mathematica to reload only those functions which have changed.
EDIT2: An explicit example. I have some functions defined in an external ".wl" file, Eg: f[x_]:=f[x]=x^2; g1[x_]:=g1[x]=x^3; g2[x_]:=g2[x]=x^4;
Suppose I source this using Needs
or Get
and do Plot[{f[x],g[x]},{x,0,100}]
. Plotting the same thing again will give near instantaneous results (even when $f,g_1,g_2$ are complicated functions) since the values are "memoized". If/when I change the definition of $g1,g_2,\ldots$ in the ".wl" file, I would like to be able to reload their definitions,without losing the memoized values of $f(x)$.
Foo`Private`
). You can then execute it insideBeginPackage["Foo`"]
-EndPackage[]
. In such a case, you will automatically patch your loaded code, and only with the changes you actually make. When the code is complete, you can move it from FrontEnd to the file. $\endgroup$