4
votes

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?

1
There are no newlines in the resulting list, it's just how SBCL prints it. CCL and CLISP for example print the list on a single line. - uselpa
O, thanks :) I appreciate the quick answer. Do you know why it prints that way? - Floofk
Sorry no I don't use SBCL I had a quick look at the documentation and I didn't find any parameter that would lead to this. Somebody more knowledgeable in SBCL might be able to explain this. - uselpa
Thanks for the help :) I'll edit my question. - Floofk
It might have something to do with Common Lisp indendation for certain symbols when found in code, such as for the special operator if. - acelent

1 Answers

9
votes

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