Generating Unstructured Output

The functions described in "Textual Input and Output Overview" determine how expressions should be formatted when they are printed, but they do not actually cause anything to be printed.

In the most common way of using the Wolfram Language you never in fact explicitly have to issue a command to generate output. Usually, the Wolfram Language automatically prints out the final result that it gets from processing input you gave. Sometimes, however, you may want to get the Wolfram Language to print out expressions at intermediate stages in its operation. You can do this using the function (RefLink[Print, paclet:ref/Print]).

Printing expressions.

(RefLink[Print, paclet:ref/Print]) prints its arguments, with no spaces in between, but with a newline (line feed) at the end:

Print[a,b];Print[c]

This prints a table of the first five integers and their squares:

Do[Print[i," ",i^2],{i,5}]

(RefLink[Print, paclet:ref/Print]) simply takes the arguments you give, and prints them out one after the other, with no spaces in between. In many cases, you will need to print output in a more complicated format. You can do this by giving an output form as an argument to (RefLink[Print, paclet:ref/Print]).

This prints the matrix in the form of a table:

Print[Grid[{{1,2},{3,4}}]]

Here the output format is specified using (RefLink[StringForm, paclet:ref/StringForm]):

Print[StringForm["x = ``, y = ``",a^2,b^2]]

(RefLink[Print, paclet:ref/Print]) also allows mixing of text and graphics:

Print["A sine wave:", Plot[Sin[x], {x, 0, 2π}]]

The output generated by (RefLink[Print, paclet:ref/Print]) is usually given in the standard Wolfram Language output format. You can however explicitly specify that some other output format should be used.

This prints output in Wolfram Language input form:

Print[InputForm[a^2+b^2]]

You should realize that (RefLink[Print, paclet:ref/Print]) is only one of several mechanisms available in the Wolfram Language for generating output. Another is the function (RefLink[Message, paclet:ref/Message]) described in "Messages", used for generating named messages. There are also a variety of lower-level functions described in "Streams and Low-Level Input and Output" which allow you to produce output in various formats both as part of an interactive session, and for files and external programs.

Another command which works exactly like (RefLink[Print, paclet:ref/Print]), but only shows the printed output until the final evaluation is finished, is (RefLink[PrintTemporary, paclet:ref/PrintTemporary]).