Is it possible to preserve a specific style of notation in $Mathematica$ output?
foo // bar
(* bar[foo] *)
Hold[foo // bar]
(* bar[foo] *)
I'm writing some code that generates sample code (e.g. a usage hint), and in one case I feel that postfix notation is easier on the eyes. I know it's subjective and not that important but now I'm just curious whether this is possible to control.
Edit
Postfix
preserves the notation as @rasher pointed out. However, my intent was to allow convenient evaluation of sample code by being able to immediately evaluate the output—that is, ShiftEnter the foo//bar
. When Postfix
is the head of an expression though, the evaluation simply returns the expression—which, makes complete sense, since that's what Postfix
... does. (This question almost seems circular now.)
Is there a way, perhaps, to create a custom PostfixToEvaluate
head that would display the expression in postfix but, maybe via an UpValue, remove itself and evaluate its contents, upon evaluation? (I don't know if that makes any sense. I'm going to try it now...)
Tags I considered but don't believe are relevant: stylesheet hold expression-manipulation. Note that I've left "hold" in the title as that's the intuitive keyword by which I would have searched, were I a future visitor.
Postfix[foo//bar]
will outputfoo//bar
? $\endgroup$ – ciao Mar 1 '14 at 7:42Postfix
. Thank you. Would you post it as an answer? (Though, I expect this question to get closed or deleted.) It wasn't very obvious to me, at least. $\endgroup$ – Andrew Cheong Mar 1 '14 at 7:45Interpretation["2//Sqrt//N", 2 // Sqrt // N]
. This displays as the string, when shift-entered, it evaluates as expected. Downside is it leaves the original, but quotes it (might not be such a bad thing). You could, I suppose, add the notebook commands to go up one and delete that as part of eval... $\endgroup$ – ciao Mar 1 '14 at 9:07Interpretation[Style["2//Sqrt//N", ShowStringCharacters -> False], 2 // Sqrt // N]
will show as the string, when evaluated, evaluates as expected, turns into typical bold MMA input form when done with no quotes, can be re-evaluated as often as wanted... $\endgroup$ – ciao Mar 1 '14 at 9:41