[Pharo-users] Stream >> <<

Richard O'Keefe raoknz at gmail.com
Thu Sep 12 09:25:06 EDT 2019


> Why you changed `printSymbol: aClass name`
> for `nextPutAll: aClass name`?

Because there is no #printSymbol: anywhere in Pharo 7 or Pharo 8> ,
so I had to *guess* what it does, and the only reason I could see for
using #printSymbol: instead of #print: is that class names are symbols
and #print: will write a hash in front, and it seemed plausible that
you would not want that hash.  Accordingly I chose a well known, even
standard, method that writes a class name with no extra decoration.

> Now it outputs things incorrectly. You
> should have changed it for `print: aClass name asSymbol`

How is one supposed to *tell* what "correct" output is?
If I wanted to write that code, I would be kind to my readers
and make it *obvious* by doing
   stream nextPut; $#; nextPutAll: aClass name.
I certainly would not go out of my way to confuse people by
sending #asSymbol to something they already know is a Symbol.

For what it's worth, I've attached my implementation.


On Wed, 11 Sep 2019 at 21:46, Herby Vojčík <herby at mailbox.sk> wrote:

> 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.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20190913/23523083/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: puton.st
Type: application/octet-stream
Size: 3815 bytes
Desc: not available
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20190913/23523083/attachment.st>


More information about the Pharo-users mailing list