cyclic looping with [0 == object] whileFalse: [object := object nextObject].

Tom Phoenix rootbeer at
Mon Nov 5 18:14:22 UTC 2007

On 11/5/07, Mathieu Suen <mathk.sue at> wrote:

> 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).

You've almost got the right idea; #nextObject doesn't return
SmallIntegers normally, just items from the object memory. But it does
return 0 at the end, as the indicator that there are no more objects
to enumerate. Of course nil can't be returned to mean no more elements
because it is one of the objects in memory that #nextObject actually
does return. If a programmer were to invoke SmallInteger>>nextObject,
that method should use #shouldNotImplement or something similar to
stop the potential infinite loop.

Additionally, remembering the initial object so as to recognize it
when it "comes around again" doesn't generally work. After all, once
the last SmallInteger is incremented, it becomes some LargeInteger,
which is a new object in memory, so #nextObject would continue on from
that one toward the end of the object memory, likely never returning
to the initial object. That's why users of #nextObject always check
whether it returns 0.


--Tom Phoenix

More information about the Squeak-dev mailing list