How to download and parse a csv file in Racket? -


how download , parse csv file in racket?

use get-pure-port download file, , use planet library (require (planet neil/csv)) parse it.

the following example downloads , parses csv file containing data on size of various galapagos islands , how many species found on each island.

#lang racket (require (planet neil/csv:1:=7) net/url)  (define galapagos-url    (string->url    "http://www.stat.washington.edu/~handcock/536/data/galapagos.csv"))  (define make-galapagos-csv-reader   (make-csv-reader-maker    '((separator-chars              #\,)      (strip-leading-whitespace?  . #t)      (strip-trailing-whitespace? . #t))))  (define (all-rows url make-reader)   (define next-row (make-reader (get-pure-port url)))   (define (loop)     (define row (next-row))     (if (empty? row)         '()         (cons row (loop))))   (loop))  (all-rows galapagos-url make-galapagos-csv-reader) 

the first rows returned are:

'(("island"    "observed.species"    "native.species"    "area(km^2)"    "elevation(m)"    "distance.nearest.island(km)"    "distance.santa.cruz(km)"    "area.adj.island(km^2)")   ("baltra" "58" "23" "25.09" "" "0.6" "0.6" "1.84")   ("bartolome" "31" "21" "1.24" "109" "0.6" "26.3" "572.33")   ("caldwell" "3" "3" "0.21" "114" "2.8" "58.7" "0.78") 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -