| www.delorie.com/gnu/docs/kawa/kawa-tour_3.html | search |
![]() Buy GNU books! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Java J. Gosling, B. Joy, G.~Steele:
The Java Language Specification, Addison-Wesley, 1996
has primitive types (such as 32-bit int) as well
reference types. If a variable has a reference type, it means that it can
contains references (essentially pointers) to objects of a class,
or it can contain references to objects of classes that "extend"
(inherit from) the named class.
The inheritance graph is "rooted" (like Smalltalk and unlike C++);
this means that all classes inherit from a distinguished class
java.lang.Object (or just Object for short).
Standard Scheme W. Clinger and J. Rees (editors):
Revised 4 report on the algorithmic language Scheme.
LISP Pointers, 4(3):1--55, 1991. has a fixed set of
types, with no way of creating
new types. It has run-time typing, which means that types are not declared,
and a variable can contain values of different types at different times.
The most natural type of a Java variable that can contain any
Scheme value is therefore Object, and all
Scheme values must be implemented using some class that
inherits from Object.
The task then is to map each Scheme type into a Java class.
Whether to use a standard Java class, or to write our own
is a tradeoff. Using standard Java classes simplifies
the passing of values between Scheme functions and existing Java methods.
On the other hand, even when Java has suitable built-in classes,
they usually lack functionality needed for Scheme, or are not organized
in any kind of class hierarchy as in Smalltalk or Dylan.
Since Java lacks standard classes corresponding to pairs,
symbols, or procedures, we have to write some new
classes, so we might as well write new classes whenever the
existing classes lack functionality. One extreme would
be to define a new SchemeObject class, and derive from
it classes for all Scheme values. While this might make
implementing Scheme easier, Kawa does not go that far,
partly because we want to allow Scheme variables to contain
arbitrary Java objects.
The Scheme boolean type is one where we use a standard Java type,
in this case Boolean (strictly speaking java.lang.Boolean).
The Scheme constants `#f' and `#t' are mapped into
static fields (i.e. constants) Scheme.falseObject and
Scheme.trueObject. These are initialized to new Boolean(false)
and new Boolean(true), respectively, when Kawa starts up.
On the other hand, numbers and collections are reasonably organized into class hierarchies, which Java does not do well. So Kawa has its own classes for those, discussed in the following sections.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |