Subject: Re: input
From: (Rob Warnock)
Date: Wed, 22 Apr 2009 20:42:54 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
david  <> wrote:
| (Rob Warnock) wrote:
| > I tend to prefer this sort of style to that FORMAT hack:
| >     > (with-input-from-string (s "go north")
| >         (loop with eof = (list :eof)
| >               for form = (read s nil eof)
| >               until (eq form eof)
| >           collect form))
| thanks for your help. why do you make eof a keyword?

EOF *isn't* "a keyword"; it's a freshly-consed list *containing*
a keyword. The "freshly-consed list" is the important part, since
that object *cannot* be EQ to any possible object the READ function
might return from reading your string. Writing "EOF = (LIST)" or
"EOF = (CONS NIL NIL)" [but the former is shorter!] would have
worked just as well, and then EOF would have contained "(NIL)".

But I find that burying some visible marker [such as the keyword :EOF]
in said freshly-consed list sometimes aids debugging. That is, down
inside some debugger breakpoint, when you run into "(:EOF)" you
immediately know where it came from, which isn't equally true of
"(NIL)". It costs almost nothing extra, since I almost always use
the keyword :EOF *somewhere* in a program, and thus it's already
been INTERNed.

| in (read s nil eof) i think nil is eof-error-p. what
| is the purpose to set it to nil?
| i think read knows eof is end-of-file by position so
| (read s nil foo) would work also?

Thomas Russ already addressed these two parts in his parallel reply,
but the purpose of setting EOF-ERROR-P is to allow you the programmer
to explicitly get a return value from reading to end-of-file instead
of causing the implementation to signal a condition.


Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607