lispcommon-lisp

How do I use format in Lisp without it addint newlines/indentation when formatting an array?


Here's my issue:

  1. I am using format on an array of long strings, and, apparently by default when using the ~s directive, it adds newlines and two spaces of indentation.
  2. This is really great for human readers of course, but in this context I don't want any of this stuff added.
  3. Can anyone offer some guidance on how I might direct format not to do this? Furthermore, I'd love to hear about your favorite documentation links for format directives: I am intimidated.

Additional context:

  1. My application in this case is part of a system to return text via Hunchentoot, i.e. my code is a handler that formats the array then serves it to the user via HTTP. Format is used in the Hunchentoot documentation and by other users, but do let me know if this is the wrong approach.
  2. Here's a demonstration:
(let ((value #("a800150c-fed9-4c2a-9de4-c34dbe5b9f83"
               "a99c023a-5d29-40cc-ad49-1745d3e2bfe4"
               "f65dff1f-3719-41f5-9735-6ef77c5816b8"
               "c463d1a3-f17b-4e8a-a246-a0cc1805c8cf")))
   (format nil "~s" value))

Yields:

"#(\"a800150c-fed9-4c2a-9de4-c34dbe5b9f83\" \"a99c023a-5d29-40cc-ad49-1745d3e2bfe4\"
  \"f65dff1f-3719-41f5-9735-6ef77c5816b8\" \"c463d1a3-f17b-4e8a-a246-a0cc1805c8cf\")"

Note the newlines and two spaces of indentation.

Let me know if you have questions! Thank you for the help!


Solution

  • You need to turn off the pretty printer by setting *print-pretty* to false:

    CL-USER> (let ((*print-pretty* nil)
                   (value #("a800150c-fed9-4c2a-9de4-c34dbe5b9f83" "a99c023a-5d29-40cc-ad49-1745d3e2bfe4" "f65dff1f-3719-41f5-9735-6ef77c5816b8" "c463d1a3-f17b-4e8a-a246-a0cc1805c8cf")))
              (format nil "~s" value))
    "#(\"a800150c-fed9-4c2a-9de4-c34dbe5b9f83\" \"a99c023a-5d29-40cc-ad49-1745d3e2bfe4\" \"f65dff1f-3719-41f5-9735-6ef77c5816b8\" \"c463d1a3-f17b-4e8a-a246-a0cc1805c8cf\")"