swarm-support
[Top][All Lists]
Advanced

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

question about copying agents


From: Paul E. Johnson
Subject: question about copying agents
Date: Tue, 13 Apr 1999 14:17:45 -0500

I got to reviewing some old swarm mail and I came again to the question
of how agents can be copied.  I found a note by Roger saying that,if you
only need to create a "shallow" copy, you can do so by copyIVars.  He
has a recommendation like this:

 Right now, if you want a
Swarm-style copy: message, all you have to do is the copy the following
method into your class:

- copy: aZone
{
return [aZone copyIVars: self];
}
(http://www.santafe.edu/projects/swarm/archive/list-archive.9702/0053.html)

What does "shallow" mean, as opposed to "deep"?

Here is what I really want to know, I guess:  

Is it correct that the copyIVars method will create a new memory
allocation and the new thing created will exist "as if" it had all the
createBegin/createEnd stuff done to it that was done to the original? 
In heatbugs, suppose you look at the heatbugModelSwarm.  Could you just
create one heatbug, call it "aHeatbug" and then clone it over and over
with repeated calls like:
   for(i=0;i<N;i++)
{
   [newHeatbug=[self copyIVars: aHeatbug ];
   [heatbugList addLast: newHeatbug];
}
(I think this works because heatbugModelSwarm is a Zone, right?).

Does this give you a list of bugs, all of whom are interchangable with
the original?

What "deep" stuff does not get copied over?

In particular, if you created a subclass from Heatbug and called it
Coolbug, and then added some instance variables, would the copyIVars
applied to Coolbug catch all the variables of Coolbug, including the
ones it inherits from the superclass? I have the fear that the "shallow"
versus "deep" distinction means copyIVars might not pick up all of the
inherited instance variables.

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