I fear that I am so confused about this, that I will have trouble articulating the question! I believe the crux of the question involves how the FrontEnd intervenes during evaluation, and whether the FrontEnd ignores HoldAll attributes of a function; I
think I am looking for a FrontEndDefer function. I'm primarily interested in getting this to work consistently---but would also like to learn a bit more about the FrontEnd.
(*
postscript added after initial posting: I'm now looking at Interpretation[__] as a way to achieve this. I'm hopeful to hear from anyone has insight whether this will be fruitful or not*)
My goal here is to creating a modal dialog that displays and expression and then returns cells that contain the expression and the evaluated form of the expression.
Here is an example which I have streamlined as much as I can, but is still a bit involved. There are few examples of usage below which indicate the nature of my question.
SetAttributes[dialogFunc, {HoldAll, HoldAllComplete}];
dialogFunc[expr_] :=
With[{thisNB = InputNotebook[]},
DialogInput[
Notebook[
{
Cell[
BoxData[MakeBoxes[expr]], "Input"
],
Cell[BoxData[
ToBoxes[
DefaultButton[
DialogReturn[
NotebookWrite[thisNB,
{
Cell[BoxData[ToBoxes[Defer@expr]], "Input"],
Cell[BoxData[ToBoxes[Evaluate@expr]], "Output"]
}
]
]
]
]
],
"Input"]
}
]
]
]
Here is an example of usage that does what I intended:
dialogFunc[Sin[Pi/2]]
Here are three examples that illustrate (I believe) how the FrontEnd ignores the HoldAll attribute and Defer:
dialogFunc[Manipulate[Sin[n Pi/2], {n, 1, 10, 1}]]
dialogFunc[Defer[Manipulate][Sin[n Pi/2], {n, 1, 10, 1}]] (*note that Defer only wraps up Manipulate*)
dialogFunc[Defer[Manipulate[Sin[n Pi/2], {n, 1, 10, 1}]]]
Finally, here are additional illustrative examples that indicate where the FrontEnd may be intervening and capturing some functions such as D and not others such as Sin
Clear[f,x];
dialogFunc[D[f[x], x]]
dialogFunc[Defer[D][f[x], x]]
I wish that I had a more efficient way to ask this question!