Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
1  
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. –  Szabolcs Oct 11 '13 at 19:17
1  
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. –  Leonid Shifrin Oct 11 '13 at 19:32
2  
@Szabolcs Set doesn't print if the package is read in via << or Needs –  rm -rf Oct 12 '13 at 4:15

1 Answer 1

(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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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