[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Testing for EOF

William James

5/3/2015 4:21:00 AM

Barry Margolin wrote:

> >I am starting to write Lisp and am trying to read the lines of a file
> >into a list of strings such that each element of the list is one line
> >from the file. I have figured out how to read lines with read-line,
> >but I can't fugure out how to test for the end of the file. I'm sure
> >it must be easy but I've looked through Steele's book on Common Lisp
> >and through the FAQ and I can't find it. I'd appreciate it if someone
> >could give me a tip.
>
> READ-LINE will return NIL (or whatever value you specify in the <eof-value>
> parameter) when it reaches EOF.
>
> (defun list-lines (filename)
> (with-open-file (stream filename :direction :input)
> (loop for line = (read-line stream)
> while (not (null line))
> collect line)))

Gauche Scheme:

The easiest way:

(use file.util)
(define (list-lines filename)
(file->string-list filename))


Another way:

(define (list-lines filename)
(with-input-from-file filename
(lambda ()
(generator-map values read-line))))

--
Jewish 1960s radicals continued to identify with their parents and with
Judaism. The countercultural revolution was in a very deep sense a mission to
the gentiles in which adaptive behavior and group-identifications of gentiles
were pathologized while Jewish group identification, ingroup pride, family
pride, upward social mobility, and group continuity retained their
psychological importance and positive moral evaluation. --- Kevin MacDonald;
"The Frankfurt School of Social Research and the Pathologization of Gentile
Group Allegiances"