Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

11. Printing Text with the format Function > Printing Multiple Lines of Output

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 only one line between the outputted numbers. The first fresh-line starts a new line; the second fresh-line is simply ignored.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint