swarm-support
[Top][All Lists]
Advanced

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

[Swarm-Support] puzzlng question about message passing and types


From: paul box
Subject: [Swarm-Support] puzzlng question about message passing and types
Date: Mon, 27 Feb 2006 14:59:51 +0930

Hello all

I'm not sure if this issue I'm describing has been addressed earlier. 
It works, but I'm disturbed by not understanding why it works.

I have a grid2d populated with cells.  I wish to make it rain on the
cells, with rainclouds (called RainZones) selecting a group of cells
on the surface and sending rain to them.

extract from Cell.h:

@interface Cell: SwarmObject {
....
  double rainLevel;
}

...
-addRain: (double) rf;
...
@end

extract from Cell.m:

-addRain: (double) rf {
  rainLevel += rf;
  return self;
}

extract from RainZone.m, making it rain on a selected collection of cells:

-makeItRain {

  double rainfall;

  // rainGen is a LogNormalDist object, which returns double numbers
  rainfall = [rainGen getDoubleSample];
 // printf ("rainzone %d dumping %g mm of rain\n", rainzoneID, rainfall);
  [cellList forEach: M(addRain:) : (int) rainfall];

  return self;
}

Since Rainfall is a double, the last command in makeItRain should read
  [cellList forEach: M(addRain:): rainfall]

but that will not compile, for obvious reasons (incompatible type for
argument 2 of 'forEach::')

However, casting the number as an integer, passing it to
Cell_addRain() , and having Cell_addRain() accept it as a double seems
to work fine (compiles and runs, with Cells receiving and storing
correct numbers).  I find this very disturbing.  Why would that work? 
And is there a more "honest" way to make it work?

--
//////////////////////////
// Paul Box
// Alice Springs, NT  Australia
//



reply via email to

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