I open a new notebook and type

test[x_] := x + 42;

I save it as Temp.nb and also as Temp.m, using the menu Save As... > Wolfram Mathematica Package (*.m). I now open up another notebook and type

<< "Temp.m"

which succeeds. But the symbol test is not defined.

?? test
Information::notfound: Symbol test not found. >>

I'm confused, because the documentation for Get, a.k.a., <<, says

<< name reads in a file, evaluating each expression in it and returning the last one.

It should have evaluated the expressions in Temp.m, then, I should think, and returned the [value of] the last one, which would be Null. One of those expressions is a SetDelayed for the symbol test and should have installed test in the Global namespace, no?

Fresh kernel session, fresh reboot of MMA, also fails if file is saved as Wolfram Language Package (*.wl), yada yada.

  • $\begingroup$ Only initialization cells in .m files are evaluated when loaded. $\endgroup$
    – m_goldberg
    Commented Aug 18, 2014 at 5:37
  • $\begingroup$ More accurately only Initialization Cells are saved as active (non-comment) lines in the package file. $\endgroup$
    – Mr.Wizard
    Commented Aug 18, 2014 at 5:50


Browse other questions tagged or ask your own question.