About Stream>>write:

Damien Cassou damien.cassou at gmail.com
Thu Aug 2 14:11:48 UTC 2007


What is the desired behavior of Stream>>write:?

The implementation is:

Stream>>write:encodedObject
  ^ encodedObject putOn:self.

and there are 2 implementors of #putOn:

Object>>putOn:aStream
  ^ aStream nextPut:self.

String>>putOn:aStream
  ^ aStream nextPutAll: self.


Is there a need for such a method?

Now, if I look at some of the senders, I find:

Bitmap>>printOnStream: aStream
  aStream
     print: 'a Bitmap of length ';
     write: self size.

Color:byteEncode: aStream
  aStream
	print: '(';
	print: self class name;
	print: ' r: ';
	write: (self red roundTo: 0.001);

Rectangle>>propertyListOn: aStream
  aStream
        print:'{ x=';
        write:origin x;

In nearly all the senders, a number is passed to #write:. But if it's
a number, then #nextPut: will be sent to the stream with the number as
argument. And if you have a stream of characters, as it is the case
here because strings are printed to the stream, you can't write
numbers directly.

Try:
stream := ReadWriteStream on: String new.

Color red byteEncode: stream.
Bitmap allInstances anyOne printOnStream: stream.

it will fail on 3.7, 3.8 and 3.9.

What is the real aim of #write: and how is it different from #print:?

-- 
Damien Cassou



More information about the Squeak-dev mailing list