#| \#\"s in this file would need to be fiddled with. I'll post the common lisp file too.
I wanted to try writing streaming csv processing. I was inspired by pizzapal doing classic AI in guile from PAIP. I'm doing something trivial in common lisp instead. Sisters of Mercy is good music, tangentially. pizzapal is working with xlsx I think, but there are shell utilities to convert those to csv.
Streaming to me means that after an initial delay, data flows out at the same rate it flows in. Hypothetically only READs take time to do.
This is all I want to do:
1. Read list of headers
2. Add or change the headers with 3 in mind
2b. Make an alist of conses often kinda like
(\"header\" .
(let ((last-val nil))
(lambda (&optional in out)
(if (and in out)
(format out \"~s\" (setf last-val (read in)))
(values last-val)))))
3. call the closures corresponding to the headers from 2 for each row
(defun rw-rows (headings in out) \"
(rw-rows headings in out)
peeks for eof before doing #'rw-each
\"
(let ((peek1 (peek-char t in nil nil))
(peek2 (peek-char nil in nil nil)))
(when peek2
(rw-each (copy-list headings) in out)
(rw-rows headings in out))))
;;;An alist like
;;;((\"string\" . (lambda (&optional in out) 'foo)))
(setq *assoclosures*
(list
(cons \"this\"
(let ((last-val nil))
(lambda (&optional in out)
(if (and in out)
(format out \"\"~a:~a\" \" \"this\"
(setf last-val (read in)))
last-val))))
(cons \"that\"
(let ((last-val nil))
(lambda (&optional in out)
(if (and in out)
(format out \"\"~a:~a\" \" \"that\"
(setf last-val (read in)))
last-val))))
(cons \"the\"
(let ((last-val nil))
(lambda (&optional in out)
(if (and in out)
(format out \"\"~a:~a\" \" \"the\"
(setf last-val (read in)))
last-val))))
(cons \"other\"
(let ((last-val nil))
(lambda (&optional in out)
(if (and in out)
(format out \"\"~a:~a\" \" \"other\"
(setf last-val (read in nil nil)))
last-val))))
(cons \"rowsum\"
(let ((last-val nil))
(lambda (&optional in out)
(if (and in out)
(format out \"\"~a:~a\"~%\" \"rowsum\"
(setf last-val
(reduce '+
(mapcan (lambda (x)
(let ((n (funcall (cdr x))))
(and n (list n))))
*assoclosures*))))
last-val))))))