LispCookbook / LispCookbook/cl-cookbook
Feature Request: Recommend and demonstrate a library for csv parsing.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 158
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 2
Description
Just making a `TODO` here for adding a tutorial on how to parse CSV.
I realize that you can [parse csv with split-sequence](https://git.sr.ht/~whereiseveryone/qc/tree/master/item/src/qc.lisp#L146) but might be nice to show to do it with a proper csv parser.
This might be a good candidate/starting point:
https://github.com/AccelerationNet/cl-csv#examples
```lisp
;; read a file into a list of lists
(cl-csv:read-csv #P"file.csv")
=> (("1" "2" "3") ("4" "5" "6"))
;; read a file that's tab delimited
(cl-csv:read-csv #P"file.tab" :separator #\Tab)
;; read a file and return a list of objects created from each row
(cl-csv:read-csv #P"file.csv"
:map-fn #'(lambda (row)
(make-instance 'object
:foo (nth 0 row)
:baz (nth 2 row))))
;; read csv from a string (streams also supported)
(cl-csv:read-csv "1,2,3
4,5,6")
=> (("1" "2" "3") ("4" "5" "6"))
;; loop over a CSV for effect
(let ((sum 0))
(cl-csv:do-csv (row #P"file.csv")
(incf sum (parse-integer (nth 0 row))))
sum)
;; loop over a CSV using iterate
(iter (for (foo bar baz) in-csv #P"file.csv")
(collect (make-instance 'object :foo foo :baz baz)))
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing split-sequence CSV example linked in the issue and review the cl-csv examples repository. Identify the appropriate tutorial location in the cookbook, then document CSV parsing with a recommended library and representative examples. Done means the cookbook includes a usable CSV-parsing tutorial.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100