swarm-support
[Top][All Lists]
Advanced

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

Re: problems (2)


From: Alex Lancaster
Subject: Re: problems (2)
Date: 20 Aug 2001 00:23:35 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.104

>>>>> "HP" == Holger Perlt <address@hidden> writes:

HP> Hello, here are two questions:

HP> 1.There is a major(?) )difference in tutorial/SimpleSwarmBug3
HP> between the printed version and the swarmapps_2.0.1 program
HP> concernig the reading in of the parameter data.  In the printed
HP> version (the older one) it is realized inside ModelSwarm.m with

HP> [ObjectLoader load: self fromFileName: "model.setup"]

HP> This seems rather obvious.  In the actual program it is realized
HP> inside main.m with

HP> if ((modelSwarm [lispAppArchiver getWithZone: globalZone key:
HP> "modelSwarm"]) == nil) raiseEvent(InvalidOperation, "Can't find
HP> the modelSwarm parameters");

HP> which is somewhat more complicated to understand. 

It may be clearer if you separate the two statements, like so: 

 modelSwarm = [lispAppArchiver getWithZone: globalZone key: "modelSwarm"];
 if (modelSwarm == nil) 
   raiseEvent(InvalidOperation, "Can't find the modelSwarm parameters");

The first line creates a "modelSwarm" object using the parameters
listed in the "bug.scm" file (as described in the README, by default
it will look for a file with same name as the application).  So you
merely need to create a file with the name of the application, and
Swarm "automagically" reads it.  One of the advantages of the archiver
is that you can have many objects and their parameters in the same
text file, e.g.:

(list 
 (cons 'modelSwarm1
       (make-instance 'ModelSwarm
                      #:worldXSize 80
                      #:worldYSize 80
                      #:seedProb 0.9F0
                      #:bugDensity 0.01F0))
 (cons 'modelSwarm2
       (make-instance 'ModelSwarm
                      #:worldXSize 100
                      #:worldYSize 100
                      #:seedProb 0.1F0
                      #:bugDensity 0.01F0))
)

You could then use a command-line parameter to conditionally create
one type of modelSwarm or the other.

The second line is just trapping an error.  It may look more
complicated, but it's actually an improvement, since in the old
version it may silently fail without you knowing what's happened.  In
this version you have an explicit message telling you that there has
been a problem locating the information about the "modelSwarm" object.

HP> Especially I do not see where the filename "bug.scm" comes into
HP> the game. In this file the corresponding parameter values are
HP> defined.

In general, the README is a good place to start investigating such
things!  Swarm tutorial version 2.1.1 should have this text.  Please
let me know if any part of this is unclear.  Here's the relevant
excerpt:

  In main(), we take advantage of an the default `lispAppArchiver'
  global singleton variable to read in the state variables of the
  ModelSwarm from a file.  Every Swarm application has an instance of
  the `lispAppArchiver', by default, the `lispAppArchiver' looks for a
  file with the name <appname>.scm.
  
  In this case, <appname> = `bug', so the expected filename is
  `bug.scm'.
  
  [Note: If this file does not exist all call to the `lispAppArchiver'
  will return `nil'.  See the `mousetrap' application to see how to use
  the Archiver feature with alternative filenames].
  
  Each file can have as many named objects as the user wishes (the user
  has control over the names, which are simply strings).
  
  Now, we can change the parameters of the model by editing the file
  `bug.scm', which has a simple Lisp-like format:
  
  (list 
   (cons 'modelSwarm
         (make-instance 'ModelSwarm
                        #:worldXSize 80
                        #:worldYSize 80
                        #:seedProb 0.9F0
                        #:bugDensity 0.01F0)))
  
  So, we name the copy of the object `modelSwarm', and ask it to
  `make-instance' of the class `ModelSwarm' with the instance variables
  as described.  [Note the special `F0' after the end of the number,
  this is to tell Archiver to create a `float' instance variable rather
  than `double', which is what it will do by default.]
  
  In main.m we simply `ask' the Archiver to create a copy of the object
  with the name `modelSwarm', the lispAppArchiver takes care of the
  instantiation of the object (i.e. running the createBegin/createEnd on
  the object) internally.
  
  [The `lispAppArchiver' can also write the object state back to a file,
  with the `putShallow:' and `putDeep:' methods.  Not discussed here].

For furhter usage, background and rationale for the "archiver" classes
see the Swarm User Guide, chapter 16, "Serialization":
 
 
http://www.santafe.edu/projects/swarm/swarmdocs/userbook/swarm.user.user3.05.chapter.html

HP> 2. I wanted to add a new simple method (setEat) to the
HP> bug-class. But the compilation failed due to some
HP> inconsistencies. From make I get the following message:

HP> address@hidden:~/swarmapps-2.0.1/mytests/test2 > make gcc -c -g -O2
HP> -Wall -Wno-import -Wno-protocol -Werror -D_GNU_SOURCE
HP> -DAPPNAME=bug -DAPPVERSION=2.0 address@hidden
HP> -I/usr/local/include Bug.m cc1obj: warnings being treated as
HP> errors Bug.m:69: warning: incomplete implementation of class `Bug'
HP> Bug.m:69: warning: method definition for `-setEat:Y:' not found
HP> make: *** [Bug.o] Error 1

HP> I attach the correspondig files (Bug.m, Bug.h, ModelSwarm.m) for
HP> better understanding.

This is simple.  You've defined a `-setEat:Y:' method in your header
file `Bug.h' file, but not in your implementation file `Bug.m'.  If
you just want to compile it, create a `dummy' method, then you can
experiment with the implementation:

- setEat: (int)x Y: (int)y {
  return self;
}

to `Bug.m'.  If you define a method for your object's "interface", you
must implement, otherwise you get the "incomplete implementation"
message.

Alex
-- 
   Alex Lancaster * <address@hidden> * www.santafe.edu/~alex 
Dept. of Integrative Biology, UC Berkeley (ib.berkeley.edu) * +1 510 642-1233
    & Swarm Development Group, Santa Fe, New Mexico (www.swarm.org) 

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