Perhaps a helper method might be useful. Here's one I alsways end up implementing on Collection for whatever Smalltalk system... classifiedBy: aBlock "Answer a dictionary where the keys are the result of evaluating the block and the values are ordered collections of the elements of the receiver that caused the block to return that key." |d| d := Dictionary new. self do: [:e | (d at: (aBlock value: e) ifAbsentPut: [OrderedCollection new]) add: e]. ^d Regards, Gary ----- Original Message ----- From: "Adrian Lienhard" <adi@netstyle.ch> To: <Pharo-project@lists.gforge.inria.fr> Sent: Wednesday, January 06, 2010 2:57 PM Subject: Re: [Pharo-project] getting crazy with ImageSegment code
I extracted some old code and adapted it slightly (see below). I've not executed this but just typed it in Mail. And I have not completely read/understood your code but maybe it does what you need :)
Cheers, Adrian
symbols := Symbol allSymbols. groups := Dictionary new. SystemOrganization categories do: [ :cat | groups at: cat put: ((SystemOrganization superclassOrder: cat) select: [:c | aCollection includes: c]) asArray ]. groups keys do: [ :cat | roots := groups at: cat. roots := roots reject: [ :each | unused includes: each ]. roots := roots , (roots collect: #class). (ImageSegment new copyFromRoots: roots sizeHint: 0 areUnique: true) extract; writeToFile: cat ]
On Jan 6, 2010, at 15:44 , Mariano Martinez Peck wrote:
Hi folks. I will pay a beer in next ESUG to the person that helps me to refactor this piece of code of ImageSegments:
The idea is that I have a list of classes that were inactive and I want to group them by category (actually, seeing the code I think it is package) and to to create an ImageSegment per category (or package).
This is the code (ONLYYYYY a piece...I cut all the rest)
unused := self inactiveClassesDuringDiscovery. "These are the classes that were not used" groups := Dictionary new. SystemOrganization categories do: [:cat | i := (cat findLast: [:c | c = $-]) - 1. i <= 0 ifTrue: [i := cat size]. groups at: (cat copyFrom: 1 to: i) put: (groups at: (cat copyFrom: 1 to: i) ifAbsent: [Array new]) , ((SystemOrganization superclassOrder: cat) select: [:c | unused includes: c]) asArray]. groups keys do: [:cat | roots := groups at: cat. Transcript cr; cr; show: cat; cr; print: roots; endEntry. roots := roots , (roots collect: [:c | c class]). "There seems to be a problem with these packages, thus they are excluded." ((cat beginsWith: 'Sys') or: [cat beginsWith: 'Multilingual'] or: [cat beginsWith: 'Kerne'] ) ifFalse: [(ImageSegment new copyFromRoots: roots sizeHint: 0) extract; writeToFile: cat]. Transcript cr; print: Smalltalk garbageCollect; endEntry]
Can someone help me tu rewrite this? I think I could use PackageOrganizer or PackageInfo but I have no idea.
Thanks!
Mariano _______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project