The idiomatic way to long multi-station constants (or vars) in Lisp code

What is the idiomatic way to insert long vars or constants into Common Lisp code? Is there something like HEREDOC in unix shell or some other languages ​​to eliminate the indentation within lines?

For example:

(defconstant +help-message+ 
             "Blah blah blah blah blah
              blah blah blah blah blah
              some more more text here")
; ^^^^^^^^^^^ this spaces will appear - not good

      

And writing this path is kind of ugly:

(defconstant +help-message+ 
             "Blah blah blah blah blah
blah blah blah blah blah
some more more text here")

      

How should we write this. If there is any way you don't need to avoid quotes, that would be even better.

+3


source to share


3 answers


I don't know about idioms, but format

can do it for you. (of course. format

can do anything.)

See Section 22.3.9.3 Hyper Secretary, New Tilda Line. Undecorated, it removes both the newline and subsequent spaces. If you want to keep the newline, use the modifier @

:



(defconstant +help-message+
   (format nil "Blah blah blah blah blah~@
                blah blah blah blah blah~@
                some more more text here"))

CL-USER> +help-message+
"Blah blah blah blah blah
blah blah blah blah blah
some more more text here"

      

+4


source


There is no such thing.

Usually indentation:

(defconstant +help-message+ 
  "Blah blah blah blah blah
blah blah blah blah blah
some more more text here")

      



Maybe use a reader macro or eval. Sketch:

(defun remove-3-chars (string)
  (with-output-to-string (o)
    (with-input-from-string (s string)
      (write-line (read-line s nil nil) o)
      (loop for line = (read-line s nil nil)
            while line
            do (write-line (subseq line 3) o)))))

(defconstant +help-message+
  #.(remove-3-chars
  "Blah blah blah blah blah
   blah blah blah blah blah
   some more more text here"))

CL-USER 18 > +help-message+
"Blah blah blah blah blah
blah blah blah blah blah
some more more text here
"

      

You will need more polish ... You can use "line trimming" or similar.

+2


source


I sometimes use this form:

(concatenate 'string "Blah blah blah"
                     "Blah blah blah"
                     "Blah blah blah"
                     "Blah blah blah")

      

+1


source







All Articles