3

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]]

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?

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93

1 Answers1

3

This is the result of FrontEnd rendering. Consider:

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

InlineCellInMessage // InputForm

Output:

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

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]
Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
  • Interesting, `HoldAllComplete[DisplayForm[Cell[BoxData[MakeBoxes[expr, StandardForm]], "Input"]]]` is also rendered. Is there a way to control this behavior? – Alexey Popkov Apr 11 '11 at 03:40
  • I was unaware that we can directly set attributes to built-in `Protect`ed functions. Thank you for the point! – Alexey Popkov Apr 11 '11 at 03:47
  • The most direct route is to use `// InputForm` as I did, but I presume you want different behavior. Please be specific. – Mr.Wizard Apr 11 '11 at 04:26
  • I just wish to understand what types of expressions FrontEnd renders automatically. I found that even `HoldAllComplete[Style[DisplayForm[Cell[BoxData[MakeBoxes[expr, StandardForm]], "Input"]], Red]]` is auto-rendered. It is very surprizing for me since `Style` is not a low-level construct. From the other side, `MakeBoxes[expr, StandardForm]` is not a valid low-level expression for `BoxData`. How all of this works? – Alexey Popkov Apr 11 '11 at 04:40
  • 1
    When the FrontEnd finds a `Style` expression within a StandardForm cell (for example), it automatically applies the style as instructed. This is not limited to `Style` and includes instructions such as `Rotate`. Try: `HoldAllComplete[Rotate[Style[expr, Red], 0.5]]` – Mr.Wizard Apr 11 '11 at 04:53
  • Interestingly, the output has completely another internal structure (press Ctrl+Shift+E) than input. If we copy-paste the output then the `InputForm` of the expression we get will differ from the original input. Is this new expression created by the FrontEnd? – Alexey Popkov Apr 11 '11 at 05:59
  • Is it possible to get complete list of expressions that are parsed by the FrontEnd automatically? – Alexey Popkov Apr 11 '11 at 06:04
  • @Alexey I don't know. I think that is worthy of posting to another question. – Mr.Wizard Apr 11 '11 at 06:19
  • @Mr.Wizard I have created [separate question](http://stackoverflow.com/questions/5617685/conversion-of-expressions-by-the-frontend) on this. – Alexey Popkov Apr 11 '11 at 06:46