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 Functi... > Control Sequences for Printing Lisp ...

Control Sequences for Printing Lisp Values

Any Lisp value can be printed with the print or prin1 command. To print a value for humans, without any delimiters, we can use the princ command:

> (prin1 "foo")
"foo"
> (princ "foo")
foo

We can use the ˜s and ˜a control sequences with format to produce the same behavior as prin1 and princ. When used with format, the ˜s control sequence includes appropriate delimiters. The ˜a shows the value, without delimiters, for humans to read:

> (format t "I am printing ˜s in the middle of this sentence." "foo")
I am printing "foo" in the middle of this sentence.
> (format t "I am printing ˜a in the middle of this sentence." "foo")
I am printing foo in the middle of this sentence.

We can adjust the behavior of these control sequences even further by entering parameters within the control sequence. For instance, we can place a number n in front of the a or s to indicate that the value should be padded with blank spaces on the right. The format command will then add spaces until the total width of the value is n.


  

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