|
From: | Paul Johnson |
Subject: | Re: removing elements while looping with an index, and return values from Set add |
Date: | Wed, 20 Mar 2002 09:03:08 -0600 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020212 |
Ken Gosier wrote:
--- Paul Johnson <address@hidden> wrote: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])It is pretty much like this, except that the conditions are not mutually exclusive. That is, in oldList, you have 3 types of elements: - Those that satisfy condition[0] - Those that satisfy condition[1] - Those that satisfy neither. Basically, the problem is that the elements that satisfy condition[0] will get removed. Then when I'm looping to find those that satisfy condition[1], the index falls off the end of the List.
An index cannot "fall off" the end if you iterate like so: for (thisElem=[index next]; [index getLoc]==Member; thisElem=[index next])As long as the thing is a Member, it gives it to you. What you might not realize is that a nil object can be in a collection.
Now, if your index finds a nil element in your collection, that means you have a nil element in the collection. It does not mean you stepped off the end. So we need to find out how the nil got into your collection.
I was guessing before that happened because you removed an element from an Array, but if your oldList is just a List object, then it must mean at some time that you did the equivalent of:
[oldList addLast: nil] or you inserted an undefined thing into a collection. I'd test by writing a diagnostic loop on oldList to find out what is in it. pj -- 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] |