[ANSI-Smalltalk] #contents on WriteStream

Richard O'Keefe ok at cs.otago.ac.nz
Fri Oct 17 03:04:54 BST 2008


On 16 Oct 2008, at 8:14 pm, Paolo Bonzini wrote:

> In the standard, the definition of #contents for <WriteStream> comes
> from <collectionStream> so that this:
>
>   (WriteStream on: String new) nextPutAll: 'abc'; skip: -1;
>      contents
>
> should "return a collection that contains the receiver's past and  
> future
> sequence values, in order", i.e. 'abc'.  To me it makes more sense  
> that
> it returns 'ab'.

In Squeak and VisualWorks the answer is indeed 'ab',
which I find rather counterintuitive.  The $c is,
after all, still part of the contents, and skip: 1
will reveal it.

In implementation terms, it's the difference between

	^collection copyFrom: 1 to: position

and

	^collection copyFrom: 1 to: readLimit

My library, written to the standard, does the latter;
Squeak and VisualWorks do the former.

The meaning of #contents in the standard is
"a collection containing the complete contents of the stream".

If you do
	(ReadStream on: 'abc') skip: 2; contents
you get all the characters, not just the remaining ones.

Nasty one: the standard's definition is simple, sensible,
and easy to implement (except for file streams, of course,
(:-)).  But implementations do something else.

What do other Smalltalks than Squeak and VW do?





More information about the ANSI-Smalltalk mailing list