为什么SBCL打印这样的Sublis?(Why does SBCL print Sublis like this?)

编程入门 行业动态 更新时间:2024-10-27 17:16:35
为什么SBCL打印这样的Sublis?(Why does SBCL print Sublis like this?)

所以功能:

(defun royal-we () (sublis '((i . we)) '(if I learn lisp I will be pleased)))

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

(IF WE LEARN LISP WE WILL BE PLEASED)

然而,例子之一:

(sublis '((roses . violets) (red . blue)) '(roses are red))

给出输出

(VIOLETS ARE BLUE)

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

So the function:

(defun royal-we () (sublis '((i . we)) '(if I learn lisp I will be pleased)))

The output in SBCL is printed this way:

(IF WE LEARN LISP WE WILL BE PLEASED)

Yet the example one:

(sublis '((roses . violets) (red . blue)) '(roses are red))

gives the output

(VIOLETS ARE BLUE)

Why is SBCL printing the atoms of the list on different lines, unlikeo other distributions like Clisp?

最满意答案

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

除此之外,您会发现,表单也会以类似方式缩进,并且某些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)

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

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

例如,

(format t "~&~@(~{~a~^ ~}~)" '(violets are blue)) Violets are blue

The (if …) list is being handled by the pretty-printer under the assumption that it's (potentially) an actual Lisp form.

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)

You'll find that, among other things, let forms will also be indented similarly, and certain loop symbols will start new lines. There are a few other effects.

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)

BTW, the relevant standards are found … http://www.lispworks.com/documentation/lw60/CLHS/Body/22_b.htm … if you were to, say, want to reprogram it for your purposes.

For just printing data lists, I'd suspect disabling pretty-printing or using FORMAT would probably suffice, though.

eg,

(format t "~&~@(~{~a~^ ~}~)" '(violets are blue)) Violets are blue

更多推荐

本文发布于:2023-08-06 23:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457673.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SBCL   Sublis   print

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!