Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 40 |
Nodes: | 6 (0 / 6) |
Uptime: | 10:19:24 |
Calls: | 291 |
Files: | 910 |
Messages: | 76,423 |
If you want to write a function that returns the lines in the file do...
this:
(defun read-lines-from-file (file)
;; Return a list of all the lines in FILE. FILE is either a string
or
;; a pathname
(with-open-file (in file :direction ':input)
;; no real line can be NIL, so we don't need to worry about
;; inventing a unique return value here
(loop for line = (read-line in nil nil)
while line collect line)))
Note for CLL people: I think this is a great use of LOOP. It's *so*
easy to see what is happening here:
loop for line = <get next line from file, NIL on EOF>
while line collect line
Of course it's not pure functional Lisp. But *so what*?