Leonardo Varuzza <varuzza@gmail.com> wrote:
+---------------
| If I want to print a list with the values separated by commas I can
| use this handy format recipe:
|
| (format t "~{~a~^,~}" '(1 2 3))
|
| But how I can reproduce this for a Tab Delimited printing?
| Or, how to embed a tab character in a lisp string?
+---------------
Several ways:
1. Tabs aren't "special" in CL strings; simply insert it:
; A #\Tab is here ---v
> (format t "~&~{~a~^ ~}" '(1 2 3))
1 2 3
NIL
>
2. If you don't need "real" tabs, just tabular spacing,
then you can use the "~T" FORMAT control:
> (format t "~&~{~a~^~0,8t~}" '(1 2 3))
1 2 3
NIL
>
3. If you need real #\Tab characters but don't want to have
obscure bugs because of unexpected whitespace reformatting
[e.g., some editors "helpfully" silently replace spaces
by tabs or vice-versa under certain random conditions],
then you can do something like this:
> (let ((fmt (format nil "~~&~~{~~a~~^~c~~}" #\Tab)))
(format t fmt '(1 2 3)))
1 2 3
NIL
>
-Rob
p.s. I have tried to have the only tabs in this reply be
only the five instances that *should* be there in the example
codes & outputs above, but my editor and/or the netnews system
may tweak the result between me & thee. If so, then my most
abject apologies in advance...
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607