1

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?

mm716783
  • 19
  • 2

1 Answers1

0

Depending on exactly what you are trying to achieve, you could replace Plus with, for example, CirclePlus

Sort[n⊕1⊕2]
(* 1⊕2⊕n *)
mikado
  • 16,741
  • 2
  • 20
  • 54