swarm-support
[Top][All Lists]
Advanced

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

Re: Java examples


From: Benedikt Stefansson
Subject: Re: Java examples
Date: Tue, 08 Feb 2000 13:30:21 -0700

The Globals.env.uniformIntRand is I believe an instance of the
UniformIntRand class, which is created when you call
Globals.env.initSwarm (...) - see for example StartHeatbugs.

This is analogous to the Objective-C API where you call initSwarm(...) to
'rev up the Swarm engine', i.e. create the memory zone in which the top
level objects can be built, create an instance of a RandomGenerator and
instances of the Uniform* distribution classes.  Check out the original
heatbugs code.

Since Java has no 'global variables' the Globals class is used as a
proxy. In Objective-C one can use tricks (i.e. create stuff in main) to
conjure global variables.

Thus you are right, you can either explicitly create an instance of the
UniformIntRand class for yourself (either seeding it from the global
random generator or creating a random generator for this purpose). But in
simpler models there is no need to go through these machinations - the
random generator and uniform distributions are already there as ivars of
the Globals class (or global variables in the Objective-C version).

Benedikt

Charles Staelin wrote:

> Marcus,
>
> Thank you.  I'm getting there.  I can instantiate classes
> just fine using the API and then use the methods in them.
> Where I get confused, however, is in using a method such as
>
> getIntegerWithMin$withMax(-1, 1)
>
> I know that I can use the method in one of my own by
> importing Swarm.Globals and then referring to the method as
>
> i = Globals.env.uniformIntRand.getIntegerWithMin$withMax(-1,
> 1);
>
> Following the API from Globals through env through
> uniformIntRand I even see how this works, but I'm not sure
> that by looking first at getIntegerWithMin$withMax I could
> have followed the path in the other direction.  Indeed, it
> would seem more logical to use this method by including
> (oops, importing) swarm.random.UniformIntegerDistImpl and
> then getting at the method through this implementation
> class.  However, I don't seem to understand how to actually
> refer to the method this way.  Do I actually have to create
> an instance of the UniformIntegerDistImpl class as in
>
> UniformIntegerDistImpl r = new UniformIntegerDistImpl;
>
> and then say
>
> i = r.getIntegerWithMin$withMax(-1, 1);  ?
>
> Or can I just refer to the class method without creating an
> instance of the class?  Or am I entirely missing something
> obvious?
>
> Thanks,
> Charles
>
> -----Original Message-----
> From: address@hidden
> [mailto:address@hidden Behalf Of Marcus
> G. Daniels
> Sent: Monday, February 07, 2000 5:17 PM
> To: address@hidden
> Subject: Re: Java examples
>
> >>>>> "CS" == Charles Staelin <address@hidden> writes:
>
> CS> The problem is not the OOP stuff,
> CS> but rather what needs to be in the include statements
> and how
> CS> particular methods in the various classes are properly
> referred to.
>
> You need to import each class or interface that you want to
> use, or
> use a wildcard expression that does the same.
>
> At
> http://www.santafe.edu/projects/swarm/swarmdocs/refbook-java
> /index.html,
> under "All Classes" are all the interfaces and classes.
> When you
> click on one of these, the documentation for that feature is
> shown on
> the right.  Note that the Java package is listed in small
> letters
> above the interface/class name.  It is the combination of
> the package
> and class/interface name that you use as the argument to
> import.
>
> Interfaces are the preferred data type for variables and
> argument
> types.  Interfaces either have no suffix, or a "C" or "S"
> suffix.  The
> common `using phase' methods are named by interfaces without
> a suffix.
> The methods you use when you are describing an object to
> instantiate
> it are in the interface with the "C" suffix (the `creating
> phase').
> The "S", `setting phase' methods are usable in either using
> or
> creating phase.
>
> The actual implementation classes have the suffix "Impl".
> Whenever
> you want to instantiate an object, you'll use one of these
> as an
> argument to "new", and most of the time it will be with a
> class in
> the using phase, not the creating phase.  (The reason for
> this is
> that most using-phase implementation classes have `common
> usages'
> of just a few arguments, that take care to run the creating
> phase,
> apply the arguments, and then finish it in one step.)
>
> Typical code for creating an object and assigning to a
> variable is:
>
>   Something obj = new SomethingImpl (aZone);
>
>                   ==================================
>    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.

--
Benedikt Stefansson      | address@hidden
CASA, Inc.               | Ph : (505) 988-8807 x101
Santa Fe, NM 87501       | Fax: (505) 988-3440




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