对函数体评估感到困惑 [英] Puzzled by Function body evaluation
本文介绍了对函数体评估感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对 Function
的以下行为感到困惑:
I am puzzled by the following behavior of Function
:
In[1]:= InlineCellInMessage=Function[expr,DisplayForm[Cell[BoxData[MakeBoxes[expr,StandardForm]],"Input"]],{HoldAllComplete}]
Out[1]= Function[expr,MakeBoxes[expr,StandardForm]]
我希望在输出中的 Function
中看到未计算的代码,如下例所示:
I expected to see unevaluated code inside Function
in the output as in the following case:
In[2]:= InlineCellInMessage=Function[x,x+1+1]
Out[2]= Function[x,x+1+1]
但是我在输出中得到了内联单元格.为什么会发生这种情况?
But I get the inline cell inside output. Why does this happen?
推荐答案
这是 FrontEnd 渲染的结果.考虑:
This is the result of FrontEnd rendering. Consider:
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
,您需要:
Also, in this use the parameter HoldAllComplete
affects future input to the function, not the creation of the function itself. If you want Function
itself to have HoldAllComplete
you need:
SetAttributes[Function, HoldAllComplete]
这篇关于对函数体评估感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文