|
From: | Paul Johnson |
Subject: | Re: removing elements while looping with an index, and return values from Set add |
Date: | Wed, 20 Mar 2002 08:37:28 -0600 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020212 |
Ken Gosier wrote:
Hello all again. Many thanks for all the replies. I am now using index remove and not getting the seg faults. However, I am now having a new problem. I am able to resolve it myself, but not happy with my solution. Specifically, the removing of elements I posted yesterday actually takes place in a 2-step loop: for (i=0; i<2; i++) { id <List> newList = [List create: self]; id <Index> index = [oldList begin: self]; id thisElem; for (thisElem=[index next]; [index getLoc]==Member; thisElem=[index next]) { if ( condition[i] ) { [newList addLast: [index remove]]; } } [index drop]; ... do stuff with newList ... } I first want to get those elements that satisfy condition[0], then those that satisfy condition[1]. I find that everything goes smashing, wonderful in the first pass through. But then the second time through, the index steps off the end of the List, and I get seg faults, b/c messages get sent to nil id's.
If oldList is a Swarm Array, this could happen, because removing things puts nil in their place. Otherwise, I can't explain it.
Well, maybe I can. Am I right in guessing that your pseudo code like so: if ( condition[i] ) is in the actual program something more elaborate, like if (condition[i]== [thisElem getValue])otherwise this loop does not make any sense to me at all. Either all or none of the objects will get removed on the first pass, and then on the second pass the list will be empty and, I have a hazy recollection that everything goes to hell if you try to create an index from an empty Swarm Collection.
-- Paul E. Johnson email: address@hidden Dept. of Political Science http://lark.cc.ku.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.
[Prev in Thread] | Current Thread | [Next in Thread] |