Skip to content

InputForm

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

InputForm[expr]

prints expr in a form suitable to be re-read by the parser, using operator syntax (a + b, not Plus[a, b]) and explicit string quotes.

Notes Like FullForm, InputForm is a printer wrapper: it is consumed during output and does not appear in the printed result.

Examples (5)

Every input below was run against the current Mathilda build and its output recorded.

Applications (5)

In[1]:= InputForm[1/2]
Out[1]= 1/2

In[2]:= InputForm[a + b]
Out[2]= a + b

In[3]:= InputForm[{1, 2, 3}]
Out[3]= {1, 2, 3}

In[4]:= InputForm[1/2 + 3/4 I]
Out[4]= 1/2 + 3/4*I

In[5]:= InputForm[{1, 1/2, "a", x}]
Out[5]= {1, 1/2, "a", x}

Implementation notes

InputForm is an unevaluated display wrapper: builtin_inputform (src/print.c) returns NULL, leaving InputForm[expr] intact. The printer's print_standard detects the InputForm head and renders the argument in a re-parseable form (a printer flag toggles InputForm-specific formatting); ToString[expr, InputForm] routes through the same standard printer.

Attributes: Protected.

References

Notes & additional examples

Notes

InputForm prints an expression in a form the parser can read back in, unlike FullForm which exposes the internal tree. It is the form to use when you need to copy a result back into the REPL or store it as text.