swarm-hackers
[Top][All Lists]
Advanced

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

Re: [swarm-hackers] Re: Swarm, Heatbugs, and forEach loops...


From: Scott Christley
Subject: Re: [swarm-hackers] Re: Swarm, Heatbugs, and forEach loops...
Date: Tue, 10 Nov 2009 18:13:51 -0800

Well this works but I wouldn't encourage it.

This issue illustrates the fundamental question of how can Swarm support both its internal collections classes as well as the OpenStep collections at the same time.  I don't have a good answer for this.

One thing that could be done is to use the reflection capability of ObjC to query the class and do the appropriate code, such as:

if ([anObj isKindOfClass: [List class]]) // do List code
if ([anObj isKindOfClass: [NSArray class]]) // do NSArray code

But the use of collections is pervasive, so this would require lots of code changes.

A second idea is to have separate implementations of the Swarm classes, one that uses Swarm collections and the other that is OpenStep.

A third idea is to change the Swarm's List class to actually be implemented by an NSArray underneath.  Then programs using List will actually be using NSArray without knowing it.  Then additional methods would be added to the NSArray class so that it responds to List methods.  Then they could be used interchangeably.

The last idea is probably the least intrusive but still might have quite a few challenges to make work correctly.

Scott

On Nov 10, 2009, at 5:06 PM, Nima Talebi wrote:

Hi Scott,

Okay I now have a working solution - I did so by implementing a new ADT called SwarmColony (SwarmCollection was taken, and SwarmList and SwarmArray leaked too much about the "how" which I want to hide).

http://git.autonomy.net.au/?p=heatbugs;a=summary (I've created an experimental branch there called exp-ListToADT).

...this new type acts as both a id<List>, as well as a NSArray, but all that is hidden.  The only thing that needs to be changed in other code is this...

actionForEach = [modelActions createActionForEach:[heatbugList selector] message:M(step)];

...Next, I will change the variable name heatbugList to hbugColony.

Thoughts?

Nima


On Wed, Nov 11, 2009 at 10:57 AM, Nima Talebi <address@hidden> wrote:
Hi Scott,

Regarding NSArray - I did consider doing that, but then I hit the following problem...

- (id <ActionForEach>)createActionForEach: target message: (SEL)aSel;

...we call that when creating an action in the HeatbugModel class as follows...

actionForEach = [modelActions createActionForEach:heatbugList message:M(step)];

...however if heatbugList is converted to an NSArray, it will no longer be a valid SEL.

How do you suggest I tackle this?  My guess is that you don't want any changes made to the framework, as this will probably break everything, but perhapse there's a way I can create a heatbugList object that conforms to <List> as well as being an NSArray if that's even possible?

Nima


On Wed, Nov 11, 2009 at 3:46 AM, Scott Christley <address@hidden> wrote:
Hey Nima,

Swarm was a written a long time ago before there was a framework like OpenStep available, so it had to implement many of its own collection classes, like List, and as you can see the interface seems somewhat foreign.

My suggestion would be to try changing Heatbugs so that it uses an NSArray instead of List.  Then you can do you operations using standard OpenStep code.  I think making the Heatbugs code look as close as possible to a normal OpenStep application is good.

Otherwise, I think your code is ok.  One major functionality that is missing from the OpenStep version of Swarm is the probe display.  This essentially provides a popup window to do very similar to what you have done, though the probe display is more general and provides display and edit capability to all of a Heatbug's instance variables.

Scott

On Nov 10, 2009, at 5:44 AM, Nima Talebi wrote:

Nevermind, I figured it out.

I've updated my clone of Heatbugs (git tree), which now allows user to interact with the state of the Heatbug agents, changing their idealTemp and outputHeat minimums and maximums.

I did that like so...

- (void)reconfigureHeatbugs {
    [heatbugList forEach:M(setRandomIdealTemperatureInRange:to:) :minIdealTemp :maxIdealTemp];
    [heatbugList forEach:M(setRandomOutputHeatInRange:to:) :minOutputHeat :maxOutputHeat];
}

...and each time the user moves the sliders, MyDocument calls this method...

- (IBAction)setMaxOutputHeat:(id)sender {
    ...
        int tA = min([sender intValue], (int)[sender maxValue] - 100);
        [swarm setMaxOutputHeat:NSInt(tA)];
        
        int tB = min(tA, [[swarm minOutputHeat] intValue]);
        [swarm setMinOutputHeat:NSInt(tB)];
        [minOutputHeat setIntValue:tB];
        [minOutputHeat setNeedsDisplay];
        
        [swarm reconfigureHeatbugs];
   ....
}


...does anyone see anything wrong with that?  I ask because I still feel a little daunted by the amount of code in this framework, so I'm never quite certain that I'm going about things the right way.

Nima

On Tue, Nov 10, 2009 at 9:52 PM, Nima Talebi <address@hidden> wrote:
Hi, I'm a little confused (as I usually am looking at Swarm) on how iteration is supposed to work...

I have added some sliders and input widgets to my own branch of heatbugs, and so each time the user acts on these input widgets, I need to update the state variables stored in each Heatbug object.

For example, I would like to have something like this...

- (void)reconfigureHeatbug:(Heatbug *)hbug;

- (void)reconfigureHeatbugs {
    int i;
    Heatbug *hbug;
    for(i=0; i<numBugs; i++) {
        hbug = [heatbugList objectAtIndex:i];
        [self reconfigureHeatbug:hbug];
    }
}    

Of course that's not possible, as the heatbugList is not an NSArray, it is an id conforming to the <List> protocol.  Looking at surrounding code, I think maybe I'm supposed to do something along the lines of...

- (void)reconfigureHeatbugs {
    id fEAction = [modelActions createActionForEach:heatbugList
                                            message:M(reconfigureHeatbug:)];
}

..but that's obviously wrong since I have no idea what I'm doing - and what is M?

As a side-question - What would make life easier is being able to highlight a function/method/class/whatever in Xcode - say M - then right-click and select 'Jump to definition' - Anyone know how I can get that working?

Nima



--
Nima Talebi
web: http://ai.autonomy.net.au/People/Nima
gpg: B51D 1F18 D8E2 B702 B027 23A4 E06B DAC1 BE70 ADC0
_______________________________________________
swarm-hackers mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/swarm-hackers


_______________________________________________
swarm-hackers mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/swarm-hackers




--
Nima Talebi
web: http://ai.autonomy.net.au/People/Nima
gpg: B51D 1F18 D8E2 B702 B027 23A4 E06B DAC1 BE70 ADC0



--
Nima Talebi
web: http://ai.autonomy.net.au/People/Nima
gpg: B51D 1F18 D8E2 B702 B027 23A4 E06B DAC1 BE70 ADC0
_______________________________________________
swarm-hackers mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/swarm-hackers


reply via email to

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