Puzzler3141
Puzzler3141

Reputation: 1682

Formatting %10t wrong from Practical Common LISP

Here's the link to the page: Chapter 3, Practical: A Simple Database. Essentially I have a database of lists with four values that I want to display. This is done with

(defun dump-db ()
  (dolist (cd *db*)
    (format t "~{~a:~10t~a~%~}~%" cd)))

The only problem is that the output isn't quite right:

TITLE:  Home
ARTIST:   Dixie Chicks
RATING:   9
RIPPED:   T
... (Shortened for brevity)

For some reason "Home" doesn't start in the 10th column, can someone tell me why? I'm using SBCL to run the code, most recent version.

Upvotes: 1

Views: 135

Answers (2)

Rainer Joswig
Rainer Joswig

Reputation: 139311

Two things:

Remark:

0] says that you are in a debug loop. Get out of it. help shows the command.

Problem:

Maybe it is a bug with SBCL. You might want to discuss it on its mailing list. That would be useful.

My guess:

* (dump-db)
^^ <- 2 characters
TITLE:  Home
^^^^^^^^ <- 8 characters, 2 less than specified

If you are back on the toplevel, you then see that the SBCL prompt is * - which is two characters long. Now you see that the first indentation of Home is two characters short. So the Lisp printer thinks that the two characters of the prompt are on the same line and then position ten is on the next eight characters - two less than needed. Maybe the Lisp printer is confused by some way the REPL is programmed. The next lines then are fine.

Btw., this does not happen with LispWorks or Clozure CL.

Upvotes: 3

Puzzler3141
Puzzler3141

Reputation: 1682

0] (dump-db)    
TITLE:  Home
ARTIST:   Dixie Chicks
RATING:   9
RIPPED:   T

TITLE:    Fly
ARTIST:   Dixie Chicks
RATING:   8
RIPPED:   T

TITLE:    Roses
ARTIST:   Kethy Mattea
RATING:   7
RIPPED:   T


NIL
0] (dump-db)
TITLE:    Home
ARTIST:   Dixie Chicks
RATING:   9
RIPPED:   T

TITLE:    Fly
ARTIST:   Dixie Chicks
RATING:   8
RIPPED:   T

TITLE:    Roses
ARTIST:   Kethy Mattea
RATING:   7
RIPPED:   T


NIL
0] 

It appears to have fixed itself... I'm not sure how or why (questions I would still love an answer to) though.

Upvotes: 0

Related Questions