Printing Multiple Lines of Output

Common Lisp has two different commands for starting a new line during printing. The first, terpri, simply tells Lisp to terminate the current line and start a new one for printing subsequent output. For example, we can print two numbers on different lines like so:

> (progn (princ 22)
         (terpri)
         (princ 33))
22
33

We can also start a new line with fresh-line. This command will start a new line, but only if the cursor position in the REPL isn’t already at the very front of a line. Let’s look at some examples:

> (progn (princ 22)
         (fresh-line)
         (princ 33))
22
33
> (progn (princ 22)
         (fresh-line)
         (fresh-line)
         (princ 33))
22
33

As you can see, placing two fresh-line statements between the two princ calls resulted in Lisp printing ...

Get Land of Lisp now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.