David Trudgett <email@example.com> wrote:
| Your suggestion is OK if you like that sort of thing, but I
| have a natural aversion to using arbitrary values as booleans...
But remember, this is Common Lisp, not Scheme. In CL the *only*
distinguished boolean is NIL as "false" -- *everything* else is "true".
Plus, we're using (READ-LINE stream NIL NIL) here, where the outcome is
*guaranteed* [absent an I/O error throwing an exception] to be either
a [possibly zero-length] string ["true"] or NIL. So you've already got
an unambiguous boolean result, and thus (WHEN LINE ...) is IMHO a more
natural way than (UNLESS (NULL LINE) ...) to say what you're really
trying to do.
The same is true of READ-CHAR but *not* of READ, which can return NIL,
which is why people tend to use the following variation when using READ:
(with-open-file (stream "filename")
(loop with eof = (list nil)
for form = (read stream nil eof)
until (eq form eof) do
And of course some prefer to use the "WHILE (NOT (EQ FORM EOF))"
variant here, for parallelism with other LOOPs that use WHILE.
Rob Warnock <firstname.lastname@example.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607