Mr.*_*ard 15 wolfram-mathematica
我无法弄清楚为什么我必须两次评估(在Mathematica 7中)进行分配.
第一次评估:
Unprotect[Rule];
Attributes[Rule]
pp = Plot | LogLinearPlot | ListPlot | ParametricPlot3D;
(h : pp)[True -> False] ^:= Print["Irrelevant data"]
(*
Out[2]= {SequenceHold}
During evaluation of In[1]:= UpSetDelayed::write: Tag Rule in (h:Plot|LogLinearPlot|ListPlot|ParametricPlot3D)[True->False] is Protected. >>
Out[4]= $Failed
*)
Run Code Online (Sandbox Code Playgroud)
从中可以看出Out[2]= {SequenceHold},Unprotect[Rule]工作,但错误消息另有说明.如果我第二次评估单元格,则赋值并且不会生成错误.
为什么会这样?
Sas*_*sha 16
您可能知道,Mathematica会加载实现其某些功能的二进制MX文件.这些MX文件存储实现以及定义和属性.
这是阴险的,但Unprotect[Rule]Mathematica新加载的MX文件已经取消了,这就解释了为什么它第二次工作.因为Mathematica已经加载了所需的所有MX文件.
如果您首先评估表达式中的所有符号,那么它就会停止抱怨:
{Unprotect, Rule, Attributes, Plot, LogLinearPlot, ListPlot,
ParametricPlot3D, True, False, Print};
Unprotect[Rule];
Attributes[Rule];
pp = Plot | LogLinearPlot | ListPlot | ParametricPlot3D;
(h : pp)[True -> False] ^:= Print["Irrelevant data"]
Run Code Online (Sandbox Code Playgroud)
编辑需要进行第一次评估,以便在取消保护之前触发所有自动加载Rule.