[squeak-dev] The Inbox: Collections-pre.838.mcz

Marcel Taeumel marcel.taeumel at hpi.de
Mon Jul 1 07:00:18 UTC 2019

Hi, there.

>From the client's perspective, isn't #do: already an abstraction level higher than #assocationsDo:? It is so on the implementation side, too - at least in Collection. Swapped in Dictionary and OrderedDictionary, though.

Collection >> associationsDo: aBlock
"Evaluate aBlock for each of the receiver's elements (key/value 
associations).  If any non-association is within, the error is not caught now,
but later, when a key or value message is sent to it."

self do: aBlock

Dictionary >> associationsDo: aBlock 
"Evaluate aBlock for each of the receiver's elements (key/value 

tally = 0 ifTrue: [ ^self].
1 to: array size do: [ :index |
(array at: index) ifNotNil: [ :element |
aBlock value: element ] ]

OrderedDictionary >> associationsDo: aBlock
"Iterate over the order instead of the internal array."

order from: 1 to: tally do: aBlock

Am 01.07.2019 02:47:26 schrieb Chris Muller <asqueaker at gmail.com>:
Hi Patrick,

Would you be willing to employ the highest-level methods possible?   "order do: [ .... ", creates an unnecessary dependency on the implementation when it appears #associationsDo: would work fine..?

It looks like it would put a space before the last paren.  Picky, I know, but there is #do:separatedBy: to the rescue.  I guess you could pre-allocate the OrderedDictionary to the proper size.

For the RunArray, could #runsAndValuesDo: help here?  I'm having trouble following this code.  At least in core code, #at:ifAbsentPut: should take a block for the second argument, IMO.


On Fri, Jun 28, 2019 at 5:11 AM <commits at source.squeak.org [mailto:commits at source.squeak.org]> wrote:

Patrick Rein uploaded a new version of Collections to project The Inbox:
http://source.squeak.org/inbox/Collections-pre.838.mcz [http://source.squeak.org/inbox/Collections-pre.838.mcz]

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

Name: Collections-pre.838
Author: pre
Time: 28 June 2019, 12:11:16.302033 pm
UUID: db29f1b2-09b5-f045-aa21-9379185664df
Ancestors: Collections-pre.837

Two method additions to Collection. The first adds ordered printing to OrderedDictionaries, to allow users to actually see the ordering. The second adds a method to convert a run array into an expanded version of the runs.

=============== Diff against Collections-pre.837 ===============

Item was added:
+ ----- Method: OrderedDictionary>>printElementsOn: (in category 'printing') -----
+ printElementsOn: aStream
+       "Based on Dictionary>>#printElementsOn:"
+       aStream nextPut: $(.
+       self size > 100
+               ifTrue: [aStream nextPutAll: 'size '.
+                       self size printOn: aStream]
+               ifFalse: [order do: [:assoc | assoc ifNotNil: [
+                                       assoc printOn: aStream. aStream space]]].
+       aStream nextPut: $)!

Item was added:
+ ----- Method: RunArray>>asValuesAndIntervals (in category 'converting') -----
+ asValuesAndIntervals
+       | interval result |
+       result := OrderedDictionary new.
+       1 to: self size do: [:i |
+               (self at: i) do: [:value |
+                       interval := result at: value ifAbsentPut: (i to: i).
+                       result at: value put: (interval start to: i)]].
+       ^ result
+       !

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

More information about the Squeak-dev mailing list