The Inbox: Collections-ct.923.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-ct.923.mcz

commits-2
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: $)!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.923.mcz

marcel.taeumel
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 [hidden email] <[hidden email]>:

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: $)!




Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-ct.923.mcz

Christoph Thiede

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


Von: Squeak-dev <[hidden email]> 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 [hidden email] <[hidden email]>:

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: $)!




Carpe Squeak!