0
  1. Is there a way to inquire whether a given message is switched On or Off without modifying the $Messages variable? The documentation is completely mum about it, it seems.

  2. Conversely, if such inquiry is not recommended by design intent, is it at least possible to "push" the current message status, modify it e.g. by turning a message on or off, and then "popping" it?

I know that a list of message types can be temporarily quieted while evaluating an expression with Quiet[expr, {message1, ...}].

Off, On, and Message are compiled kernel functions, so snooping around the available source is of no help.

creidhne
  • 5,055
  • 4
  • 20
  • 28

2 Answers2

2

Here is a simple example using the message Log::argct.

We first switch the message off and then check:

Off[Log::argt]    
Log::argt /. Messages[Log]

$Off[]

Therefore, the answer $Off[] indicates that the message is switched of. On the other hand, by switching the message on we get the full message:

On[Log::argt]
Log::argt /. Messages[Log]

"1 called with 2 arguments; 3 or 4 arguments are expected."

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
1

A bit more digging in documentation reveals that Messages[symbol], which returns the list of all messages for the given symbol, wraps the messages that have been turned off in $Off:

  Off[ParallelMap::nopar1]

Messages[ParallelMap] {HoldPattern[ParallelMap::nopar1] ⧴ $Off[1 cannot be
parallelized; proceeding with sequential evaluation.]}

On[ParallelMap::nopar1]

Messages[ParallelMap] {HoldPattern[ParallelMap::nopar1] ⧴ 1 cannot be
parallelized; proceeding with sequential evaluation.}

Context[$Off] System`

That allows to inquire the message status, modify it as desired, and then restore it.