Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help understanding this line in lisp

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

The dolist makes it go through every element of the list *db* with the variable cd right?

and ~a means print it in a more readable form, but these two confuse me.

~{ ~} does this mean anything in between will be the way every element of *db* will be formatted?

What's the : in ~{~a:?

like image 358
neil Avatar asked Dec 12 '25 16:12

neil


1 Answers

[The] iteration directive ~{ [...] tells FORMAT to iterate over the elements of a list or over the implicit list of the format arguments. 1

The : isn't a format directive, it's just printed verbatim in after each element:

> (format t "~{~a: ~}" '(foo bar))
FOO: BAR: 
like image 151
Fred Foo Avatar answered Dec 14 '25 21:12

Fred Foo