Re: bug in read-lines: skips empty lines
Ralf Juengling <[email protected]> Mon, 13 Feb 2006 14:06:28 -0800 (PST)
| Newsgroups | gmane.lisp.lush.devel |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 13 Feb 2006, Raymond Martin wrote: >> >> read-lines should return an empty string for an empty line. >> Here is a fix that works on a unix platform: >> >> --- orig/lsh/libc/shell.lsh >> +++ mod/lsh/libc/shell.lsh >> @@ -75,8 +75,9 @@ >> (de read-lines(f) >> (reading f >> (let ((ans ())) >> - (while (<> (skip-char "\n\r\f") "\e") >> - (setq ans (cons (read-string) ans))) >> + (while (<> (skip-char "") "\e") >> + (setq ans (cons (read-string) ans)) >> + (read-string 1)) ;; need a function 'read-newline' here >> (reverse ans)))) >> > > Isn't the function name "read-lines" something of a misnomer. Shouldn't > it be more like "read-file-lines", it only works with a filename/descriptor > and does not match with "write-lines" (for which a "write-file-lines" might > also be appropriate). Good point. But rather than renaming "read-lines" to "read-file-lines" I'd consider generalizing function 'reading' instead (i.e., merge current 'reading' and 'reading-string'). Without changing a line of code, 'read-lines' could then read lines from whatever 'reading' is able to deal with. A nice example of "generic programming". Ralf ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642