4

I mean, suppose I have this expression:

2 + 2

I want to get something like this:

Plus[2, 2]

as an output. I've tried FullForm, but this just evaluates 2+2 and returns 4. Is this even possible?

Ezo
  • 43
  • 3

1 Answers1

7
tree = Function[x, Defer @ FullForm @ x, HoldAll];

Now:

2 + 2 // tree
Plus[2, 2]

I used Defer to allow the output to be evaluated. If you do not prefer this replace it with HoldForm.

For some explanation of the mechanics of this code see: Why doesn't "Defer" work with "TableForm"?

See also my standard methods for analyzing parsing.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371