Hi David, hi Marcel,<br>
<br>
these are very good points. Please find the next iteration of the patch attached. Instead of ' (n)', I decided on '^n' (common mathm. multiset notation) as I believe that even more brackets would be too confusing. Many printStrings already use them to display a hash or something else.<br>
<br>
What do you think? :-)<br>
<br>
Best,<br>
Christoph<br>
<br>
<b>=============== Summary ===============</b><br>
<br>
Change Set:        Bag printString<br>
Date:            26 February 2022<br>
Author:            Christoph Thiede<br>
<br>
This changeset customizes the Bag printString to no longer emit every occurence of each element repeatedly.<br>
<br>
Example:<br>
    {10 @ 10. 10 @ 10. 20 @ 20. 20 @ 20. 20 @ 20. 30 @ 30. 30 @ 30. 40 @ 40} asBag. 'a Bag(10@10^2 20@20^3 30@30^2 40@40)'.<br>
<br>
Thanks to Robert (rhi) for the hint!<br>
<br>
Revision: Do not print the number for items with 1 occurence. Instead of '->', denote counts by '^', following the mathematical notiation of multisets.<br>
<br>
<b>=============== Diff ===============</b><br>
<br>
<b>Bag>>printElementsOn: {printing} · ct 3/25/2022 20:21</b><br>
<font color="#FF0000">+ printElementsOn: aStream<br>
+ <br>
+     aStream nextPut: $(.<br>
+     contents size > 100<br>
+         ifTrue: [aStream nextPutAll: 'size '.<br>
+             self size printOn: aStream]<br>
+         ifFalse: [contents keysInOrder<br>
+             do: [:key | | count |<br>
+                 aStream print: key.<br>
+                 (count := contents at: key) > 1 ifTrue: [<br>
+                     aStream<br>
+                         nextPut: $^;<br>
+                          print: count]]<br>
+             separatedBy: [aStream space]].<br>
+     aStream nextPut: $)</font><br>
<br>
<b>BagTest>>testPrintString {tests} · ct 3/25/2022 20:24</b><br>
<font color="#FF0000">+ testPrintString<br>
+ <br>
+     | bag |<br>
+     bag := Bag new.<br>
+     bag add: $1 withOccurrences: 5.<br>
+     bag add: '2' withOccurrences: 1.<br>
+     bag add: self withOccurrences: 3.<br>
+     <br>
+     self assert: 'a Bag(BagTest>>#testPrintString^3 ''2'' $1^5)' equals: bag printString.</font><br>
<br>
<b>Dictionary>>printElementsOn: {printing} · ct 2/26/2022 20:28 (changed)</b><br>
printElementsOn: aStream <br>
    aStream nextPut: $(.<br>
    self size > 100<br>
        ifTrue: [aStream nextPutAll: 'size '.<br>
            self size printOn: aStream]<br>
        ifFalse: [self keysInOrder<br>
                do: [:key | aStream print: key;<br>
                         nextPutAll: '->';                <br>
<s><font color="#0000FF">-                          print: (self at: key);<br>
-                          space]].<br>
</font></s><font color="#FF0000">+                          print: (self at: key)]<br>
+                 separatedBy: [aStream space]].<br>
</font>    aStream nextPut: $)<br>
<br>
<font color="#808080">---<br>
</font><font color="#808080"><i>Sent from </i></font><font color="#808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><font color="#808080">Squeak Inbox Talk</font></u></a></i></font><br>
<br>
On 2022-02-28T09:17:04+01:00, marcel.taeumel@hpi.de wrote:<br>
<br>
> Hi Christoph --<br>
> <br>
> I have to agree with Dave. Can we find a threshold when it makes sense to show the counts of each element? Maybe drop the "1" entirely and only show "->n" for n > 1? Maybe don't use "->" but parentheses? And maybe check with objects that have a more complex printString on their own. Hmm...<br>
> <br>
> aBag(10 at 10 (2) 20 at 20 (3) ...)<br>
> <br>
> (Also make sure that the printString is kind of as fast as before. Thanks.)<br>
> <br>
> Best,<br>
> Marcel<br>
> Am 26.02.2022 23:08:06 schrieb David T. Lewis <lewis at mail.msen.com>:<br>
> This seems easier to read for the case of a Bag containing<br>
> many copies of the same entry, and harder to read for the<br>
> case of a Bag containing mostly different entries. I am not<br>
> sure which is the more common scenario.<br>
> <br>
> The original printString hides the implementation, which seems<br>
> like a good thing.<br>
> <br>
> Either approach would be fine for me, although I think I slightly<br>
> prefer the original version.<br>
> <br>
> Dave<br>
> <br>
> On Sat, Feb 26, 2022 at 08:49:48PM +0100, christoph.thiede at student.hpi.uni-potsdam.de wrote:<br>
> > =============== Summary ===============<br>
> ><br>
> > Change Set:????????Bag printString<br>
> > Date:????????????26 February 2022<br>
> > Author:????????????Christoph Thiede<br>
> ><br>
> > This changeset customizes the Bag printString to no longer emit every occurence of each element repeatedly.<br>
> ><br>
> > Example:<br>
> > ????{10 @ 10. 10 @ 10. 20 @ 20. 20 @ 20. 20 @ 20. 30 @ 30. 30 @ 30. 40 @ 40} asBag. 'a Bag(10 at 10->2 20 at 20->3 30 at 30->2 40 at 40->1)'.<br>
> ><br>
> > Thanks to Robert (rhi) for the hint!<br>
> ><br>
> > =============== Diff ===============<br>
> ><br>
> > Bag>>printElementsOn: {printing} ? ct 2/26/2022 20:26<br>
> > + printElementsOn: aStream<br>
> > +<br>
> > + ????contents printElementsOn: aStream.<br>
> ><br>
> > BagTest>>testPrintString {tests} ? ct 2/26/2022 20:25<br>
> > + testPrintString<br>
> > +<br>
> > + ????| bag |<br>
> > + ????bag := Bag new.<br>
> > + ????bag add: '1' withOccurrences: 5.<br>
> > + ????bag add: '2' withOccurrences: 1.<br>
> > + ????bag add: '3' withOccurrences: 3.<br>
> > + ????<br>
> > + ????self assert: 'a Bag(''1''->5 ''2''->1 ''3''->3)' equals: bag printString.<br>
> ><br>
> > Dictionary>>printElementsOn: {printing} ? ct 2/26/2022 20:28 (changed)<br>
> > printElementsOn: aStream<br>
> > ????aStream nextPut: $(.<br>
> > ????self size > 100<br>
> > ????????ifTrue: [aStream nextPutAll: 'size '.<br>
> > ????????????self size printOn: aStream]<br>
> > ????????ifFalse: [self keysInOrder<br>
> > ????????????????do: [:key | aStream print: key;<br>
> > ???????????????????????? nextPutAll: '->';????????????????<br>
> > - ???????????????????????? print: (self at: key);<br>
> > - ???????????????????????? space]].<br>
> > + ???????????????????????? print: (self at: key)]<br>
> > + ????????????????separatedBy: [aStream space]].<br>
> > ????aStream nextPut: $)<br>
> ><br>
> > ---<br>
> > Sent from Squeak Inbox Talk<br>
> > ["Bag printString.1.cs"]<br>
> <br>
> ><br>
> <br>
> <br>
> -------------- next part --------------<br>
> An HTML attachment was scrubbed...<br>
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220228/5e79ee82/attachment.html><br>
> <br>
> <br>
["Bag printString.2.cs"]