[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: List: forEach: arg1;
From: |
Ken Cline |
Subject: |
Re: List: forEach: arg1; |
Date: |
Wed, 5 Mar 1997 09:16:27 -0500 (EST) |
On Wed, 5 Mar 1997, Kevin Crowston wrote:
> "Ludo Pagie" <address@hidden> wrote:
>
> >-addConcentration: (double) c;
>
> >[metabList forEach: M(addConcentration:) : myarg];
> >with:
> >
> >>reaction.m: In function `_i_Reaction__react_':
> >>reaction.m:38: incompatible type for argument 4 of indirect function call
>
> It helps to know that a message send is basically syntactic sugar for a
> function call--the line above is (more or less) turned into the function
> call:
>
> _i_Reaction__react_(metabList, sel, M(addConcentration), myarg)
>
> So argument four is myarg.
>
> >without this line the program compiles (and runs) fine. I guess that the
> >argument 4 is an argument of one of those (?) run-time function-calls (eg.
> >"objc_msgSend" in Next Objective C, don't know about Swarms run-time system).
>
> The incompatible type comes because the forEach:: expects to get id's as
> arguments, and you're passing a double. I had similar problems in my
> simulation. What I ended up doing was: (1) switching to float's, since
> they're the same size as id's, at least on a Sun--you might want to verify
> this on whatever you're using. (2) passing the float as an id--this was a
> bit ugly, since it turns out you can't simply cast a float to a pointer.
> What I ended up doing was taking a pointer to my float, casting it to a
> pointer to an id, and deferencing the pointer... ugly at best. If I
> remember correctly, it looked like:
>
> (*((id*)(&f)))
>
> There's probably a more elegant way, but I think this worked.
>
> Kevin
>
Of course you could abandon the "forEach" method:
-react: (ChemicalModelSwarm*) chemicals{
id metabList; // this is a List
id metabListIndex; // this is a List Index
id metabListMember;
double myarg;
myarg=[uniformDblRand getDoubleWithMin: 0.0 withMax: 1.0];
metabList=[chemicals getMetaboliteList];
// I'm not sure whether you wanted to "addConcentration"
// to the first one twice ??
[ [metabList getFirst] addConcentration:myarg];
metabListIndex = [metabList begin: [self getZone] ];
while ( metabListMember = [metabListIndex next] ) {
[ metabListMember print ];
[ metabListMember addConcentration: myarg ];
}
[metabListIndex drop];
return self;
}
Just another option...
Ken.
_________________________________________________________
Ken Cline address@hidden
SAIC VOICE (410) 571-0413
Annapolis, MD FAX (301) 261-8427
- List: forEach: arg1;, Ludo Pagie, 1997/03/05
- Re: List: forEach: arg1;, Kevin Crowston, 1997/03/05
- Re: List: forEach: arg1;,
Ken Cline <=
- Re: List: forEach: arg1;, Roger M. Burkhart, 1997/03/05
- Re: List: forEach: arg1;, glen e. p. ropella, 1997/03/05
- Re: List: forEach: arg1;, Roger M. Burkhart, 1997/03/05
- Re: List: forEach: arg1;, Kevin Crowston, 1997/03/05