Formatted Output with format

Example → Output Aesthetic (like princ) (format nil "~a" "hi") → hi Standard (like prin1, readable) (format nil "~s" "hi") → "hi" (format nil "~5,'0d" 42) → 00042

(format nil "~:d" 1234567) → 1,234,567 Binary, octal, hex (format nil "~b" 10) → 1010 (format nil "~,2f" pi) → 3.14 ~e / ~g / ~$ Exponential / general / monetary (format nil "~$" 3.14159) → 3.14 Number in words (format nil "~r" 42) → forty-two (format nil "~:r" 3) → third (format nil "~@r" 1999) → MCMXCIX Newline / fresh line Tabulate to a column Iterate over a list

(format nil "~{~a~^, ~}" '(1 2 3)) → 1, 2, 3 Exit iteration if no more args Conditional by index

(format nil "~[zero~;one~;two~]" 1) → one False/true choice (format nil "~:[no~;yes~]" t) → yes

(format nil "~d item~:p" 3) → 3 items (format nil "~:(~a~)" "hello world") → Hello World Skip an argument (format nil "~10<~a~>" "hi") → hi Call a custom function

(format t "Hello, ~a!~%" "World")         ; t = *standard-output*
(format nil "~a" 42)                      ; nil = return a string
(format *error-output* "warning~%")       ; any stream
(format t "~&~{~a: ~a~%~}" '(:name "Ana" :age 30))   ; iterate over a plist in pairs
(format nil "~a has ~d apple~:p" "Bo" 1)             ; "Bo has 1 apple"
(format nil "~10a|~10@a|" "left" "right")            ; padded columns
(format nil "~,,'.,4:d" 12345678)                    ; "1234.5678" (custom grouping)