Lisp 在一行上漂亮地打印对象
Lisp Pretty Print Object on One Line
我正在将列表的列表写入 .dot 文件以生成树。看起来 lisp 中漂亮的打印机在输出中插入了新行,所以当我执行点文件时,新行使得生成的图形难以读取。
我看过 format
文档,但我还不能很好地利用它。
这是一个应该打印的示例列表:
(((TOWER 'D 'C ^LEFT '0 ^RIGHT '2 ^BOTTOM '4 ^TOP '8)
(TOWER 'C 'B ^LEFT '0 ^RIGHT '2 ^BOTTOM '2 ^TOP '6)
(TOWER 'B 'A ^LEFT '0 ^RIGHT '2 ^BOTTOM '0 ^TOP '4) (ON 'D 'C)
(ON 'C 'B) (ON 'B 'A))
((TOWER 'D 'C ^LEFT '0 ^RIGHT '2 ^BOTTOM '4 ^TOP '8)
(TOWER 'C 'B ^LEFT '0 ^RIGHT '2 ^BOTTOM '2 ^TOP '6)
(TOWER 'B 'A ^LEFT '0 ^RIGHT '2 ^BOTTOM '0 ^TOP '4) (ON 'D 'C)
(ON 'C 'B) (ON 'B 'A))
((TOWER 'D 'C ^LEFT '0 ^RIGHT '2 ^BOTTOM '4 ^TOP '8)
(TOWER 'C 'B ^LEFT '0 ^RIGHT '2 ^BOTTOM '2 ^TOP '6)
(TOWER 'B 'A ^LEFT '0 ^RIGHT '2 ^BOTTOM '0 ^TOP '4) (ON 'D 'C)
(ON 'C 'B) (ON 'B 'A))
((TOWER 'D 'C ^LEFT '0 ^RIGHT '2 ^BOTTOM '4 ^TOP '8)
(TOWER 'C 'B ^LEFT '0 ^RIGHT '2 ^BOTTOM '2 ^TOP '6)
(TOWER 'B 'A ^LEFT '0 ^RIGHT '2 ^BOTTOM '0 ^TOP '4) (ON 'D 'C)
(ON 'C 'B) (ON 'B 'A))
((TOWER 'D 'C ^LEFT '0 ^RIGHT '2 ^BOTTOM '4 ^TOP '8)
(TOWER 'C 'B ^LEFT '0 ^RIGHT '2 ^BOTTOM '2 ^TOP '6)
(TOWER 'B 'A ^LEFT '0 ^RIGHT '2 ^BOTTOM '0 ^TOP '4) (ON 'D 'C)
(ON 'C 'B) (ON 'B 'A))
((TOWER 'D 'C ^LEFT '0 ^RIGHT '2 ^BOTTOM '4 ^TOP '8)
(TOWER 'C 'B ^LEFT '0 ^RIGHT '2 ^BOTTOM '2 ^TOP '6)
(TOWER 'B 'A ^LEFT '0 ^RIGHT '2 ^BOTTOM '0 ^TOP '4) (ON 'D 'C)
(ON 'C 'B) (ON 'B 'A)))
以下是将列表打印到文件的方式:
(((TOWER 'D 'C
^LEFT '0
^RIGHT '2
^BOTTOM '4
^TOP '8)
(TOWER 'C 'B
^LEFT '0
^RIGHT '2
^BOTTOM '2
^TOP '6)
(TOWER 'B 'A
^LEFT '0
^RIGHT '2
^BOTTOM '0
^TOP '4)
(ON 'D 'C)
(ON 'C 'B)
(ON 'B 'A))
((TOWER 'D 'C
^LEFT '0
^RIGHT '2
^BOTTOM '4
^TOP '8)
(TOWER 'C 'B
^LEFT '0
^RIGHT '2
^BOTTOM '2
^TOP '6)
(TOWER 'B 'A
^LEFT '0
^RIGHT '2
^BOTTOM '0
^TOP '4)
(ON 'D 'C)
(ON 'C 'B)
(ON 'B 'A))
((TOWER 'D 'C
^LEFT '0
^RIGHT '2
^BOTTOM '4
^TOP '8)
(TOWER 'C 'B
^LEFT '0
^RIGHT '2
^BOTTOM '2
^TOP '6)
(TOWER 'B 'A
^LEFT '0
^RIGHT '2
^BOTTOM '0
...
...
...
应该使用哪些 format
指令来获得格式正确的输出?
这是我使用的代码
(format stream "~A [shape=record, label=\"{~A|~A|~A}\"];~%" a b c d)
如果您将 *print-right-margin*
设置为一个非常大的数字,漂亮的打印机将不会插入任何换行符。
默认为 nil
表示设备(例如,您的显示器)的宽度。
我正在将列表的列表写入 .dot 文件以生成树。看起来 lisp 中漂亮的打印机在输出中插入了新行,所以当我执行点文件时,新行使得生成的图形难以读取。
我看过 format
文档,但我还不能很好地利用它。
这是一个应该打印的示例列表:
(((TOWER 'D 'C ^LEFT '0 ^RIGHT '2 ^BOTTOM '4 ^TOP '8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'B) (ON 'B 'A)))
以下是将列表打印到文件的方式:
(((TOWER 'D 'C
^LEFT '0
^RIGHT '2
^BOTTOM '4
^TOP '8)
(TOWER 'C 'B
^LEFT '0
^RIGHT '2
^BOTTOM '2
^TOP '6)
(TOWER 'B 'A
^LEFT '0
^RIGHT '2
^BOTTOM '0
^TOP '4)
(ON 'D 'C)
(ON 'C 'B)
(ON 'B 'A))
((TOWER 'D 'C
^LEFT '0
^RIGHT '2
^BOTTOM '4
^TOP '8)
(TOWER 'C 'B
^LEFT '0
^RIGHT '2
^BOTTOM '2
^TOP '6)
(TOWER 'B 'A
^LEFT '0
^RIGHT '2
^BOTTOM '0
^TOP '4)
(ON 'D 'C)
(ON 'C 'B)
(ON 'B 'A))
((TOWER 'D 'C
^LEFT '0
^RIGHT '2
^BOTTOM '4
^TOP '8)
(TOWER 'C 'B
^LEFT '0
^RIGHT '2
^BOTTOM '2
^TOP '6)
(TOWER 'B 'A
^LEFT '0
^RIGHT '2
^BOTTOM '0
...
...
...
应该使用哪些 format
指令来获得格式正确的输出?
这是我使用的代码
(format stream "~A [shape=record, label=\"{~A|~A|~A}\"];~%" a b c d)
如果您将 *print-right-margin*
设置为一个非常大的数字,漂亮的打印机将不会插入任何换行符。
默认为 nil
表示设备(例如,您的显示器)的宽度。