Re: Test for On/Off
- To: mathgroup at smc.vnet.net
- Subject: [mg24710] Re: [mg24689] Test for On/Off
- From: Adalbert Hanssen <hanssen at Zeiss.de>
- Date: Wed, 9 Aug 2000 02:31:09 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hi, All! If you say Off[message], then the message is wrapped in $Off: In[13]:=On[General::spell] In[14]:=General::spell Out[14]="Possible spelling error: new symbol name \"`1`\" is similar to existing symbols `2`." In[15]:=Off[General::spell] In[16]:=General::spell Out[16]=$Off["Possible spelling error: new symbol name \"`1`\" is similar to existing symbols `2`."] In order to determine the On/Off state, we can investigate the Head of the message: In[17]:=On[General::spell] In[18]:=Head[General::spell] Out[18]=String In[19]:=Off[General::spell] In[20]:=Head[General::spell] Out[20]=$Off The message is Off, if the head of it is $Off. An implementation of checking the current state would be: In[43]:= CurrentState[message_]:=If[Head[Evaluate[message]]===$Off ,Off ,On ]; Attributes[CurrentState]={HoldAll}; In[46]:=On[General::spell]; CurrentState[General::spell] Off[General::spell]; CurrentState[General::spell] Out[47]=On Out[49]=Off Now, I would like to overload On[message] and Off[message], such that they always return the previous state before On and Off were applied. Any Idea how to overload On and Off? Regards Adalbert