swarm-support
[Top][All Lists]
Advanced

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

passing by reference


From: Paul Johnson
Subject: passing by reference
Date: Thu, 24 Feb 2000 11:54:10 -0600

I'm doing an exercise where I want to pass an object by reference, but
I'm missing something. I think that what's confusing me is that an id is
a pointer. 

Suppose the standard swarm setup (ModelSwarm creates objects, tells them
to do stuff).

Suppose the ModelSwarm declares 

  id proposal;

and then in its schedule, one of its actions is to ask an agent called
aSetter for a proposal object, as in

   [modelActions createActionTo:  aSetter  message: M(makeProp:):
proposal];


It seems like no matter how I fiddle the makeProp: method, however, the
proposal is always nil in the ModelSwarm after that scheduled step has
executed.  My first try was like so:

-makeProp: obj
{
    code here does createbegin/createEnd on a new object,  "newobj"
    
    diagnostics confirm that within this scope, the thing obj does exist
and it responds to messages.

    to try to pass it back out, I say

    obj=newobj; 

    return self;
}

However, the ModelSwarm never gets the thing proposal back from the
object.

I saw after some study that I probably need to declare the method like
so:

-makeProp: (id *) obj
{
   after I create a new object "newojb",  
   What do I do?
      *obj= newobj;
}
   Does not work, the proposal variable in ModelSwarm is still nil after
it.

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



reply via email to

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