I'm trying to learn to reuse functions. I have created a .wl file with the following content. As I understand the last line without semicolon is the function output. Should each function have it's own block of Begin[] and End[]?
BeginPackage["vectorFunctions`"] Begin["`Private`"] (* Begin Private Context *) vectorDeriv::usage=" vectorDeriv[v_,bc_Integer] "; (* The function works fine if declared in the notebook. *) vectorDeriv[v_,bc_Integer] := ( vFFirstDer = D[v,{t}]; vFSecondDer = D[v, {t,2}]; vFFirstDerNorm = N[Norm[vFFirstDer] /. t -> bc]; vFSecondDerNorm = N[Norm[vFSecondDer] /. t -> bc]; {vFFirstDer, vFSecondDer, vFFirstDerNorm, vFSecondDerNorm} ) End[] (* End Private Context *) EndPackage[] When I try to call the function from the notebook I get no output.
(* the path is correct *) In[39]:= Get["C:\\Program Files \ (x86)\\MyJournal\\Images\\Math_Physics_Library\\vectorFunctions.wl"] Out[39]= "vectorFunctions`Private`" In[40]:= vF = {Sin[2 t], E^(3 t), t^3 - 4 t}; In[41]:= vectorDeriv[{Sin[2 t], E^(3 t), -4 t + t^3}, 2] Out[41]= vectorDeriv[{Sin[2 t], E^(3 t), -4 t + t^3}, 2] Am I missing something with the Private vs Public scope? Should modules be kept in only Mathematica's running directory?
BeginPackageetc. to simply re-use function definitions. It is sufficient to put the definitions into an.mor.wlfile and load them withGet.Getjust evaluates whatever is in your file—it does nothing more and nothing less. $\endgroup$vectorDerivis not mentioned betweenBeginPackageandBegin. See the post about creating packages I linked above (also this answer). $\endgroup$