Marco Antoniotti wrote:
> > (defun file-to-lists (input-file-name)
> > "reads a test file: return a list of lines, ie a sublist of string
> > tokens"
> > (with-open-file (stream (make-pathname :name input-file-name)
> > :direction :input)
> > (let ((acc (list)))
> > (do* ((current-line (read-line stream nil 'eof)
> > (read-line stream nil 'eof))) ;current line of
> > the stream
> > ((equal current-line 'eof) (nreverse acc))
> > (push (str-tokenize current-line) acc)))))
> >
>
> Standard reply (untested)
>
> (defun file-to-list (ifn)
> (with-open-file (stream ifn :direction :input)
> (loop for line of-type (or null string) = (read-line stream nil nil)
> while line
> collect (str-tokenize line))))
Note that there is no "str-tokenize" in CL (COBOL-Like).
(require srfi/13) ; string-tokenize (By default, splits on whitespace.)
(require srfi/42) ; list-ec
(define (file-to-list filename)
(call-with-input-file filename
(lambda (in-port)
(list-ec (:port line in-port read-line)
(string-tokenize line)))))
(file-to-list "bar.txt")
===>
'(("A" "SAILING" "WE") ("WILL" "GO."))
--
Gabler ... tells how they replaced the "real" America. "They created ... an
America which is not the real America ... but ultimately this shadow America
becomes ... so widely disseminated that its images and its values come to
devour the real America. And so the grand irony of all of Hollywood is that
Americans come to define themselves by the shadow of America...."
http://archive.org/details/nolies