I'm beginning to write me some Common Lisp and am just getting the hang of consing things together and formatting them.
Let's suppose I have an alist, like this:
(defvar *map* '((0 . "zero") (1 . "one") (2 . "two")))
How do I format it like this?
0: zero
1: one
2: two
I was thinking something like (format t "~{~{~a: ~a~}~%~}" *map*)
, but that gives an error because "zero" isn't a list and you can't take the car of it.
Of course, doing (format t "~{~a~%~}" *map*)
prints
(0 . "zero")
(1 . "one")
(2 . "two")
like it's supposed to, but it's not quite what I want. Is there a better way to do this than just (dolist (entry *mapping*) (format t "~a: ~a~%" (car entry) (cdr entry)))
?