1

I am still puzzled by the fact that Message is not always traced when switching On[Message] while surely this function is called through the evaluator.

Consider:

In[1]:= On[Message,Plus];
1+1
Sin[1,1]
During evaluation of In[1]:= Plus::trace: 1+1 --> 2. >>
Out[2]= 2
During evaluation of In[1]:= Sin::argx: Sin called with 2 arguments; 1 argument is expected. >>
During evaluation of In[1]:= Message::trace: Message[Sin::argx,Sin,2] --> Null. >>
Out[3]= Sin[1,1]

In[4]:= Unprotect[Message];
Message:=Print[List[##]]&
1+1
During evaluation of In[4]:= {Plus::trace,1+1,2}
Out[6]= 2

It is obvious that Message is called in both cases through the evaluator because the call can be intercepted on the top level. But it is not traced in the case of 1+1. Why?

Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93
  • 3
    Imagine that `Message` would be traced in such cases. How would you get out of infinite recursion (tracing message that is tracing message etc) then? – Leonid Shifrin Apr 27 '11 at 13:54
  • 2
    @Leonid This comment is just to tell you that I already read your comment. – Dr. belisarius Apr 27 '11 at 14:00
  • 1
    @belisarius That's exactly the point :) – Leonid Shifrin Apr 27 '11 at 14:05
  • @Leonid This comment .... Ok. Stop. – Dr. belisarius Apr 27 '11 at 14:12
  • @Leonid It is very interesting to know the underlying mechanism used to suppress tracing of the `Message` calls in such cases. Is it possible to simulate this making an analog of `Message`? – Alexey Popkov Apr 27 '11 at 14:14
  • @Alexey I guess it is not too hard: don't trace any message with the name `MessageName[somename,"trace"]`. This should be easy to check. – Leonid Shifrin Apr 27 '11 at 14:17
  • @Leonid How it could be done not breaking tracing `Message` calls in the other cases? – Alexey Popkov Apr 27 '11 at 14:23
  • @Leonid The problem is that *traced* `Message` call can [generate hundreds of `Messages` when tracing of many symbols is turned on](http://stackoverflow.com/questions/5772277/the-logic-of-message-internals). Suppressing them by a rule requires [many CPU time](http://stackoverflow.com/questions/5772277/the-logic-of-message-internals/5801972#5801972) and it is obviously not a way how it is implemented internally. – Alexey Popkov Apr 27 '11 at 14:28
  • @Alexey `Message` has `HoldFirst` attribute, so I suppose it should be possible for it to first look at the internals of `MessageName`. I don't see why this is s problem. And for your second comment - I don't understand: how is the generation of many messages related to breaking out of recursion for tracing mechanism? These seem two different problems to me. – Leonid Shifrin Apr 27 '11 at 14:44
  • @Leonid I pointed out that internal break of recursion works very fast and it seems that the excess calls to `Message` are not even produced because catching calls results in high CPU usage (at least in [my implementation](http://stackoverflow.com/questions/5772277/the-logic-of-message-internals/5801972#5801972) of catching mechanism). – Alexey Popkov Apr 27 '11 at 14:52
  • @Leonid It is not possible to catch calls just by one `MessageName` and symbol name. – Alexey Popkov Apr 27 '11 at 14:59
  • @Alexey I see your point. Can not offer a solution at the moment. – Leonid Shifrin Apr 27 '11 at 19:36
  • @Leonid will you please formally answer this question, so that it will not appear as unanswered? – Mr.Wizard Aug 18 '11 at 21:17

0 Answers0