27.4 Format Directive Interface

The primary interface to operations for dynamically determining the arrangement of output is provided through the functions above. However, an additional interface is provided via a set of format directives because, as shown by the examples in this section and the next, format strings are typically a much more compact way to specify pretty printing. In addition, without such an interface, one would have to abandon the use of format when interacting with the pretty printer.

As examples of the convenience of specifying pretty printing with format strings, consider the functions pprint-defun and pprint-let used as examples in the last section. They can be more compactly defined as follows. The function pprint-vector cannot be defined using format, because the data structure it traverses is not a list. The function pprint-tabular is inconvenient to define using format, because of the need to pass its tabsize argument through to a ~:T directive nested within an iteration over a list.

(defun pprint-defun (list)
  (format t "~:<~W ~@_~:I~W ~:_~W~1I ~_~W~:>" list))

(defun pprint-let (list)
  (format t "~:<~W~̂ ~:<~@{~:<~@{~W~̂ ~_~}~:>~̂ ~:_~}~:>~1I~
                ~@{~̂ ~_~W~}~:>"
          list))