Next: Basic Formatting, Previous: format Function, Up: Common Lisp Formatting [Contents][Index]
All directives start with a tilde (‘~’) and end with a single character (upper- or lowercase) that identifies the directive.
(format t "~A" pi) ==> 3.14
Some directives take prefix parameters, which are written immediately following the tilde, separated by commas, and used to control things such as how many digits to print after the decimal point when printing a floating-point number.
(format t "~$" pi) ==> 3.14 (format t "~5$" pi) ==> 3.14159 ^
The values of prefix parameters are either decimal numbers, or characters, written as a single quote followed by the desired character. The value of a prefix parameter can also be derived from the format arguments in two ways:
format
to consume one format argument and
use its value for the prefix parameter;
(format t "~v$" 3 pi) ==> 3.142 (format t "~#$" pi) ==> 3.1 ^
You can omit prefix arguments, but if there are multiple possible prefix arguments, then you must use a comma to skip ones that come before the ones you want to use.
(format t "~,5F" pi) ==> 3.14159 ^
You can also modify the behavior of some directives with a colon and at-sign modifiers, which are placed after any prefix parameters and before the directive’s identifying character. These modifiers change the behavior of the directive in small ways. In some cases you can combine the colon and at-sign modifiers to get both modifications.
(format t "~D" 1000000) ==> 1000000 (format t "~:D" 1000000) ==> 1,000,000 (format t "~@D" 1000000) ==> +1000000 (format t "~:@D" 1000000) ==> +1,000,000 ^
Next: Basic Formatting, Previous: format Function, Up: Common Lisp Formatting [Contents][Index]