(use magic-pipes) (use args) (use ports) (use chicken-syntax) (use csv) (use alist-lib) (receive (options operands before-exprs after-exprs usage) (parse-mp-args (command-line-arguments) (list (args:make-option (D delimiter) (required: "DELMIITER-CHAR") "Specify the delimiter character") (args:make-option (T tsv) #:none "Set the delimiter character to a tab")) "" "Read s-expressions (lists of strings and numbers) from standard input, and convert them to CSV on standard output.") (unless (= (length operands) 0) (usage)) (let* ((ec (make-eval-context before-exprs '() after-exprs)) (delim-str (if (assq 'tsv options) "\t" (alist-ref options 'delimiter (lambda () ",")))) (delim (if (= (string-length delim-str) 1) (string-ref delim-str 0) (usage)))) (receive (fmt-cell fmt-record fmt-csv) (make-format delim) (for-each-input-datum (lambda (sexpr) (display (fmt-record (list->csv-record sexpr))) (newline)))) (without-input-port (eval-context-end-closure ec))))