[Pharo-users] Stream >> <<

Herby Vojčík herby at mailbox.sk
Wed Sep 11 05:46:19 EDT 2019

On 11. 9. 2019 3:23, Richard O'Keefe wrote:
> It is good that you have a coherent idea of how << can work.

After the changes sent by Sven, Pharo 8 seems to have the exactly same 
idea. IMNSHO.

> The question I was addressing is how << *DOES* work in Pharo.
> Having simple things working, if they are kept consistent,
> is indeed good.  The problem is that in Pharo 7 they are NOT
> consistent, and << does NOT work consistently, because there
> are occasions when << does ^something nextPutAll: something else
> and nextPutAll: returns something else.

Bug. '^' should not have been there.

> I am grateful for the link to the changes to Pharo 8.
> That's a massive simplification and improvement.
> There is some way to go yet.

Actually, from my PoV, just the fix I posted. The rest seems correct.

> The very first thing that should be done is to write down
> what the *semantics* of #<< is supposed to be, and then to
> ensure it is implemented that way. >
> Let's look at the chunk example.
> exportTraitDefinitionOf: aClass on: aStream
>    "Chunk format."
>    aStream
>      nextPutAll: 'Trait named: '; nextPutAll: aClass name; cr;

The devil is in the details. Why you changed `printSymbol: aClass name` 
for `nextPutAll: aClass name`? Now it outputs things incorrectly. You 
should have changed it for `print: aClass name asSymbol`

And this is precisely that distinction between low-level nextPutAll: and 
high-level write: / << / print:.

>      tab; nextPutAll: 'package: '; print: aClass category; nextPutAll: 
> '!!'; cr.
>    aClass comment isEmpty ifFalse: [
>      aStream
>        nextPutAll: '!!'; print: aClass; nextPutAll: 'commentStamp!!'; cr;
>        nextPutAll: aClass category withDelimiter: $!; nextPutAll: '!!'; cr].
>    aStream cr.
> With the exception of #nextPutAll:withDelimiter:, this is completely
> standard and portable.  If I am willing to do something nonstandard,
>    aStream format: 'Trait named: {s}{n}{t}package: {p}{n}'
>      with: aClass name with: aClass category.
>    aClass comment isEmpty ifFalse: [
>      aStream format: '!!{p} commentStamp!!{n}{D$!}!!{n}'
>        with: aClass with: aClass comment].
>    aClass format: '{n}.
> #write: really does not seem to be any improvement over #nextPutAll:.

Will post.

> For what it's worth, GNU Smalltalk also has #<<, which it defines
> to be equivalent to #displayOn:, if memory serves me correctly.
> It has never been clear to me what the use case for #write: is.
> In Pharo 7, for streams it is the same as #putOn: except for the
> result.  Neither of them is in any interesting way "higher
> level" than #nextPut: or #nextPutAll:, merely less informative.

More information about the Pharo-users mailing list