[squeak-dev] The Inbox: Collections-ct.923.mcz

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Mon Jan 25 12:27:35 UTC 2021


I remember we had a similar discussion about printString reevaluability some time ago. :-)


IMO, the check is quite cheap and saves me from unnecessary syntax slip errors when reusing the output of an every-day printIt snippet.


> why not add that extra space *all the time*.


Also +1. Considering today's screen sizes a few more spaces really shouldn't matter ...


Best,

Christoph

<http://www.hpi.de/>
________________________________
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel
Gesendet: Montag, 25. Januar 2021 12:15:19
An: squeak-dev
Betreff: Re: [squeak-dev] The Inbox: Collections-ct.923.mcz

If we want to optimize this for code artifacts, why not add that extra space *all the time*. Then again, only #storeOn: should do that, right? Putting so much effort into making #printOn: fit for something it is not meant to be, worries me. :-/

Best,
Marcel

Am 24.01.2021 16:53:54 schrieb commits at source.squeak.org <commits at source.squeak.org>:

A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.923.mcz

==================== Summary ====================

Name: Collections-ct.923
Author: ct
Time: 24 January 2021, 4:53:44.716273 pm
UUID: bd630b83-a77e-cb4f-a008-246786a5c7d8
Ancestors: Collections-mt.919

Fixes printString representation of Associations and Dictionarys to avoid ambiguous selectors. As a consequence, reevalabuality is not limited any longer.

Examples:
1 -> 2. "--> 1->2"
1 -> -2. "--> 1 -> -2"
Dictionary new at: -1 put: 1; at: 1 put: -1; yourself. "--> a Dictionary(-1->1 1 -> -1)"

=============== Diff against Collections-mt.919 ===============

Item was changed:
----- Method: Association>>printOn: (in category 'printing') -----
printOn: aStream
+
| arrow |
super printOn: aStream.
+
+ "Avoid AmbiguousSelector warnings when evaluating the stream as Smalltalk code."
+ arrow := ((key isSymbol and: [key isBinary])
+ or: [(value printStringLimitedTo: 1) beginsWith: '-'])
+ ifTrue: [' -> ']
+ ifFalse: ['->'].
- "If the key is a binary selector and we don't use whitespace, we will stream (key, '->') asSymbol."
- arrow := (key isSymbol and: [key isBinary]) ifTrue: [' -> '] ifFalse: ['->'].
aStream nextPutAll: arrow.
+
+ value printOn: aStream.!
- value printOn: aStream!

Item was changed:
----- Method: Dictionary>>printElementsOn: (in category 'printing') -----
printElementsOn: aStream
aStream nextPut: $(.
self size > 100
ifTrue: [aStream nextPutAll: 'size '.
self size printOn: aStream]
ifFalse: [self keysInOrder
+ do: [:key | aStream print: (self associationAt: key)]
+ separatedBy: [aStream space]].
- do: [:key | aStream print: key;
- nextPutAll: '->';
- print: (self at: key);
- space]].
aStream nextPut: $)!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210125/7bca17bb/attachment.html>


More information about the Squeak-dev mailing list