2
$\begingroup$

I want to use mu own package. This is the procedure I take:

1) In Mathematica notebook I put the following code taken from code

BeginPackage["SOPackage`"];
AddTwo::usage = 
"AddTwo[\!\(\*StyleBox[\"a\", \"TI\"]\), \!\(\*StyleBox[\"b\", \"TI\
\"]\)] returns \!\(\*StyleBox[\"a\", \"TI\"]\)+\!\(\*StyleBox[\"b\", \
\"TI\"]\).";
DotTwo::usage = 
"DotTwo[\!\(\*StyleBox[\"a\", \"TI\"]\), \!\(\*StyleBox[\"b\", \"TI\
\"]\)] returns \!\(\*StyleBox[\"a\", \"TI\"]\)*\!\(\*StyleBox[\"b\", \
\"TI\"]\).";
AddTwo::argnum = 
"AddTwo was called with `1` arguments. It expected 2.";
DotTwo::argnum = 
"DotTwo was called with `1` arguments. It expected 2.";

Begin["`Private`"];

AddTwo[a_, b_] := a + b
AddTwo[args___] := (Message[AddTwo::argnum, Length[{args}]]; $Failed)
DotTwo[a_, b_] := a*b
DotTwo[args___] := (Message[DotTwo::argnum, Length[{args}]]; $Failed)

End[];
EndPackage[];

2) Go to SaveAs SOPackage.m

3) Put the file in $UserBaseDirectory/Applications

4) load the package with << SOPackage`

The problem is that nothing is loaded (I checked with Names["SOPackage`*"]). How to do this right?

I am using Mathematica 10.1 on Linux.

$\endgroup$
  • $\begingroup$ See (31302) $\endgroup$ – ilian Aug 29 '15 at 18:17
  • $\begingroup$ You quoted Names["SOPackages`*"], while it should've been Names["SOPackage`*"]. Could it be just a simple typo? $\endgroup$ – Leonid Shifrin Aug 29 '15 at 18:17
  • $\begingroup$ yes a typo. Sorry $\endgroup$ – WoofDoggy Aug 29 '15 at 18:18
  • $\begingroup$ So, does the correct command give you the function names all right? $\endgroup$ – Leonid Shifrin Aug 29 '15 at 18:18
  • $\begingroup$ Unfortunately not :( empty. $\endgroup$ – WoofDoggy Aug 29 '15 at 18:20
2
$\begingroup$

All cells in a notebook saved as a .m file which is intended to be loaded with Get or Needs must be initialization cells.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.