Another example would be to print every element of list delimited with commas, which can be done using the , and } directives: (let ((groceries '(eggs bread butter carrots))) (format t "~{~A~^, ~}.~%" groceries) ; Prints in uppercase (format t "~:(~{~A~^, ~}~).~%" groceries)) ; Capitalizes output ;; prints: EGGS, BREAD, BUTTER, CARROTS. ;; prints: Eggs, Bread, Butter, Carrots. Note that not only is the list of values iterated over directly by format, but the commas correctly are printed between items, not after them. A yet more complex example would be printing out a list using customary English phrasing: (let ((template "The lucky winners were:~#[ none~; ~S~; ~S and ~S~ ~:;~@{~#[~; and~] ~S~^,~}~].")) (format nil template) ;; ⇒ "The lucky winners were: none." (format nil template 'foo) ;; ⇒ "The lucky winners were: FOO." (format nil template 'foo 'bar) ;; ⇒ "The lucky winners were: FOO and BAR." (format nil template 'foo 'bar 'baz) ;; ⇒ "The lucky winners were: FOO, BAR, and BAZ." (format nil template 'foo 'bar 'baz 'quux) ;; ⇒ "The lucky winners were: FOO, BAR, BAZ, and QUUX." ) The ability to define a new directive through ~/functionName/ provides the means for customization. The next example implements a function which prints an input string either in lowercase, uppercase or reverse style, permitting a configuration of the number of repetitions, too. (defun mydirective (destination format-argument colon-modifier-supplied-p at-sign-modifier-supplied-p &optional (repetitions 1)) "This function represents a callback suitable as a directive in a ``format'' invocation, expecting a string as its FORMAT-ARGUMENT to print REPETITIONS number of times to the DESTINATION. --- The COLON-MODIFIER-SUPPLIED-P and AT-SIGN-MODIFIER-SUPPLIED-P flags expect a generalized Boolean each, being the representatives of the ``:'' and ``@'' modifiers respectively. Their influence is defined as follows: - If no modifier is set, the FORMAT-ARGUMENT is printed without further modifications. - If the colon modifier is set, but not the at-sign modifier, the FORMAT-ARGUMENT is converted into lowercase before printing. - If the at-modifier is set, but not the colon-modifier, the FORMAT-ARGUMENT is converted into uppercase before printing. - If both modifiers are set, the FORMAT-ARGUMENT is reversed before printing. --- The number of times the FORMAT-ARGUMENT string is to be printed is determined by the prefix parameter REPETITIONS, which must be a non-negative integer number and defaults to one." (declare (type (or null (eql T) stream string) destination)) (declare (type T format-argument)) (declare (type T colon-modifier-supplied-p)) (declare (type T