Forgive my ignorance, I'm new to Mathematica/the Wolfram Language.
I'm looking for a way to apply HoldForm or some equivalent to the result of a function, as well as its arguments.
For example, I would like to modify
Sort[Unevaluated[n+1+2]]]
so that it returns 1+2+n rather than 3+n.
Using Trace on this line reveals the following.
{Sort[n+1+2],1+2+n,3+n}
So it appears that my arguments are being passed in unevaluated, as I had hoped, but that the result is evaluated. How can I prevent this?
Edit:
I have found that using some version of Inactive doesn't quite suit my needs, at least on its face, because I would like to be able to convert the result to a string for export. From what I can tell:
ToString[HoldForm[1+2+n]]
returns "1 + 2 + n", which is what I need.
However,
ToString[Inactive[Plus][1+2+n]]
or
ToString[Inactive[Plus] @@ Sort[{n, 1, 2}]]
returns a string with the Inactive wrapper.
Is there a way to use HoldForm rather than Inactive? Or is there a way to make an inactive expression convert to a string without the wrapper?
Inactive[Plus] @@ Sort[{n, 1, 2}]– Bob Hanlon Mar 11 '17 at 20:16ToString[Plus @@ (ToString /@ Sort[{n, 1, 2}])]– Bob Hanlon Mar 11 '17 at 21:46Inactive[Plus]by replacing it afterwards:Inactive[Plus] @@ Sort[{n, 1, 2}] /. Inactive[Plus][a__] :> HoldForm[Plus[a]]– b3m2a1 Mar 12 '17 at 20:12nor only about1/2not being added up. What is really the input here? – Kuba Mar 13 '17 at 19:36