[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Drop doesn't work after createBegin:,createEnd:
From: |
Rick Riolo |
Subject: |
Re: Drop doesn't work after createBegin:,createEnd: |
Date: |
Sun, 1 Feb 1998 09:40:10 -0500 (EST) |
Hi Benedikt,
I tried what I think is a very simple test of what you did
(almost..see below) and I don't get a crash.
Here is my main.m (i've left out imports, etc):
int main(int argc, char ** argv) {
id bug;
initSwarm(argc, argv);
bug = [Heatbug1 createBegin: globalZone];
[bug setIdealTemperature: 100];
[bug setOutputHeat: 110];
bug = [bug createEnd];
[bug printSelf];
printf("\ngetIdealTemperature -> %d.\n",
[bug getIdealTemperature] );
[bug drop];
printf("just dropped the bug...bye!\n");
return 0;
}
---------------------------------------------------------------
Here is the interface:
@interface Heatbug1: SwarmObject {
double unhappiness;
HeatValue idealTemperature;
HeatValue outputHeat;
}
-createEnd;
-(double) getUnhappiness;
-(HeatValue) getIdealTemperature;
-(HeatValue) getOutputHeat;
-(void) setIdealTemperature: (HeatValue) i;
-(void) setOutputHeat: (HeatValue) o;
-(void) printSelf;
@end
------------------------------------------------------------------
Here is the Heatbug1.m:
@implementation Heatbug1
-createEnd { return self; }
-(double) getUnhappiness {
return unhappiness; }
-(HeatValue) getIdealTemperature {
return idealTemperature; }
-(HeatValue) getOutputHeat {
return outputHeat; }
-(void) setIdealTemperature: (HeatValue) i {
idealTemperature = i; }
-(void) setOutputHeat: (HeatValue) o {
outputHeat = o; }
-(void) printSelf {
printf( "printSelf Heatbug values:\n" );
printf( " unhappiness: %.2f\n", unhappiness );
printf( " idealTemperature: %d.\n", idealTemperature );
printf( " outputHeat: %d.\n", outputHeat );
}
@end
------------------------------------------------------------------
Here is a run:
badger-rlr)heatbugs1
printSelf Heatbug values:
unhappiness: 0.00
idealTemperature: 100.
outputHeat: 110.
getIdealTemperature -> 100.
just dropped the bug...bye!
badger-rlr)
------------------------------------------------------------------
So what are the differences between what I did and what you did:
1) I createBegin in the globalZone directly
(since this is not happening inside another object, so I can't
do a [self getZone]).
2) My createEnd doesn't do anything except return self.
3) Lots of other stuff, since my example is so simple...
I modified the above program by adding a -createABug method,
which just does:
-createABug {
id bug;
printf("ask a bug to create a bug...\n");
bug = [Heatbug1 createBegin: [self getZone]];
[bug setIdealTemperature: 100];
[bug setOutputHeat: 110];
bug = [bug createEnd];
[bug printSelf];
[bug drop];
printf("\nthe created sub-bug now dropped.\n");
return self;
}
So in main.m before I drop the bug, I ask it to createABug
and drop it. That works ok too, at both levels,
so I don't think its connected to [self getZone].
So....I must be missing something from your examples.
Is my createEnd not doing something that yours does?
Am I missing something else?
- r
ps this is all swarm-1.0.5 .
Rick Riolo address@hidden
Program for Study of Complex Systems (PSCS)
4068 Randall Lab
University of Michigan Ann Arbor MI 48109-1120
Phone: 313 763 3323 Fax: 313 763 9267
http://www.pscs.umich.edu/PEOPLE/rlr-home.html
On Fri, 30 Jan 1998, Benedikt Stefansson wrote:
> Date: Fri, 30 Jan 1998 19:21:50 -0800
> From: Benedikt Stefansson <address@hidden>
> To: address@hidden
> Subject: Drop doesn't work after createBegin:,createEnd:
>
> Hi,
>
> I guess Roger is the one to answer this one. It's one of my pet peeves
> with Swarm, and I've never been able to figure it out from the docs.
>
> Here's the deal: If you override the createEnd: method with your own and
> use the
>
> agent=[Agent createBegin: [self getZone]];
> (set some parameters)
> agent=[agent createEnd]
>
> form, and later call [agent drop] on this agent, you get a run-time
> error, and SIGABRT crash. The crash message looks like this:
>
> error: Zone_c.Creating (class)
> Zone_c.Creating does not recognize dropAllocations:
>
> Now, if I change the -createEnd method name in the agent to something
> like "initialize" and use
>
> agent=[Agent create: [self getZone]];
> (set some parameters)
> agent=[agent initialize];
>
> the subsequent [agent drop] call works. Seems odd and inconsistent to
> me, and the docs make no mention of it.
>
> I think that this defies the whole purpose of introducing two different
> "protocols" for creating objects in the first place, i.e.simple create
> vs. createBegin,createEnd
>
> I guess my question is, is this a bug or a feature?
>
> Regards,
> -Benedikt
>
> ------------------
> Benedikt Stefansson address@hidden
> Department of Economics, UCLA Fax. (310) 825-9528
> Los Angeles, CA 90095-1477 Tel. (310) 825-4126
>
>
>
> ==================================
> 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.
> ==================================
>
==================================
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.
==================================
- Re: Drop doesn't work after createBegin:,createEnd:,
Rick Riolo <=