2

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.

WoofDoggy
  • 314
  • 1
  • 10

1 Answers1

2

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257