6
$\begingroup$

I noticed that if I open a .m file in Mathematica and click on the Run Package button, all the Set definitions will be printed as output if they are not ended in ;. The same for function::usage definitions.

This is probably harmless, but I am wondering if there is a guidance on weather semicolons should be appended at the end of Set or SetDelayed definitions.

Looking into the Mathematica libraries source code, I can see both approaches - some Module functions have ; at the end, others do not.

$\endgroup$
  • 1
    $\begingroup$ As you noticed, it doesn't really make a difference for as long as the commands written in the package don't print any output as a side effect. Packages typically contain definitions, which don't print anything when evaluated, so most of the time there's no need for semicolons. Set is a possible exception, as you noticed. $\endgroup$ – Szabolcs Oct 11 '13 at 19:17
  • 1
    $\begingroup$ I usually do this, but I know a lot of folks who don't. This probably doesn't matter much, as long as one is consistent with it. $\endgroup$ – Leonid Shifrin Oct 11 '13 at 19:32
  • 2
    $\begingroup$ @Szabolcs Set doesn't print if the package is read in via << or Needs $\endgroup$ – rm -rf Oct 12 '13 at 4:15
2
$\begingroup$

(Based on Szabolcs's & rm -rf's comment)

As you noticed, it doesn't really make a difference for as long as the commands written in the package don't print any output as a side effect. Packages typically contain definitions, which don't print anything when evaluated directly, so most of the time there's no need for semicolons. Set is a possible exception, as you noticed.

Even cells in the package which contain code that otherwise prints output if Shift+Enter-ing the cell (e.g. lines with Set, or simple statements without assignments like {1, 2, 3}) won't print anything if the package is read in via << or Needs.

$\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.