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 (12)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (3)¶
In[1]:= InputForm[{1, 1/2, "a", x}]
Out[1]= {1, 1/2, "a", x}
In[2]:= InputForm["say \"hi\""]
Out[2]= "say \"hi\""
In[3]:= InputForm[Series[Exp[x], {x, 0, 3}]]
Out[3]= SeriesData[x, 0, {1, 1, 1/2, 1/6}, 0, 4, 1]
Applications (9)¶
Linear syntax
Strings keep their quotes
Embedded quotes are escaped
Explicit * before I
A series shows its SeriesData form
Display wrappers are kept, so the text re-reads
String patterns print infix
An inert wrapper that stays in the expression
Round trip through text
Implementation notes¶
Mechanism. InputForm is an inert display wrapper. builtin_inputform (src/print.c) returns NULL, so InputForm[expr] stays in the tree (Head[InputForm[x]] is InputForm), and the printer does the work. When print_standard meets the head, it increments g_inputform_depth and prints the argument in its linear, re-parseable form. While that depth is non-zero several display-only paths are switched off:
SeriesDataprints as the literalSeriesData[x, x0, {...}, nmin, nmax, den]rather than1 + x + … + O[x]^4.TraditionalForm/StandardFormwrappers are kept, not made transparent.NumberForm,Row,GraphicsandGraphare not given their display rendering.
Strings. print_string_literal quotes strings and escapes ", \, newline, tab and carriage return. An explicit InputForm[...] keeps the quotes even inside Print, whose own traversal otherwise prints strings as bare characters (OutputForm). This was fixed in v0.455. ToString[expr, InputForm] and ToString[expr, StandardForm] go through the same printer (expr_to_string).
Limits. InputForm round-trips within Mathilda: ToExpression[ToString[e, InputForm]] === e. Two spellings differ from Mathematica's. Products print with * before I (3*I + Sqrt[2]), and machine reals in scientific range print as C-style 1.5e+20, which Mathilda's parser reads back but Mathematica would not (it writes 1.5*^20). In the notebook, InputForm suppresses typesetting and shows the text as code. Protected.
Attributes: Protected.
References¶
See also: FullForm, TeXForm, NumberForm, StandardForm, TraditionalForm, HoldForm, Print, SeriesData
- Source:
src/print.c - Specification:
docs/spec/builtins/expression-information.md - Tests:
tests/test_graph.c - Tests:
tests/test_graph_ops.c - Tests:
tests/test_hypergraph.c - Tests:
tests/test_numeric_largearg.c
Notes & additional examples¶
Notes¶
InputForm[expr]printsexprin a linear form the parser can read back: operator syntax (a + b, notPlus[a, b]) with explicit string quotes. UseFullFormto see the internal tree.- It is an inert wrapper: the head stays in the expression, and only the printer
acts on it. Under it,
SeriesData,NumberForm,Rowand theTraditionalForm/StandardFormwrappers lose their display-only rendering. - An explicit
InputForm[...]insidePrintkeeps string quotes (v0.455).Printotherwise shows strings as bare characters.ToString[e, InputForm]gives the same text as aString. - Two spellings differ from Mathematica's. Machine reals in scientific range
print as
1.5e+20, which Mathilda's parser reads back but Mathematica writes as1.5*^20. Products put an explicit*beforeI. - In the notebook,
InputFormsuppresses typesetting and shows the text as code. - See also:
FullForm,ToString,ToExpression,StandardForm.