2011-04-11 53 views
3

我受的Function以下行为疑惑不解:通过函数体评价

In[1]:= InlineCellInMessage=Function[expr,DisplayForm[Cell[BoxData[MakeBoxes[expr,StandardForm]],"Input"]],{HoldAllComplete}] 
Out[1]= Function[expr,MakeBoxes[expr,StandardForm]] 

我预计在输出看到里面Function未评估的代码,如以下情况:

In[2]:= InlineCellInMessage=Function[x,x+1+1] 
Out[2]= Function[x,x+1+1] 

但我在输出中获得内联单元。为什么会发生?

+0

尝试使用'InlineCellInMessage:= Function' – Elalfer 2011-04-11 02:53:39

回答

3

这是FrontEnd渲染的结果。试想一下:

InlineCellInMessage = 
    Function[expr,DisplayForm[Cell[BoxData[MakeBoxes[expr,StandardForm]],"Input"]],{HoldAllComplete}] 

InlineCellInMessage // InputForm 

输出:

InputForm[Function[expr, DisplayForm[Cell[BoxData[MakeBoxes[expr, StandardForm]], "Input"]], {HoldAll.Complete}]] 

而且,在此使用参数HoldAllComplete影响未来输入功能,而不是创造功能本身。如果你想Function本身具有HoldAllComplete您需要:

SetAttributes[Function, HoldAllComplete] 
+0

有趣,'HoldAllComplete [DisplayForm [细胞[BoxData [MakeBoxes [EXPR,StandardForm], “输入”] ]]'也被渲染。有没有办法来控制这种行为? – 2011-04-11 03:40:07

+0

我不知道我们可以直接设置属性来内置'保护'功能。谢谢你的观点! – 2011-04-11 03:47:19

+0

最直接的路线是像我一样使用''InputForm',但我认为你需要不同的行为。请具体说明。 – 2011-04-11 04:26:33