Sometimes I like to output some text with (format t ..).
To prevent long unreadable format-strings in source code, and get the output easily aligned, I use (format t (concatenate 'string ....).
Example:
(format t (concatenate 'string
"some output~%"
" error-msg: ~a~%"
" uiop-cwd: ~a~%"
" uiop-file-exists: ~a~%")
"error foo"
(uiop:getcwd)
(uiop:file-exists-p "hello_world.bmp"))
Is there a more idiomatic and at-compile-time way to do the same in Common Lisp?
Here is an equivalent format string that makes use of the Tilde newline format directive, which ignores the following newline and spaces (until the next visible character). In order to indent with spaces as you did, I wrote the forced newline ~% before the spaces:
(format t
"some output~
~% error-msg: ~a~
~% uiop-cwd: ~a~
~% uiop-file-exists: ~a~%"
"error foo"
(uiop:getcwd)
(uiop:file-exists-p "hello_world.bmp"))
(NB. This is a single string so there is no concatenation to be done at compile-time.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With