I am trying to figure out the logic of Message
behavior.
Consider evaluation of the following:
On[]
Sin[1,1]
After evaluating the above you will get about 830 (!) Messages
(in Mathematica 7).
All these Messages
have arisen during producing the one:
Sin::argx: Sin called with 2 arguments; 1 argument is expected. >>
(this is one but last Message
).
The last Message
Message::trace: Message[Sin::argx,Sin,2] --> Null. >>
corresponds to finishing of the work of internal Mathematica's Message
function. Most of the other Messages
go from evaluation of $NewMessage
and $MessagePrePrint
.
My questions are:
1) Why there are no infinite loop of Message
generation? If calling Message[Sin::argx,Sin,2]
produces more than 830 other Messages
why each of them does not produce similar number of Messages
? How such behavior can be simulated (by writing an analog of Message
)?
2) Is it possible to force Message
do not produce any additional Messages
when it is called in the tracing mode (I mean the mode after evaluating On[]
)?
It seems that I have found one way to achieve with built-in function
Message
what I want:Now things work as expected:
The only problem with the above is that CPU load is still high as you can see from the timings.
Other tested cases also work correctly:
Thanks to Mr.Wizard for his help.
I am not understanding why it is necessary to turn on all the messages with
On
. Can you not only activate the subset you need. The reference page ofOn
in "More Information" section lists various categories which you might find useful. In case you choose to proceed as stated, you can suppress trace messages by explicitly turning them off right afterOn[]
:This outputs only two messages. Hence 830 of the messages you see are ::trace messages and originate from execution of some top-level code which is not necessarily message related, might be typesetting...