Page 1 of 1

csv to nested list?

PostPosted: Sun Oct 29, 2017 1:29 pm
by 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:

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


Or this:
Code: Select all
(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 :-)

Re: csv to nested list?

PostPosted: Mon Oct 30, 2017 4:59 am
by ralph.ronnquist
Doing it properly might require a proper CSV parser, like
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
Code: Select all
(CSV:parse-file csvfile)
if you're using comma as delimiter and double-quote as quote character.