[vwnc] ReadWriteStream emptiness

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[vwnc] ReadWriteStream emptiness

Ernest Micklei
Hi all,

In the process of porting our Cloudfork packages, I noticed some unexpected "isEmpty" behavior in ReadWriteStream.

So I took a close look at the class comment and executed the examples:

| r |
r := ReadWriteStream on: 'abcdefghijklmnopqrstuvwxyz'.
r next.    "returns nil"
r isEmpty  "true => expected"

| r s |
s := 'abcdefghijklmnopqrstuvwxyz'.
r := ReadWriteStream on: s from: 1 to: s size.
r isEmpty.  "true ????? => unexpected"
r next.    "returns $a"

The second script returns an unexpected "true" for the stream. Clearly it has content as it is returning $a on next.

In vw76nc, this class inherits the "isEmpty" method from PositionableStream but IMO the implementation must be different for ReadWriteStream.
If this is indeed a valid assumption, then the following definition can help:

ReadWriteStream>>isEmpty
    "Answer if the receiver contains no elements."

    ^position >=  readLimit

Now all examples work fine and as expected, at least by me. 
But looking back at PositionableStream again, I noticed that this is exactly the implementation of "atEnd" !

Should I have used that instead and has the emptiness a different meaning here? 


--
^ Ernest Micklei

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] ReadWriteStream emptiness

kobetic
I don't think I've ever used #isEmpty on a stream, but it seems to me that its intent is clearly different from #atEnd. It talks about what "has already happened" with the stream, not what is "yet to happen". It tells you if anything was already read from/written into a stream. I'd say the selector makes more sense in the writing context than reading, but that's fairly common with shared read/write stream operations in my experience (read and write streams have very little in common IMO).

my 2c,

Martin

"Ernest Micklei"<[hidden email]> wrote:

> Date: March 23, 2009 17:09:15.000
> From: "Ernest Micklei"<[hidden email]>
> To: [hidden email]
> Subject: [vwnc] ReadWriteStream emptiness
>
> Hi all,
>
> In the process of porting our Cloudfork packages, I noticed some unexpected
> "isEmpty" behavior in ReadWriteStream.
>
> So I took a close look at the class comment and executed the examples:
>
> | r |
> r := ReadWriteStream on: 'abcdefghijklmnopqrstuvwxyz'.
> r next.    "returns nil"
> r isEmpty  "true => expected"
>
> | r s |
> s := 'abcdefghijklmnopqrstuvwxyz'.
> r := ReadWriteStream on: s from: 1 to: s size.
> r isEmpty.  "true ????? => unexpected"
> r next.    "returns $a"
>
> The second script returns an unexpected "true" for the stream. Clearly it
> has content as it is returning $a on next.
>
> In vw76nc, this class inherits the "isEmpty" method from PositionableStream
> but IMO the implementation must be different for ReadWriteStream.
> If this is indeed a valid assumption, then the following definition can
> help:
>
> ReadWriteStream>>isEmpty
>     "Answer if the receiver contains no elements."
>
>     ^position >=  readLimit
>
> Now all examples work fine and as expected, at least by me.
> But looking back at PositionableStream again, I noticed that this is exactly
> the implementation of "atEnd" !
>
> Should I have used that instead and has the emptiness a different meaning
> here?
>
>
> --
> ^ Ernest Micklei
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc