ReadStream and skipping past the end

Boris Gaertner Boris.Gaertner at gmx.net
Thu Mar 10 22:30:48 UTC 2005


"Martin Kuball" <MartinKuball at web.de> wrote:


> Hi!
> 
> The comment in method PositionableStream>>#skip: says:
> 
> "Set the receiver's position to be the current position+anInteger. A 
>  subclass might choose to be more helpful and select the minimum of
>  the receiver's size and position+anInteger, or the maximum of 1 and 
>  position+anInteger for the repositioning."
> 
> Now why is this not implemented right there? Or at least in the 
> subclass ReadStream? I think this would be more compatible to the 
> behaviour of the method #next when reading past the end. It just 
> return nil. No error signaled.
We have the same behavior in
StandardFileStream>>basicNext.

CrLfFileStream>>upTo:  and
CrLFFileStream>>next
check for nil to detect the end-of-file 

You may wish to try this example with different Smalltalks:

 | st |
  st := ReadStream on: #(1 2 3).
  (1 to: 4) collect: [:x | st next]

Smalltalk V/286, Dolphin and VisualAge signal an error,
Squeak,VisualWork and Smalltalk/X answer #(1 2 3 nil)
> 
> By the way there is a class EndOfStream which was appearantly designed 
> to signal an error when reading past the end. But it is not used. And 
> I think it should not. So maybe the class should be removed.

In Dec 2003 I tried implement the modifications that are necessary to
use EndOfStream, but we could not come to a decision about the issue.
In fact there is little need to introduce exception handling in a situation
where nil can be used to represent the eof mark. Note also the the
EndOfStream answers nil when it is not handled (in instance method
defaultAction)

Boris



More information about the Squeak-dev mailing list