Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Stupid looping question

15 views
Skip to first unread message

Robert L.

unread,
Mar 16, 2018, 6:26:12 PM3/16/18
to
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

Kaz Kylheku

unread,
Mar 16, 2018, 8:00:49 PM3/16/18
to
On 2018-03-16, Robert L. <No_spamming@noWhere_7073.org> wrote:
> 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

Note that there is no "require" or "srfi/13" in Scheme.
0 new messages