[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help on walking lists of Swarm Collection
From: |
Paul E. Johnson |
Subject: |
Re: Help on walking lists of Swarm Collection |
Date: |
Sat, 08 May 1999 10:18:24 -0500 |
"William S. Shu" wrote:
>
> A bit of assitance please:
> I have been having very strange errors (segfaults) and my primary suspicion
> now is the use of indexes (in collections) to walk a list of objects. This
> is because methods call methods which add/remove from the list via their own
> created indices. The manual clearly warns about this. So I decide to use
> atOffset:, and forEach: methods where possible. I use atOffset like so:
>
> id <List> colonyList;
> ....
> int count, i;
> .....
>
> count = [colonyList getCount];
> for (i = 0; i < count; ++i) {
> cly = [colonyList atOffset: i];
> if (...condition ...) { // remove base on certain condition
> ...
> [colonyList remove: cly];
> ...
> }
> ...
> }
>
> My trouble is, the loop removes entries from colonyList, which makes my
> value of count incorrect and (by the manual) triggers an exception.
> Computing the count each time round the loop is NOT helpful as the list may
> actually increase in size (via some other method invoked in the above code)
> and hence not terminate when desired. Any ideas?
My first thought is that you ought to use the Swarm index to do these
iterations. There is some in the FAQ about how you can create an index
object, and then use a while statement to step through a list.
My second thought is that you ought to study SwarmSugarScape (sss) from
the swarm ftp site. It does a procedure in which objects are assigned
to a death list called a "reaperQue" and then they are dropped.
> I will welcome any suggestions on how to handle the above. One thing I was
> thinking was why the List protocol (assumed to be like a singly-linked, or
> perhaps doubly-linked, list) does not contain a 'next' and related methods
> to walk a list. This would be most natural for lists, and save one the
> trouble of crashing indices!
>
That's what the builtin list index objects are for
--
Paul E. Johnson email: address@hidden
Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.