cyclic looping with [0 == object] whileFalse: [object := object
rootbeer at redcat.com
Mon Nov 5 17:57:54 UTC 2007
On 11/5/07, Rob Withers <reefedjib at yahoo.com> 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?
I think that would be the surrounding code. Certainly sending
#nextObject can't always succeed; it should eventually run out of real
objects and return zero. If you send #nextObject to 0, a SmallInteger,
it should fail for sure.
> object _ nil.
> [0 == object or: [count > 500000]] whileFalse: [
This should drop out when 0 is encountered, or when 500000 objects
have been counted. The first should eventually happen, and so should
the second. Are you sure you let this loop run long enough?
But I've got to say it seems odd that the loop starts at nil. Most
users of #nextObject don't use it like that, since nil isn't
guaranteed to be at any particular place in the enumeration of all
objects. Shouldn't it be something like this?
object := self someObject.
> What guarantee is there supposed to be that #nextObject won't loop back into
> a cycle?
Zero is the guarantee.
> What did I do to break that guarantee and how can I reestablish
I don't think you broke it, unless you redefined
SmallInteger>>nextObject or something like that.
Hope this helps!
More information about the Squeak-dev