csv to nested list?

Started by tomtoo, October 29, 2017, 06:29:23 AM

Previous topic - Next topic

tomtoo

Hi guys,



I would like to use lookup and/or assoc  to generate html tables. The source data will come from 4 different csv (maybe tsv) files.



This bit from the manual seems almost perfect:



(set 'persons '(
(id001 (name "Anne") (address (country "USA") (city "New York")))
(id002 (name "Jean") (address (country "France") (city "Paris")))
))


Or this:

(set 'persons '(
    ("John Doe" 35 "M" 12.34)
    ("Mickey Mouse" 65 "N" 12345678)


I'm having trouble working out how to populate my list with elements from the different sources.



Help?



It seems like this is a common enough scenario, but I can't quite get it without things getting really ugly.



Thanks :-)

rrq

#1
Doing it properly might require a proper CSV parser, like

https://github.com/kanendosei/artful-newlisp/blob/master/csv.lsp">//https://github.com/kanendosei/artful-newlisp/blob/master/csv.lsp



I must admit I haven't tried it myself, but it looks fine at a glance.



Load that file, then it's simply a matter of (CSV:parse-file csvfile) if you're using comma as delimiter and double-quote as quote character.