From: Kent M Pitman
Subject: eof value for streams
Date: 
Message-ID: <sfwk8w5j8xp.fsf@world.std.com>
I got private mail from Vassil Nikolov that I wanted to reply to here.
(His permission to post his part is included at end.)

> Date: Fri, 26 Mar 1999 01:32:06 +0200
> From: Vassil Nikolov <········@poboxes.com>
> To: Kent M Pitman <······@world.std.com>
> Subject: Thanks for the eof value for streams
> 
> On 1999/03/24,
> you (Kent M Pitman <······@world.std.com>) wrote in comp.lang.lisp:
> 
>   (...)
>   >  #.+EOF-VALUE+
>   > will give a bogus eof result when doing READ, and so you defeat the
>   > purpose.  I prefer to make a new EOF value lexically in the scope
>   > of whatever routine I'm using just to make sure no program gets to the
>   > eof value.  Seems obscure, but I worry about such things.
> 
> Obscure?  I have always thought that was pretty self-evident...
> Well, may be not always, but after I had figured it out.  (Though
> I never was bitten by this.)
> 
>   > Btw, to avoid consing, the unique value I almost always use is the stream
>   > itself, which is invariably not found in the stream.  As long as it's
>   > not bound to a special (like *standard-input*) it's not available to
>   > the stream.    Sometimes I do
>   >  (let ((eof stream)) ...)
>   > so that I can still use a variable named EOF instead of the STREAM 
>   > variable. Feels kind of weird either way.  But it's very practical.
> 
> Thanks a lot!
> 
> Not weird at all.
> 
> That I had never figured out myself, and is good to know, as
> I have always wondered what was the `best' value to use.
> (Allocating a fresh cons or gensym doesn't waste much storage
> but is inelegant and, more importantly, bothers me: should it
> be '(NIL) or '#:EOF or what---I dislike arbitrary choices, they
> often are a symptom that the design is wrong.)

'(NIL) seems an especially bad value because of coalescing.
(LIST NIL) is safer since it's guranteed fresh.
I sometimes do (LIST 'EOF) to make it clearer when I'm making
unique things.

I think #:EOF is safer, though it makes my head hurt to reason about
identity of gensyms  and I usually try to avoid it.

> In fact, come to think of it, this could be the default value for
> the eof-value argument to READ & friends, useful when eof-error-p
> is (supplied as) NIL.

This is an interesting idea I hadn't really thought of.  I don't know
whether I think it would be good but I figured I'd put it out here "on
the record" for others to comment on in case anyone was of a mind to.

> This started as private mail being a `thank you' message,^1 but now I
> see maybe I should have posted it.  But it is too painful for me to go
> back to Deja News, so I leave it to you to decide whether to post it to
> the group (in part or in full as you find fit).  (E.g. depending on the
> amount of information you received, i.e. the degree of unexpectedness,
> of surprise.  Shannon's theory is an interesting one.)
> ___________________
> ^1 and a sort of `me too'

No one ever said "him too" messages were poor form, so we're safe.
By me sending it instead of you, it's not a "me, too" any more. 
"from-field laundering".
From: Vassil Nikolov
Subject: Re: eof value for streams
Date: 
Message-ID: <7dgpe7$bi0$1@nnrp1.dejanews.com>
In article <···············@world.std.com>,
  Kent M Pitman <······@world.std.com> wrote:
(...)
> > '(NIL) or '#:EOF
(...)
>
> '(NIL) seems an especially bad value because of coalescing.

Yes, *of course*.  While I was typing that sometime in the wee
hours of the morning, I wrote in fact (CONS NIL NIL) and then
my mind went into luser mode and I replaced that by '(NIL).
Optimisation is not for the human mind.

> (LIST NIL) is safer since it's guranteed fresh.
> I sometimes do (LIST 'EOF) to make it clearer when I'm making
> unique things.
>
> I think #:EOF is safer, though it makes my head hurt to reason about
> identity of gensyms  and I usually try to avoid it.

In fact, the general issue here is: which is the *canonical* fresh
reference (where the value doesn't matter): a call to CONS or a
GENSYM (or a call to MAKE-ARRAY or...).  Well, I suppose this has
no answer.

(...)
> No one ever said "him too" messages were poor form, so we're safe.
> By me sending it instead of you, it's not a "me, too" any more.
> "from-field laundering".

:-) :-)

Now, there's this SMTP/NNTP server on the Cayman Islands...

Vassil Nikolov <········@poboxes.com> www.poboxes.com/vnikolov
(You may want to cc your posting to me if I _have_ to see it.)
   LEGEMANVALEMFVTVTVM  (Ancient Roman programmers' adage.)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own