漂亮的打印机不仅仅由 *print-pretty* 控制。例如,查看与SBCL 中的 *print-right-margin*的交互(在 SLIME 下):
CL-USER> (pprint '(let ((a 1) (b 2) (c 3)) (+ a b c)))
(LET ((A 1) (B 2) (C 3))
(+ A B C))
; No value
CL-USER> (let ((*print-right-margin* 10))
(pprint '(let ((a 1) (b 2) (c 3)) (+ a b c))))
(LET ((A
1)
(B
2)
(C
3))
(+ A B
C))
; No value
CL-USER> (let ((*print-right-margin* 20))
(pprint '(let ((a 1) (b 2) (c 3)) (+ a b c))))
(LET ((A 1)
(B 2)
(C 3))
(+ A B C))
; No value
只需设置该变量,您也许可以获得满意的结果,但通常您会想看看22.2 The Lisp Pretty Printer。漂亮的打印函数有很多地方可以放置可选的换行符等,它们的放置位置取决于很多东西(比如 *print-right-margin* 和 *print-miser-width*)。22.2.2 使用 Pretty Printer 示例中有一些使用 Pretty Printer 格式化 Lisp 源代码的示例。引用的内容太多了,但它显示了以下漂亮的打印代码如何根据上下文生成所有这些输出:
(defun simple-pprint-defun (*standard-output* list)
(pprint-logical-block (*standard-output* list :prefix "(" :suffix ")")
(write (first list))
(write-char #\Space)
(pprint-newline :miser)
(pprint-indent :current 0)
(write (second list))
(write-char #\Space)
(pprint-newline :fill)
(write (third list))
(pprint-indent :block 1)
(write-char #\Space)
(pprint-newline :linear)
(write (fourth list))))
(DEFUN PROD (X Y)
(* X Y))
(DEFUN PROD
(X Y)
(* X Y))
(DEFUN
PROD
(X Y)
(* X Y))
;;; (DEFUN PROD
;;; (X Y)
;;; (* X Y))