Is it allowed to define local functions inside the Module
in Mathematica? For example, out of the two codes below which one is correct?
First:
plt1[a_, b_] :=
Module[{x, y},
f[x_, y_] := Sin[x*y];
Plot3D[f[x, y], {x, -a, a}, {y, -b, b}]
];
plt1[1, 2]
Second:
plt2[a_, b_] :=
Module[{f},
f[x_, y_] := Sin[x*y];
Plot3D[f[x, y], {x, -a, a}, {y, -b, b}]
];
plt2[1, 2]
f
in the second example, since often (but not in your case above) they will not be automatically garbage-collected. I recommend reading this Q/A for more information on that. $\endgroup$