Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 949
Floofk Avatar asked Jan 07 '23 02:01

Floofk


1 Answers

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
like image 65
BRPocock Avatar answered Feb 01 '23 21:02

BRPocock