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.

It is common in many packages, as well as system symbols, that the same message can be issued by several functions. Here's an example:

Mathematica graphics

One mechanism that can be used for this is to define the message only once, and attach it to the General symbol. This is how the infy messages works as well. infy can appear to come from any symbol:

Mathematica graphics

When writing a custom package, it might not be the best idea to do this though because of the risk of message conflicts. Two packages might attach the same message identifier to General, so the one that's loaded last will overwrite the previous one. In fact, looking at the some standard packages (e.g. CUDALink), they do not attach messages to General even when the same message can be issued by several functions. Looking at the source code of the package, CUDALink uses a helper function to attach the same message text to several symbols in one go.

The question: What is the best way to proceed when several functions need to be able to issue the same message, and indicate that it is coming from them? What do you use in your own packages?

What's important for me is minimizing the risk of conflict with other packages and the simplicity of implementation.

share|improve this question
Once I saw it done by cascading $NewMessage functions, but I can't remember where. If I remember well, it wasn't too difficult. –  belisarius Feb 27 '13 at 17:30

1 Answer 1

up vote 5 down vote accepted

How about doing something as simple as

sym1::msg = "I am feeling grumpy.";
sym2::msg = sym3::msg = sym1::msg; 


Do[With[{ff = f}, 
  Message[MessageName[ff, "msg"]]], {f, {sym1, sym2, sym3}}]


sym1::msg: I am feeling grumpy.

sym2::msg: I am feeling grumpy.

sym3::msg: I am feeling grumpy.
share|improve this answer

Your Answer


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.