csv parsing in Guile Scheme
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Brady McDonough 86db681bec
Rename top level import
2 days ago
csv2 Rename top level import 2 days ago
.gitignore What was 90% of that? 5 years ago
AUTHORS Added to AUTHORS 5 years ago
CHANGELOG Add CHANGELOG 5 years ago
COPYING Released v0.0.1 13 years ago
Makefile Rename top level import 2 days ago
README.md Rename top level import 2 days ago

README.md

guile-csv

A csv reader for Guile. Forked from Nala Ginrut's repository of the same name. This version of the library is built with the tools available in (sxml transform) in mind, if you don't need to run (pre-post-order) to clean your data up, use the original instead.

install

$make

$sudo make install

General usage

reading

First get yourself a port out of whatever csv you want to process:

(use-modules (csv2 csv))
(define $port (open-input-string "a,b\n1,2\n3,4"))

Then, you can process it into a form of your choice between xml and sxml.

(csv->xml $port)

Output:

"<record-1><a>1</a><b>2</b></record-1><record-2><a>3</a><b>4</b></record-2>"

If you plan on working with the parsed output further in scheme you'll probably want to use (csv->sxml) with the optional argument #:record-sym like so:

(csv->sxml $port
           #:record-sym (lambda n "rec"))

Output:

(*TOP* (rec ((a "1") (b "2"))) (rec ((a "3") (b "4"))))

#:record-sym expects a procedure and is called with a numeric argument to generate a string. Ignoring the argument and using a single symbol for all records as seen in the example above could be useful if you plan on manipulating the resulting tree using something like (sxml transform).

writing

While there are facilities to write csv strings and files provided user be warned: they don't quite do what they say on the tin. Calling sxml->csv with the output from csv->sxml for example will result in an error.
The "sxml" expected by this function is what I would venture to call "scsv".

`((a b c)("1" "2" "3")("4" "5" "6"))

Note the double quotes surrounding each data point, the algorithm currently does not attempt to make any conversions and (string-join) will complain accordingly.

I don't have any need for converting back into csv and have no personal plans on improving this situation (just in case you were preparing to hold your breath). If anyone reading this does want such functionality and has a description of how they think the function ought to act please do raise an issue.