2011/8/12 Nicolas Cellier <[email protected]>: > 2011/8/12 Stéphane Ducasse <[email protected]>: >> You are really lucky. >> One the last dinosaurs.... there are rarer and rarer. >> May be you can improve with a timesRepeat: >> > > Yes, good idea, refactoring with an even worse hack is a good joke, > For example (thisContext asManyTimes: 6) repeat sender > > Object>>asManyTimes: anInteger > ^ManyTimesProxy target: self times: anInteger > > ManyTimesProxy>>repeat > ^RepeatManyTimesProxy target: target times: count > > RepeatManyTimesProxy>>doesNotUnderstand: aMessage > count <= 0 ifTrue: [^target]. > count := count - 1. > target := target perform: aMessage selector with: aMessage arguments. > ^self perform: aMessage selector with: aMessage arguments > > Nicolas >
Oh, maybe we should not just stop at RE-factoring but also use factoring and write it ((thisContext asManyTimes: 3) repeat asManyTimes: 2) repeat sender but I'm unsure of the result... Nicolas >> >> Stef >> >> On Aug 12, 2011, at 5:12 PM, Igor Stasenko wrote: >> >>> DiskProxy>>comeFullyUpOnReload: smartRefStream >>> "Internalize myself into a fully alive object after raw loading from a >>> DataStream. (See my class comment.) DataStream will substitute the >>> object from this eval for the DiskProxy." >>> >>> | globalObj symbol arrayIndex | >>> symbol := globalObjectName. "See if class is mapped to another >>> name" >>> (smartRefStream respondsTo: #renamed) >>> ifTrue: [ >>> "If in outPointers in an ImageSegment, remember >>> original class >>> name. >>> See mapClass:installIn:. Would be lost otherwise." >>>>>>>> (thisContext sender sender sender sender sender >>>>>>>> sender sender sender receiver class == ImageSegment >>>>>>>> and: [ thisContext sender sender sender >>>>>>>> sender method == (DataStream compiledMethodAt: #readArray) ]) >>> ifTrue: [ >>> arrayIndex := thisContext sender >>> sender sender sender tempAt: >>> 4. "index var in readArray. Later safer to find i on stack >>> of context." >>> smartRefStream renamedConv at: >>> arrayIndex put: symbol ]. "save >>> original name" >>> symbol := smartRefStream renamed at: symbol ifAbsent: >>> [ symbol ] ]. "map" >>> globalObj := Smalltalk globals >>> at: symbol >>> ifAbsent: [ >>> preSelector == nil & (constructorSelector = #yourself) >>> ifTrue: [ >>> Transcript >>> cr; >>> show: symbol , ' is >>> undeclared.'. >>> (Undeclared includesKey: symbol) >>> ifTrue: [ ^ Undeclared at: >>> symbol ]. >>> Undeclared at: symbol put: nil. >>> ^ nil ]. >>> ^ self error: 'Global "' , symbol , '" not found' ]. >>> preSelector >>> ifNotNil: [ >>> Symbol >>> hasInterned: preSelector >>> ifTrue: [ :selector | >>> [ globalObj := globalObj perform: >>> selector ] >>> on: Error >>> do: [ :ex | >>> ex messageText = 'key >>> not found' >>> ifTrue: [ ^ >>> nil ]. >>> ^ ex signal ] ] ]. >>> "keep the Proxy if Project does not exist" >>> constructorSelector ifNil: [ ^ globalObj ]. >>> Symbol >>> hasInterned: constructorSelector >>> ifTrue: [ :selector | >>> [ ^ globalObj perform: selector withArguments: >>> constructorArgs ] >>> on: Error >>> do: [ :ex | >>> ex messageText = 'key not found' >>> ifTrue: [ ^ nil ]. >>> ^ ex signal ] ]. "args not >>> checked against Renamed" >>> ^ nil >>> >>> -- >>> Best regards, >>> Igor Stasenko AKA sig. >>> >> >> >> >
