cyclic looping with [0 == object] whileFalse: [object := object
nextObject].
Mathieu Suen
mathk.sue at gmail.com
Mon Nov 5 17:56:51 UTC 2007
On Nov 5, 2007, at 6:39 PM, Rob Withers wrote:
> What gaurantees that doing loops with #nextObject won't cause
> cyclic looping whereby you process the same set of objects over and
> over again?
>
> The work I was doing was testing changing the parser to eliminate
> #ifTrue: macros from compiled methods and recompiled the entire
> image. I saved the image. When I started the image it was
> frozen. I broke into it and it was looping in the method
> CommandHistory class>>#forgetAllGrabCommandsFrom:. I took the loop
> and modified it slightly to see what it was processing:
>
> | object count objects |
> objects := OrderedCollection new: 1000000.
> count := 0.
> object _ nil.
> [0 == object or: [count > 500000]] whileFalse: [
> count := count + 1.
> objects add: object.
> object isMorph ifTrue: [object removeProperty:
> #undoGrabCommand].
> object _ object nextObject].
> objects
I think your test is wrong 0 == object while always evaluate to false.
#nextObject return the nextObject in memory. But integer are not
object in memory they are pointer (need to be confirm).
So you could try:
| object count objects |
objects := OrderedCollection new: 1000000.
count := 0.
object := nil.
firstObject := object
[firstObject == object or: [count > 500000]] whileFalse: [
count := count + 1.
objects add: object.
object isMorph ifTrue: [object removeProperty:
#undoGrabCommand].
object _ object nextObject].
objects
HTH
Mth
>
> It was looping through objects defined by this loop, block contexts
> defined by my change to #ifTrue: bytecodes - they now create block
> contexts.
>
> [] in UndefinedObject>>DoIt {[object removeProperty:
> #undoGrabCommand]}
> [] in UndefinedObject>>DoIt {[count > 500000]}
> OrderedCollection>>add:
> OrderedCollection>>addLast:
> [] in OrderedCollection>>addLast: {[self makeRoomAtLast]}
> False>>or:
> [] in UndefinedObject>>DoIt {[object removeProperty:
> #undoGrabCommand]}
> [] in UndefinedObject>>DoIt {[count > 500000]}
> . . .
>
> What guarantee is there supposed to be that #nextObject won't loop
> back into a cycle? What did I do to break that guarantee and how
> can I reestablish it?
>
> cheers,
> Rob
>
More information about the Squeak-dev
mailing list
|