打开和关闭ShowIt调试功能
问题描述:
我喜欢在此处定义的Mathematica中使用ShowIt变体进行调试。https://*.com/a/8270643/884752。我又读到了rcollyer的想法,使用消息的某些功能在这里打开或关闭https://*.com/a/4211700/884752。我问自己是否可以为ShowIt做类似的事情,但我没有做到。有人有任何想法吗?由于打开和关闭ShowIt调试功能
答
如果我理解你的意图:
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
谢谢,这是我想要的。我不能将调试消息的输出转换为像我为原始ShowIt一样的输入格式。有没有办法绕过这个? – faysou 2012-01-15 11:27:14
@Faysal,我不知道。我明天会尝试。 – 2012-01-15 15:35:02