links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Last updated at 8:50 am UTC on 30 March 2017
 ReadWriteStream subclasses  
 {RWBinaryOrTextStream . FileStream . Transcripter . CompressedSourceStream . MultiByteBinaryOrTextStream}

Notes 2007

In response to the issues raised below:
The code in the book is wrong. It works for the ReadStream
class, but not the ReadWriteStream class.

s := ReadWriteStream on: #(1 2).
s inspect.
The readLimit variable is 0

Look at the ReadWriteStream contents method:

"Answer with a copy of my collection from 1 to readLimit."

readLimit _ readLimit max: position.
^collection copyFrom: 1 to: readLimit

^ collection copyFrom: 1 to: 0 will be #().

[dae 15Dec07]
Are there bugs in the ReadWriteStream class in Squeak 3.5?

I've been reading the "Squeak: A Quick Trip to ObjectLand" book and have come across some problems with getting the examples using ReadWriteStream to work (on page 174-175). I don't get the same results as the book states as one should expect.

For instance, the following is a series of message sends from the book and what it says are the expected returned values:

s := ReadWriteStream on: #(1 2).
s next. "expected returned value should be 1"
s next. "...should be 1"
s atEnd. "...should be true"
s reset.
s next. "...should be 1"
s position. "...should be 0"

However, this is what I actually got:

s := ReadWriteStream on: #(1 2).
s next. ".result is nil while expected result should be 1 according to the book"
s atEnd. "results in true"
s position. "Answers 0"
s reset.
s next. "result is nil should be 1 according to the book"
s position. "Again, answers 0 while it should be 1"
s atEnd. "true again despite reset message send"
s contents. "#()"

I stepped through the on: message sent to ReadWriteStream and noticed that the read limit is set to 0.

I tried sending the with: message to see what happened.

s := ReadWriteStream with: #(1 2).
s next. "result returned is nil"
s position. "2"
s atEnd. "true"

Again, the next message returned nil instead of 1. Although, this time the position messaged returned 2.

The results are closer to what the book expects if a reset message is sent and the with: creation method is used instead of on:.

s := ReadWriteStream with: #(1 2).
s reset.
s next. "1 as expected"
s next. "2 likewise, as expected"
s atEnd. "true"

I've written an unit test for ReadWriteStream, ReadWriteStream, which exposes these failings. Is it possible if those responsible for ReadWriteStream could please verify the tests assumptions?