为什么SBCL会像这样打印Sublis?

Flo*_*ofk 4 lisp sbcl common-lisp

所以功能:

(defun royal-we ()
  (sublis '((i  .  we))
      '(if I learn lisp I will be pleased)))
Run Code Online (Sandbox Code Playgroud)

SBCL中的输出以这种方式打印:

(IF WE
    LEARN
    LISP
    WE
    WILL
    BE
    PLEASED)
Run Code Online (Sandbox Code Playgroud)

然而一个例子:

(sublis '((roses . violets)  (red . blue))
        '(roses are red))
Run Code Online (Sandbox Code Playgroud)

给出输出

(VIOLETS ARE BLUE)
Run Code Online (Sandbox Code Playgroud)

为什么SBCL在不同的行上打印列表的原子,不像其他发行版如Clisp?

BRP*_*ock 9

这个(if …)列表由漂亮的打印机处理,假设它(可能)是一个实际的Lisp形式.

CL-USER> (setf *print-pretty* nil)
NIL
CL-USER> '(if 1 2 3)
(IF 1 2 3)
CL-USER> (setf *print-pretty* t)
T
CL-USER> '(if 1 2 3)
(IF 1
    2
    3)
Run Code Online (Sandbox Code Playgroud)

您会发现,除其他外,let表单也将以类似方式缩进,并且某些loop符号将开始新行.还有一些其他影响.

CL-USER> '(loop for thing in stuff with boo = 4 count mice)
(LOOP FOR THING IN STUFF
      WITH BOO = 4
      COUNT MICE)
CL-USER> '(let 1 2 3)
(LET 1
  2
  3)
CL-USER> '(defun 1 nil 2 3)
(DEFUN 1 () 2 3)
CL-USER> (setf *print-pretty* nil)
NIL
CL-USER> '(defun 1 nil 2 3)
(DEFUN 1 NIL 2 3)
Run Code Online (Sandbox Code Playgroud)

顺便说一句,相关的标准被发现... http://www.lispworks.com/documentation/lw60/CLHS/Body/22_b.htm ...如果你想要为你的目的重新编程它.

对于打印数据列表,我怀疑禁用漂亮打印或使用FORMAT可能就足够了.

例如,

 (format t "~&~@(~{~a~^ ~}~)" '(violets are blue))
 Violets are blue
Run Code Online (Sandbox Code Playgroud)