csv to nested list?

Q&A's, tips, howto's
Post Reply
tomtoo
Posts: 46
Joined: Wed Oct 28, 2009 10:00 pm

csv to nested list?

Post 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 :-)

ralph.ronnquist
Posts: 216
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia

Re: csv to nested list?

Post by ralph.ronnquist »

Doing it properly might require a proper CSV parser, like
https://github.com/kanendosei/artful-ne ... er/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.

Post Reply