[Pharo-project] getting crazy with ImageSegment code
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
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
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
Before I add an issue to add classifiedBy: is it different from groupedBy: aBlock "Answer a dictionary whose keys are the result of evaluating aBlock for all my elements, and the value for each key is the selection of my elements that evaluated to that key. Uses species." | groups | groups := PluggableDictionary integerDictionary. self do: [ :each | (groups at: (aBlock value: each) ifAbsentPut: [ OrderedCollection new ]) add: each ]. self species ~~ OrderedCollection ifTrue: [ groups associationsDo: [ :association | association value: (self species withAll: association value) ]]. ^ groups which is now in Pharo 1.1 ;-") On Jan 6, 2010, at 4:28 PM, Gary Chambers wrote:
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
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Yeah, that's pretty much the same... ;-) Guess we can update our "extensions" package to refator to that now! Regards, Gary ----- Original Message ----- From: "Stéphane Ducasse" <stephane.ducasse@inria.fr> To: <Pharo-project@lists.gforge.inria.fr> Sent: Wednesday, January 06, 2010 8:39 PM Subject: Re: [Pharo-project] getting crazy with ImageSegment code
Before I add an issue to add classifiedBy: is it different from
groupedBy: aBlock "Answer a dictionary whose keys are the result of evaluating aBlock for all my elements, and the value for each key is the selection of my elements that evaluated to that key. Uses species." | groups | groups := PluggableDictionary integerDictionary. self do: [ :each | (groups at: (aBlock value: each) ifAbsentPut: [ OrderedCollection new ]) add: each ]. self species ~~ OrderedCollection ifTrue: [ groups associationsDo: [ :association | association value: (self species withAll: association value) ]]. ^ groups
which is now in Pharo 1.1 ;-")
On Jan 6, 2010, at 4:28 PM, Gary Chambers wrote:
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
_______________________________________________ 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
participants (4)
-
Adrian Lienhard -
Gary Chambers -
Mariano Martinez Peck -
Stéphane Ducasse