[squeak-dev] Review Request: Bag printString

christoph.thiede at student.hpi.uni-potsdam.de christoph.thiede at student.hpi.uni-potsdam.de
Sat Feb 26 19:52:30 UTC 2022


I forgot to mention that this also fixes a dangling space at the end of Dictionary printString.

Best,
Christoph

---
Sent from Squeak Inbox Talk

On 2022-02-26T20:49:48+01:00, christoph.thiede at student.hpi.uni-potsdam.de wrote:

> =============== Summary ===============
> 
> Change Set:????????Bag printString
> Date:????????????26 February 2022
> Author:????????????Christoph Thiede
> 
> This changeset customizes the Bag printString to no longer emit every occurence of each element repeatedly.
> 
> Example:
> ????{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)'.
> 
> Thanks to Robert (rhi) for the hint!
> 
> =============== Diff ===============
> 
> Bag>>printElementsOn: {printing} ? ct 2/26/2022 20:26
> + printElementsOn: aStream
> + 
> + ????contents printElementsOn: aStream.
> 
> BagTest>>testPrintString {tests} ? ct 2/26/2022 20:25
> + testPrintString
> + 
> + ????| bag |
> + ????bag := Bag new.
> + ????bag add: '1' withOccurrences: 5.
> + ????bag add: '2' withOccurrences: 1.
> + ????bag add: '3' withOccurrences: 3.
> + ????
> + ????self assert: 'a Bag(''1''->5 ''2''->1 ''3''->3)' equals: bag printString.
> 
> Dictionary>>printElementsOn: {printing} ? ct 2/26/2022 20:28 (changed)
> printElementsOn: aStream 
> ????aStream nextPut: $(.
> ????self size > 100
> ????????ifTrue: [aStream nextPutAll: 'size '.
> ????????????self size printOn: aStream]
> ????????ifFalse: [self keysInOrder
> ????????????????do: [:key | aStream print: key;
> ???????????????????????? nextPutAll: '->';????????????????
> - ???????????????????????? print: (self at: key);
> - ???????????????????????? space]].
> + ???????????????????????? print: (self at: key)]
> + ????????????????separatedBy: [aStream space]].
> ????aStream nextPut: $)
> 
> ---
> Sent from Squeak Inbox Talk
> ["Bag printString.1.cs"]
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220226/74dd8dbe/attachment.html>
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: Bag printString.1.cs
> Type: application/octet-stream
> Size: 1759 bytes
> Desc: not available
> URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220226/74dd8dbe/attachment.obj>
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220226/9e79fef3/attachment.html>


More information about the Squeak-dev mailing list