From: Francogrex on
I knew how to do this once now I forgot, I want to output tab
separated values in a format with an iterator:
(with-open-file (stream "c:/tabout.txt" :direction :output)
(format stream "~{~S~T ~}" (list 1 2 3 4 5)))

However this is only giving some spaces bewteen the values in the file
and not tabs (note I work on windows OS).
From: Pascal J. Bourguignon on
Francogrex <franco(a)grex.org> writes:

> I knew how to do this once now I forgot, I want to output tab
> separated values in a format with an iterator:
> (with-open-file (stream "c:/tabout.txt" :direction :output)
> (format stream "~{~S~T ~}" (list 1 2 3 4 5)))
>
> However this is only giving some spaces bewteen the values in the file
> and not tabs (note I work on windows OS).

Yes. This is because the ASCII code 9 is a control code that
corresponds to NO CHARACTER in the base character set defined by the
Common Lisp standard. A good reason for this is that there is nothing
such as a TAB ASCII code on some computers or devices. For example,
if you offered remote access on your MS-Windows computer to let me
connect to your lisp and receive this list of integers formated, I
would connect with my faithful 3278 model 5 terminal, and your
terminal driver would have to convert anything your program sends to
EBCDIC, where there's no code for a "TAB".

Actually, even on displays where you can write text encoded in ASCII,
ISO-8859-1 or any Unicode encoding, there's no guarantee that these
devices will handle the CONTROL CODE 9 in any meaningful way anymore
that they would handle the iso6429 CONTROL CODE sequence 27 91 49 69
(which is also made of ASCII CONTROL CODES!).


So now you have two solutions:

- either your file format calls for a byte valued 9 in it, therefore
it is not a text file, and you should open it in binary, and convert
your strings into the encoding required by this file format
yourself (an alternative is to use non-standard ambivalent streams).

- or you just want to align your numbers on columns, and for this,
either let the CL implementation do what it knows it can do on the
target platform and device, praying that it will just use spaces,
because this is what is specified by the standard, or use spaces
explicitely yourself to align your data:

(format stream "~{~10D~}" (list 1 2 3 4 5))


--
__Pascal Bourguignon__ http://www.informatimago.com/
From: Barry Fishman on
Francogrex <franco(a)grex.org> writes:
> I knew how to do this once now I forgot, I want to output tab
> separated values in a format with an iterator:
> (with-open-file (stream "c:/tabout.txt" :direction :output)
> (format stream "~{~S~T ~}" (list 1 2 3 4 5)))
>
> However this is only giving some spaces bewteen the values in the file
> and not tabs (note I work on windows OS).

Looking up ~T format control in the hyperspec:

http://www.lispworks.com/documentation/HyperSpec/Body/22_cfa.htm

you would see it does not produce tab characters, but spaces to
to move to a specified column. The default is to produce a single
space.

If you want tabs in the output you need to put them directly
in the format spec, or indirectly by some means like:

(let ((fspec (format nil "~~{~~s~c~~}" #\tab)))
(with-open-file (stream "c:/tabout.txt" :direction :output)
(format stream fspec (list 1 2 3 4 5)))

--
Barry Fishman
From: Thomas A. Russ on
Francogrex <franco(a)grex.org> writes:

> I knew how to do this once now I forgot, I want to output tab
> separated values in a format with an iterator:
> (with-open-file (stream "c:/tabout.txt" :direction :output)
> (format stream "~{~S~T ~}" (list 1 2 3 4 5)))

The simplest answer is to put a literal tab character directly into the
format string where you want it. In Emacs you would do this with either
C-Q Tab or C-Q C-I

Or you can just copy the following format string:

"~{~S ~}"

--
Thomas A. Russ, USC/Information Sciences Institute
From: Pascal J. Bourguignon on
Barry Fishman <barry_fishman(a)acm.org> writes:

> Francogrex <franco(a)grex.org> writes:
>> I knew how to do this once now I forgot, I want to output tab
>> separated values in a format with an iterator:
>> (with-open-file (stream "c:/tabout.txt" :direction :output)
>> (format stream "~{~S~T ~}" (list 1 2 3 4 5)))
>>
>> However this is only giving some spaces bewteen the values in the file
>> and not tabs (note I work on windows OS).
>
> Looking up ~T format control in the hyperspec:
>
> http://www.lispworks.com/documentation/HyperSpec/Body/22_cfa.htm
>
> you would see it does not produce tab characters, but spaces to
> to move to a specified column. The default is to produce a single
> space.
>
> If you want tabs in the output you need to put them directly
> in the format spec, or indirectly by some means like:
>
> (let ((fspec (format nil "~~{~~s~c~~}" #\tab)))
> (with-open-file (stream "c:/tabout.txt" :direction :output)
> (format stream fspec (list 1 2 3 4 5)))

All right, but to make it a portable program, you would have to do this:

(when (ignore-errors (read-from-string "#\\tab"))
(push :has-tab *features*))

(let ((fspec #+has-tab (format nil "~~{~~s~c~~}" #\tab)
#-has-tab "~11S "))
(with-open-file (stream "c:/tabout.txt" :direction :output)
(format stream fspec (list 1 2 3 4 5))))


--
__Pascal Bourguignon__ http://www.informatimago.com/