Why does SBCL print Sublis like this?

So the function:

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

The output in SBCL is printed as follows:

(IF WE
    LEARN
    LISP
    WE
    WILL
    BE
    PLEASED)

But there is one example:

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

gives way

(VIOLETS ARE BLUE)

Why does SBCL print list atoms on different lines, unlike other distributions like Clisp?

+4
source share
1 answer

The list is (if …)processed by a pretty printer under the assumption that it is (potentially) an actual form of 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)

You will find that, among other things, the forms letwill also indent similarly, and some characters loopwill start new lines. There are a few more 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, ... http://www.lispworks.com/documentation/lw60/CLHS/Body/22_b.htm... , , .

, FORMAT, , .

,

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

Source: https://habr.com/ru/post/1618316/


All Articles