File: csvwrite.lsp

package info (click to toggle)
nyquist 3.24%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 58,156 kB
  • sloc: ansic: 74,757; lisp: 18,169; java: 10,942; cpp: 6,688; sh: 175; xml: 58; makefile: 40; python: 15
file content (24 lines) | stat: -rw-r--r-- 700 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
;; csvwrite.lsp -- csv file writer
;;
;; Roger B. Dannenberg
;; June 2022

;; write a CSV file. See csvread.lsp for details on representation
;;
(defun csv-write (filename csv)
  (let ((outf filename) need-comma)
    (cond ((stringp outf)
           (setf outf (open filename :direction :output))))
    (cond ((not (filep outf))
           (error (format nil "csv-write: could not get a file to write from ~A"
                          filename))))
    (dolist (row csv)
      (setf need-comma nil)
      (dolist (col row)
        (cond (need-comma (princ #\, outf)))
        (cond (col
               (prin1 col outf)))
        (setf need-comma t))
      (princ #\Newline outf))
    (close outf)))