swarm-support
[Top][All Lists]
Advanced

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

Re: Averager usage


From: Ken Cline
Subject: Re: Averager usage
Date: Tue, 22 Jun 1999 09:30:27 -0400 (EDT)

Steve,

My initial guess: there is no setProbeSelector method
defined that takes 3 arguments; the one provided by Averager
protocol (actually by MessageProbe) takes only one argument,
i.e. `setProbeSelector:'.

Ignoring the compiler error for the moment, I'm not sure you
can use Averager like you are.  The `setProbedSelector:' is
suppose to be a create-time message, I believe, and although
the compiler probably can not enforce this requirement, the
runtime mechanism(s) may.

The possible work-arounds that pop into my head immediately
are: (1) subclass or modify the Averager class directly (and
maybe the matching protocol as well), (2) use some type of
closure or nested function (ala Java inner classes) or (3)
use another (possibly global, singleton) object to hold the
target pigment and species information when `update' is
called.  I think #3 is probably the easiest but feels a
little hackish.

For #3, I was thinking of something like:
     id target = [SpeciesPigmentInfo create: [self getZone]];
   > averageID = [Averager createBegin: [self getZone]];
   > [averageID setCollection: waterColumn];
     [averageID setProbedSelector: M(getValue)];
   > averageID = [averageID createEnd];
   > for (j=0;j<phyN;j++) {
   >   for (i=1;i<=4;i++) {
         [target setSpecies: j Pigment: i];
   >     [averageID update];
   >     printf("%e ",[averageID getAverage]);
   >   }
   > }

And, in each WaterClass*, we could have:
   -(double) getValue {
       id target = [ self getSpeciesPigmentSingleton ]
       return [ self getPigments: [target getPigment]
                         Species: [target getSpecies] ];
   }

Hmmm... actually you probably don't really need the
"SpeciesPigmentInfo" singleton, you can store this
information directly into each WaterClass.  That is, in the
inner for-loop, just before `[averageID update]', you could
have something like:
   [waterColumn forEach: M(setSpecies:Pigment:) : j : i];
and then modify the "getValue" method to retrieve the
values from `self'.

(IMHO, the first two options I suggested are more appealing
from a coding-style point of view.  One reason for this is
that they couple the selector with what is being selected.  
In a multi-threaded environment, hacks #3 & #4 would be
risky without using a little resource locking.  But I
digress... )

Well, I hope that helps.

Ken.

(*The `getValue' method goes in the WaterClass class and
not the WaterColumn class, since the Averager sends the
message to each member of the list and not the list itself.)

On Tue, 22 Jun 1999 address@hidden wrote:
> 
> waterID                = WaterClass object
> waterColumn            = List of WaterClass objects
> phytoID                = PhytoClass object
> phytoList              = List of PhytoClass objects   
> chla, chlb, chlc, caro = instance variables of phytoID
> each waterID has a phytoList
> 
> I want to calculate the average of each separate pigment
(chla..caro)
> for each individual species (phytoID) down the water
column. i.e. the
> Averager object must iterate:
> 
> foreach phytoID
>    foreach pigment in [chla, chlb, chlc, caro]
>       print average across waterColumn
>    }
> }
> 
> My clumsy effort resulted in:
>   
>   averageID = [Averager createBegin: [self getZone]];
>   [averageID setCollection: waterColumn];
>   averageID = [averageID createEnd];
>   for (j=0;j<phyN;j++) {
>     for (i=1;i<=4;i++) {
>       [averageID setProbedSelector: M(getPigments:Species:):(id)i:(id)j];
>       [averageID update];
>       printf("%e ",[averageID getAverage]);
>     }
>   }
> 
> This leads to a compiler error:
> 
> OceanClass.m:481: warning: return type for
> `setProbedSelector:::' defaults to id
>   [snip]
> but the error is probably in the syntax of the
> setProbedSelector method. Any help appreciated

_________________________________________________________
Ken Cline                             address@hidden
SAIC                                 VOICE (410) 571-0413
Annapolis, MD                          FAX (301) 261-8427






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