[BUG] ReadStream>>isEmpty ?

Andreas Raab andreas.raab at gmx.de
Fri Aug 8 21:19:20 UTC 2003


> That simple of a solution won't work either. 

It absolutely will.

> ReadStream>>size simply returns readLimit which can be
> non-zero and still mean there is that can be read from
> the stream.

A stream isn't "empty" just because you can't read from it. That's called
"at end". The implementation of #isEmpty by using size is therefore
completely well-defined. It asks the stream if there are any elements
whatsoever and if there are, it will answer true. What the current position
of the stream is, is entirely irrelevant in this context.

Note that this interpretation is also consistent with the collection
protocol. In fact, one can rightfully claim that "streams" are nothing but
collections with a "cursor" which indicates what element to answer when you
ask for the #next element and very few other methods. This has always been
my favourite interpretation and I find it most unfortunate that streams
don't support the collection protocols as it would mean that the concept of
streams can be fully explained by saying "a stream is a collection with a
cursor" which would remove much of the need for learning their
idiosyncraties.

In fact I think that you wouldn't even have that confusion about the
"meaning of size" if you would have been introduced to streams that way
(which isn't your fault).

Cheers,
  - Andreas



More information about the Squeak-dev mailing list