next up previous contents
Next: Boolean Expressions Up: Exploring the Basics Previous: The length Function

Simple Output

In order to display the results generated by your programs, Darwin includes several formatting commands designed to give you control over where and how information is sent to the terminal. The simplest of these are the print (pretty print) and lprint (linear print) commands.

> square := [[1,2], [3,4]]:
> print('This is a pretty print of a square matrix', square);
This is a pretty print of a square matrix
 1 2
 3 4
> lprint('This is a linear print of a square matrix', square);
This is a linear print of a square matrix [[1, 2], [3, 4]]
> lprint(72483734723897348372847382);           # big numbers are printed 
                                                #   in exponential notation.
> print('This isn\''t difficult to use');       # To print a single quote, 
                                                #   use the \'' sequence.
This isn't difficult to use
> print('A two for one sale on backslashes \\');
A two for one sale on backslashes \
> lprint('A sequence of expressions ', 2, xyz, 2^5);
A sequence of expressions  2 xyz 32
Both commands will accept an arbitrary length sequence of expressions as long as the elements are separated by commas. The lprint does not place a carriage return and newline after displaying each expression whereas the print command does. The behaviour of the print statement is dependent on the type of the expression. If the expression is of type matrix and it has dimension two, as is the case with variable square above, it prints out the square array in a graphical manner preserving this structure. We will see in Chapter [*] - Overloading, Polymorphism and Object Orientation that print can be extended to ``pretty print'' any data structure.

Gaston Gonnet