swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Want to delete item from list. Can't understand archived notes


From: Paul E. Johnson
Subject: Re: Want to delete item from list. Can't understand archived notes
Date: Wed, 22 Jul 1998 15:47:17 -0500 (CDT)

Dear everybody:
  This is a public expression of gratitude to Ken, Doug, and Benedikt, who
took me to school on lists over the past week.  I've now thoroughly 
investigated the various options and here is what I learned.  I left all
the stuff in the note below for reference.

  1. I never got Doug's method to work, probably for reasons that Ken
sensed.  The removeIndex=index command, and variants that Ken suggested,
seem to be the source of a run time crash.  There is probably a way to 
make it work, but I am not able to.

  2. Ken's three stage approach worked just as he had written it.  it
successfully picks the top ranked alternative and moves it over. 
The clear separation of the steps is (I think) the key to success here.
Thanks a ton.

Now Just one more question.
  Sometimes while statements using indexes are written like this:     
      while (( aRecruiter=[index next]))
  and other times, by other people, they are written like this
      while (( [index next] != NULL)
  and yet other times it is
      while (( aRecruiter = [index next] != NULL))

Why these differences?  It seems to me the !=NULL is superfluous ?
And including the object name gives something to reference inside the
while?
pj 


On Tue, 21 Jul 1998, Ken Cline wrote:

> 
> On Fri, 17 Jul 1998, Chimera wrote:
> 
> > In your case, I wonder if you could just:
> > 
> >   index = [invitationsList begin: [self getZone]];
> >   removeIndex=[invitationsList begin: [self getZone]];
> >   while (( aRecruiter = [index next]) )
> >   {
> >      proposal= [aRecruiter getProposal];
> >      disutility = [self distFromIdeal: proposal];
> >      if( disutility < bestValue )
> >      {
> >         bestValue=disutility;
> >         bestAlternative=aRecruiter;
> >         removeIndex=index;
> >      }
> >   }
> >
> >   [invitationsRanking addLast: bestAlternative];
> >   [removeIndex remove];
> >   //  Remember to drop indexes
> >   [removeIndex drop];
> >   [index drop];
> > 
> 
> I haven't try this code either, but it seems like the line
> "removeIndex=index;" would cause a bug.  Maybe it should be
> "removeIndex=[index copy:[self getZone]];" or perhaps
> "[removeIndex setOffset: [index getOffset]];".
> 
> You might try breaking the code into several parts:
> 
> #define MAX_IDEAL 100000.0
> 
> -(double) getValueFor: (id) aRecruiter {
>    return [ self distFromIdeal: [(Recruiter *)aRecruiter getProposal] ];
> }
> 
> -(int) getMinOffsetFrom: (id <List>) aList {
>    id <Index> index    = NULL;
>    id         element  = NULL;
>    int        offset   = 0;
>    double     min      = MAX_IDEAL;
>    double     value    = MAX_IDEAL;
> 
>    index = [ aList begin: [self getZone] ];
>    while ( (element = [index next]) != NULL ) {
>       value = [self getValueFor: element];
>       if ( value <= min ) {
>          min = value;
>          offset = [ index getOffset ];
>       }
>    }
>    [ index drop ];
>    return offset;
> }
> 
> -(void) moveBestFrom: (id <List>) invitations
>                   To: (id <List>) rankings     {
>    id <Index> index = NULL;
> 
>    index  = [ invitations begin: [self getZone] ];
>    [ index setOffset: [self getMinOffsetFrom: invitations] ];
>    [ rankings addLast: [index remove] ];
>    [ index drop ];
> }
> 

Paul E. Johnson                       email: address@hidden
Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
University of Kansas                  Office: (913) 864-9086
Lawrence, Kansas 66045                FAX: (913) 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.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]