Last active
April 19, 2018 00:18
-
-
Save corpix/45ecb405eed6dd7a892bac584a33c01f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env racket | |
#lang racket | |
(require racket/cmdline) | |
(require csv-reading) ;; $ raco pkg install csv-reading | |
(define (will-loop executor) | |
(lambda () | |
(let loop () | |
(will-execute executor) | |
(loop)))) | |
(define will-executor (make-will-executor)) | |
(define (will executor value destructor) | |
(will-register executor value destructor) | |
value) | |
;; | |
(define (print-list-items lst) | |
(for-each | |
(lambda (item) | |
(display (string-trim item)) | |
(newline)) | |
lst)) | |
(define (convert row) | |
(print-list-items | |
(string-split (car row) "|"))) | |
(define make-csv-reader | |
(make-csv-reader-maker | |
'((separator-chars #\;) | |
(strip-leading-whitespace? . #t) | |
(strip-trailing-whitespace? . #t)))) | |
(define (main) | |
(void (thread (will-loop will-executor))) | |
(let* | |
([filename (command-line #:args (filename) filename)] | |
[filename-port (will | |
will-executor | |
(open-input-file filename) | |
(lambda (port) (close-input-port port)))] | |
[reader (make-csv-reader filename-port)]) | |
(void (reader)) ;; Skip CSV header | |
(csv-for-each convert reader)) | |
(void)) | |
(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment