swarm-support
[Top][All Lists]
Advanced

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

More Swarm Beginner mistakes/questions


From: Paul Johnson
Subject: More Swarm Beginner mistakes/questions
Date: Mon, 1 Dec 1997 00:24:27 -0600 (CST)

As I make these mistakes and learn from them, I'm going to 
ask if I've learned the right lessons and then other
users might not blunder so badly.


Lesson 1.  Lists swallow objects and erase them.
I was surprised that an object, called "current", turned up
empty after I added this code:  

   policyList = [List create: [self getZone]];
     [policyList addLast: current];
    
I don't think the documentation makes it crystal clear that when
you add an object to a list, it disappears from view  and won't
answer messages anymore. Right?  The only way I could make
the rest of it work is this (an idea stolen from the observerBug
approach in on of the tutorials):

   current = [policyList removeLast];
     [policyList addLast: current]; 

This gets the last object from the list, calls it current AGAIN,
and puts it back in the list.  That makes the program run fine,
but it seems weird.

Question 1A: If things happen to the object "current" in the program, do they
happen to the object that was put into the list, brought back out, copied ?and
put back in? Know what I mean?

Question 1B: If the list actually did swallow the object, and it sure did
in this case, why am I able to add the second code to put values back into
the place holder "current"?  Shouldn't the name current have disappeared
and its memory been dropped by the process that put it in the list to
begin with?

Lesson 2.  There are some funky problems that can happen if you choose
swarm-official-names for things!  I had methods called getX and getY
that were used to access values from an object.  As long as the return
values were integers, it was OK. But when I changed them to floats,
all hell broke loose about conflicting definitions of getX and getY.  I
wish I had copied the exact compiler syntax, but it was telling me that
it was going to use (int)getX because it found that in
swarm-1.0.3/include/tk....  So I went through and renamed those methods
to getPolX and getPolY, and it works!  Is it generally known that you
can't have two methods of the same name if they have differnt return types? 

Lesson 3. The Grid2d space for zoomRaster accepts only integers,
right? so the drawSelfOn method would not work if the X and Y
are doubles.  However, if I just cast them as ints, I get "rounded"
output, right, so 14.544 is seen as 14 and the grid looks approximate?
Right? 

  (Here's the code.  ideal is a 2-D array of floats)

-drawSelfOn: (Raster *) r {
  [r drawPointX: (int) ideal[0] Y: (int) ideal[1] Color: 1];
  return self;

Lesson 4. The lack of a matrix algebra/vector passing ability seems to be a
problem for me.  If the ideal array were a ten dimensional thing, it would get
really inconvenient to individually refer to coordinates.  I've gotten around
some problems by passing in an object that contains such an array.  That
works, until one object has to tell the other what its array is. The only
way I can figure to pass them out is to write one method for each dimension and
give them one floating point number at a time. (Hence a method getPolX has to be
written that has "return ideal[0]" and a method getPolY has a "return ideal[1]"
and then the object that receives those messages converts them back into an
array with newarray[0]=[thatobject getX] and newarray[1]=[thatobject getY].

Well, as I said, I'm writing this down to document the Swarm beginner experience
and if you help answer my questions, I'll be happier for it.


Paul E. Johnson                           address@hidden
Dept. of Political Science                Office: (913) 864-9086
University of Kansas                      FAX: (913) 864-5700
Lawrence, Kansas 66045                    Home: (913) 842-9916                  
   


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