Francogrex <······@grex.org> writes:
> I create an array and print it to a file as such:
>
> (setf arr #2A((1 2 3) (4 5 6) (7 8 9)))
> (setf out-stream (open "Output.txt" :direction :output))
> (print arr out-stream)
> (close out-stream)
Don't use OPEN. Use WITH-OPEN-FILE:
(with-open-file (out-stream "Ouput.txt :direction :output)
(print arr out-stream))
> But the output is in the CL array form. Is there a way to print the
> array's columns and rows in a tab-delimited format that can be
> immediadely read as a spreadsheet by something like MS-Excel?
Yes. Writing programs. There's no magic behind the magic, only the
stuff of the trade. You're in to code, so go ahead, code!
> Thanks
Contrarily to popular belief, there is a big number (line in one, two,
three, big) of CSV lisp libraries. Choose and use one of them.
For example:
http://darcs.informatimago.com/darcs/public/lisp/common-lisp/csv.lisp
(Notice that *writing* CSV involves only two functions, so it's hardly
worth a library, which may explain why there are so many of them).
However, you will have to convert it to lists, since FORMAT ~{~}
accepts only lists:
(loop
:with element-type = (array-element-type arr)
:with record-size = (array-dimension arr 1)
:with record = (make-list record-size)
:for i :from 0 :below (array-dimension arr 0)
:for row = (make-array record-size
:displaced-to arr
:displaced-index-offset (* i record-size)
:element-type element-type)
:do (replace record row)
(com.informatimago.common-lisp.csv:write-record record out-stream))
--
__Pascal Bourguignon__ http://www.informatimago.com/
"Remember, Information is not knowledge; Knowledge is not Wisdom;
Wisdom is not truth; Truth is not beauty; Beauty is not love;
Love is not music; Music is the best." -- Frank Zappa