Stream Question
Aaron J Reichow
reic0024 at d.umn.edu
Tue Sep 18 17:11:24 UTC 2001
On Tue, 18 Sep 2001, Ken G. Brown wrote:
> Can anyone give some insight into why these snippets do not successfully
> read anything with the 'next' message?
>
> strm _ ReadWriteStream on: (String new: 10000).
> strm nextPutAll: 'aaaaaaaaa'.
> get _ strm next. "gets nil"
>
> strm _ ReadWriteStream on: (Array new: 10000).
> strm nextPutAll: 'aaaaaaaaa'.
> get _ strm next. "gets nil"
The reason those return nil is simple- the position is at the end of the
stream.
strm _ ReadWriteStream on: (String new: 10000). "position = 0"
strm nextPutAll: 'aaaaaaaaa'. "position = 10"
get _ strm next.
And when you get around to sending #next, you're asking for the next
character at the end of the stream, which there is obviously no more of.
strm _ ReadWriteStream on: (String new: 10000).
strm nextPutAll: 'AAAAaaaa'.
strm position: 0. "put the stream marker at the begining!"
get _ strm next. "returns $A"
strm position: 4. "put the stream marker in the middle"
get _ strm next. "returns $a"
Regards and good luck!
Aaron
Aaron Reichow :: Twin Ports ACM Pres :: http://www.d.umn.edu/~reic0024/
"life, probably the biggest word i've ever said, that says a lot 'cause
there is a whole lot of words inside my head..." -- atmosphere
More information about the Squeak-dev
mailing list
|