Lisp代码中长多字符串常量(或变量)的惯用方法

Lisp代码中长多字符串常量(或变量)的惯用方法,lisp,common-lisp,heredoc,Lisp,Common Lisp,Heredoc,在公共Lisp代码中插入长多字符串变量或常量的惯用方法是什么? 在unix shell或其他一些语言中是否有类似于herdoc的东西来消除字符串文本中的缩进空格 例如: (defconstant +help-message+ "Blah blah blah blah blah blah blah blah blah blah some more more text here") ; ^^^^^^^^^^^ thi

在公共Lisp代码中插入长多字符串变量或常量的惯用方法是什么? 在unix shell或其他一些语言中是否有类似于herdoc的东西来消除字符串文本中的缩进空格

例如:

(defconstant +help-message+ 
             "Blah blah blah blah blah
              blah blah blah blah blah
              some more more text here")
; ^^^^^^^^^^^ this spaces will appear - not good
这样写有点难看:

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

我们应该怎么写。如果有任何方法,当你不需要转义引号时,它会更好。

没有这样的事情

压痕通常为:

(defconstant +help-message+ 
  "Blah blah blah blah blah
blah blah blah blah blah
some more more text here")
可能使用读卡器宏或读取时间评估。草图:

(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
"

需要更多的抛光。。。您可以使用“string trim”或类似功能。

我不知道惯用语,但
格式可以为您做到这一点。(当然。
format
可以做任何事情。)

参见Hyperspec第22.3.9.3节,波浪新线。未修饰,它同时删除换行符和后续空格。如果要保留换行符,请使用
@
修饰符:

(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"

我有时使用这种形式:

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

去年,我曾考虑过制作类似的宏,但如果有人在其他编辑器中使用不同的缩进设置编辑代码,它会破坏一切。谢谢,这看起来是合理的做法。@coredump,对于常量字符串,您可以使用#。(如中所示)。这会给你:“废话废话废话废话废话废话废话废话废话废话废话废话废话”,没有新词。