XPost: comp.lang.scheme
Pascal Bourguignon wrote:
(defun read-file (filename delimiter)
"Return a list of lists containing strings in pathname FILENAME delimited by character DELIMITER."
(let ((output '()))
(with-open-file (in filename)
(do ((line (read-line in nil) (read-line in nil)))
((null line))
(push (line-split line delimiter) output))
(nreverse output))))
Good. Eventually, I switched to loop:
(defun read-file (filename delimiter)
"Return a list of lists containing strings in pathname FILENAME
delimited by character DELIMITER."
(with-open-file (in filename)
(loop
:for line = (read-line in nil)
:while line
:collect (line-split line delimiter))))
There is no "line-split" in CL.
Gauche Scheme
(define (read-and-split-lines filename delimiter)
(with-input-from-file filename
(lambda()
(generator-map
(cut string-split <> delimiter)
read-line))))
(read-and-split-lines "input.dat" #\space)
===>
(("V0003" "oranges") ("V0002" "foo" "bar") ("V0001" "and" "so" "on")
("V0003" "screws") ("V0002" "apples") ("V0003" "glue"))
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)