You can also use the more modern write
. I'm not a huge fan of format
because of its terse sub language, which usually is interpreted. Note that a good implementation might be able to compile format directives to more efficient code. I use FORMAT mostly when it makes complex code shorter, but not to output plain objects or things like single carriage returns...
Common Lisp includes three or more generations of text I/O APIs:
- the old s-expression printing routines
- the specialized and generalized stream IO functions
- the complex formatter, based on earlier Fortran and/or Multics IO formatters
- the Generic Function to print objects
- the pretty printer
Additionally there are semi-standard CLOS-based IO implementations like Gray Streams.
Each might have its purpose and none is going away soon...
CL-USER 54 > (let ((label "Social security number")
(colon ": ")
(social-security-number '|7537 DD 459234957324 DE|))
(terpri)
(princ label)
(princ colon)
(princ social-security-number)
(write-char #\newline)
(write-string label)
(write-string colon)
(write social-security-number :escape nil)
(format t "~%~A~A~A" label colon social-security-number)
)
Social security number: 7537 DD 459234957324 DE
Social security number: 7537 DD 459234957324 DE
Social security number: 7537 DD 459234957324 DE
(format ... "~%")
is just overkill when I know exactly what I need and I don't need format to interpret it for me. Also FRESH-LINE as opposed to(format ... "~&")
. – Parodic