打开和关闭ShowIt调试功能

时间:2012-01-14 20:12:10

标签: wolfram-mathematica

我喜欢在这里定义的Mathematica https://stackoverflow.com/a/8270643/884752中使用ShowIt的变体进行调试。我再次阅读rcollyer的想法,即使用某些功能的消息来打开或关闭它们https://stackoverflow.com/a/4211700/884752。而且我问自己是否有可能为ShowIt做类似的事情,但我没有成功。有人有什么想法吗?感谢

1 个答案:

答案 0 :(得分:1)

如果我理解你的意图:

debug::ShowIt = "`1`";
SetAttributes[System`ShowIt, HoldAll];
System`ShowIt[code__] := System`ShowIt[{code}];
System`ShowIt[code_] :=
  With[{y = code},
    Message[debug::ShowIt, HoldForm[code = y]];
    y
  ];
In[5]:= ShowIt[2 + 2]

During evaluation of In[5]:= debug::ShowIt: 2 + 2 = 4

Out[5]= 4

In[6]:= Off[debug::ShowIt]
        ShowIt[2 + 2]

Out[7]= 4