swarm-support
[Top][All Lists]
Advanced

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

Re: pass an ivar name through as an argument to a method?


From: Benedikt Stefansson
Subject: Re: pass an ivar name through as an argument to a method?
Date: Tue, 07 Mar 2000 13:10:56 -0700

Fernando Diaz wrote:

> passing ivar references around is fragile.  if you want this type of
> dynamic assignment, i would set up some sort of keyed collection in the
> Agent which contains its possible contexts ("home","work").  that way you
> can toss in new contexts on the fly ("mall").

This is exactly what ProbeMaps are for. The Swarm libs were ahead of the
curve in 'reflection', where a class can reveal to the world which methods it
responds to and which ivars it contains.

In fact the main reason for subclassing from SwarmObject instead of
CreateDrop is that SwarmObject gives you probe maps and thus reflection.

The following code for example prints out all the ivars and methods in self:

index = [[self getProbeMap] begin: [self getZone]];

for (probe = [index next]; [index getLoc] == Member; probe = [index next])
{
    if(([probe class] == [VarProbe class]))
        printf("Ivar %s,value %f\n",[probe getProbedVariable],[probe
probeAsDouble: self]);
    else
        printf("Method %s\n",[probe getProbedMessage]);
}
[index drop];

There are of course different ways to use this information, reading the
swarmdocs and playing around with simple examples will be useful.

In particular note that in all the ObserverSwarm, ModelSwarm examples in
swarmapps such as heatbugs a specialized probe map gets built, this is the
easiest way to create a map of variable probes that one would like to iterate
through.

Benedikt

--
Benedikt Stefansson      | address@hidden
CASA, Inc.               | Ph : (505) 988-8807 x101
Santa Fe, NM 87501       | Fax: (505) 988-3440




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