thinman@netcom.com (Lance Norskog) (04/22/91)
- 1 -
5D Reference Manual
Revision 0.1
Release date: 4/21/1991
Copyright (c) 1991 by Lance Norskog, Santa Clara, USA
1. _I_n_t_r_o_d_u_c_t_i_o_n
5D is a portable implementation of "virtual reality". It
implements a simple, extensible programming language for
real-time 3D graphics interaction, and forms the basis of a
cyberspace/hypermedia-oriented window system.
1.1 _S_c_o_p_e__o_f__5_D
5D only addresses the _h_a_r_d_w_a_r_e _c_o_n_t_r_o_l level of 5D. It
provides a pleasant programming language for creating custom
user interfaces, and network protocols for user interaction.
This system is intended first as a platform for
experimentation in 5D user interface and network interaction
betwixt decks in larger persistent worlds.
1.2 _P_o_s_s_i_b_l_e__a_p_p_l_i_c_a_t_i_o_n_s
5D is a Cyberspace building block. It communicates data in
the form of 5D programs. The 5D language encoding is dense
enough to download simple worlds in several minutes over
commodity 9600 baud modems, or ISDN. With the future
inclusion of a 2D text rendering model, 5D could support
hypertext applications at this bandwidth. X.25's ability to
support several simultaneous connections to separate phone
numbers opens impressive groupware and cyberspace doors.
- 2 -
The reference application for low-end decks is MazeWar.
Several players on an Ethernet, one to a deck, wander
through a maze shooting at each other. The decks
continuously broadcast the position, eye direction, laser
direction, and trigger status of their users.
Scientific Visualization uses multi-dimensional viewing
methods. Ray-tracing systems often include "fog"
implemented as 3D stochastic white-out blurring. A 5D
system could support sci-vis by implementing fog from a 3D
dataset, thus allowing a surgeon to _e_x_p_e_r_i_e_n_c_e a brain scan
instead of viewing it. This will, of course, not run in
real-time on a PC.
The Habitat system [ref ??] uses standard computer game
technology and telecommunications to implement Cyberspace
with a real-time quasi-3D interface. Every evening 300-400
people sit at home with a Commodore 64 and a 300 baud modem
playing an elaborate and permanent computer game with up to
5 other subscribers in a room or "cell". Habitat has 20,000
cells total, and 15,000 paying subscribers. It should be
possible to implement a 5D version of the Habitat system at
baud rates of 9600 on up.
1.3 _5_D__G_l_o_s_s_a_r_y
world A "world" is a visible 3D scene with
which the user interacts.
deck A "deck" is the combination of visual,
sound, and force-feedback hardware that
implements a 5D environment for one or a
few users.
program On a network, a "program" is the remote
application which is responsible for a
world.
World Manager A World Manager is a remote program
responsible for the main operation of
the deck. A typical deck is set up to
have more than one world available; the
WM allows switching between the
different worlds.
TerraFormer The TTTTeeeerrrrrrrraaaaFFFFoooorrrrmmmmeeeerrrr is a visual programming
CASE system for 5D trees. It is a 5D
program which presents a tree as a 3D
scene, using translucent structure
blocks to display several levels of
structure simultaneously.
- 3 -
2. _5_D__S_y_s_t_e_m__A_r_c_h_i_t_e_c_t_u_r_e
5D runs on personal computers and professional workstations.
It presents an interactive real-time 3D environment for the
user to work with. It may read in and present a "canned"
world description from a file, or download one over a
network connection. The world description consists of
picture elements (polygons, spheres, etc.) which are drawn
in 3D, and many other software constructs necessary to
implement a complete free-running program inside the deck.
Constructs include various 3D graphics mathematics
operations, sound generation control, force feedback
control, and network communications.
5D is a real-time simulation system for 3D graphics scenes.
A collection of objects exists, and exhibit various
behaviors in response to external input.
2.1 _L_a_n_g_u_a_g_e__D_e_s_i_g_n__P_h_i_l_o_s_o_p_h_y
"_W_e _t_o_o_k _a _f_e_w _s_i_m_p_l_e _i_d_e_a_s _a_n_d _b_e_a_t _t_h_e_m _t_o _d_e_a_t_h."
- _D_e_n_n_i_s _R_i_t_c_h_i_e _n_e_v_e_r _s_a_i_d _t_h_i_s _a_b_o_u_t _d_e_s_i_g_n_i_n_g _U_N_I_X.
A real-time software system must veer in one of two opposing
directions:
+o it can allow the programmer complete control over the
computer, and provide a range of services to a program,
_o_r
+o it can take over the low-level control of the computer
and provide a set of high-level constructs which the
programmer can arrange into a program. The system then
implements real-time response by "doing the best it
can" based on the given constructs.
5D chooses the latter method. It is a simulation
description language. It includes a rich set of very
abstract operators for describing 3D graphics scenes. The
point is to get as close as possible to letting the
programmer say "_d_o _w_h_a_t _I _m_e_a_n". A general principle is
that the more abstract the language, the more efficient the
compiled code IFF the language constructs are carefully
designed for compilability. The more the compiler
understands what you're "really" doing, the better code it
can generate.
- 4 -
2.2 _C_o_n_t_r_o_l
"_W_h_e_n _I _h_e_a_r _t_h_e _w_o_r_d _M_a_c _I _r_e_a_c_h _f_o_r _m_y _g_u_n."
Since 5D is never saved in binary format, the user may alter
any aspect of a world at any time. User interfaces are
generally designed by programmers, who are generally
terrible at it. 5D users are not forced to operate canned
software, but may change it at any time. The user is in
control, not the programmer.
The 5D software community is encouraged to develop libraries
of new software which can be disseminated as simple tools,
not complete enclosed worlds. A kinematics toolkit, for
example, is badly needed for many applications.
2.3 _C_l_e_a_n_l_i_n_e_s_s
The language is defined by a small set of basic operators
and data types, which are then combined to create useful
programming constructs. Parsimony is a virtue in language
design. _I_f _s_o_m_e_t_h_i_n_g _c_a_n _b_e _i_m_p_l_e_m_e_n_t_e_d _a_s _a _c_o_m_b_i_n_a_t_i_o_n _o_f
_e_x_i_s_t_i_n_g _c_o_n_s_t_r_u_c_t_s, _i_t _w_i_l_l _n_o_t _b_e _d_e_f_i_n_e_d _a_s _a _s_e_p_a_r_a_t_e
_b_u_i_l_t-_i_n _c_o_n_s_t_r_u_c_t.
The primary motivation for this is that a system feature,
once made available to the user community, is immortal.
Mature systems generally have a thick layer of "barnacles",
old features which don't slough off like dead skin. These
systems are much larger and more complex than they need to
be because they must provide backwards compatibility for
these "mistakes of youth".
The 5D design process is a continuing search for simpler and
more basic constructs. The best analogy is to the physical
world: quarks are combined into protons, neutrons, and
electrons, which are combined into many different molecules,
which are ultimately combined into visible objects such as
chairs.
The X Window System, on the other hand, includes 1000
different predefined molecules which don't fit together very
well. 5D was designed with the X Window System as a shining
example of poor design.
- 5 -
3. _L_a_n_g_u_a_g_e__C_o_n_c_e_p_t_s
5D was motivated by the need for a very high-level
programming language for implementing Virtual Reality
software. It is interpretable, compilable, malleable to
parallel and custom graphics hardware configurations, and
friendly (well, maybe) to non-programmers.
3.1 _D_e_s_i_g_n__c_o_n_s_t_r_a_i_n_t_s
5D has four major design constraints:
1. It is a programming language for designing worlds.
2. It is a protocol for interacting with an application.
3. It operates in real-time; i.e. the language constructs
operate in a _p_r_e_d_i_c_t_a_b_l_e amount of time.
4. It is portable to the wide variety of the hardware
platforms used in computer graphics.
The search for clean, elegant solutions for the problems
caused by these constraints is the source of most of the
peculiar features of the language.
3.2 _H_i_e_r_a_r_c_h_i_c_a_l__D_i_s_p_l_a_y__L_i_s_t_s
5D was inspired by the _h_i_e_r_a_r_c_h_i_c_a_l _d_i_s_p_l_a_y _l_i_s_t. In
standard 3D modeling systems, a 3D scene description is
traversed and rendered each time the scene or the viewpoint
changes. Abstract physical models are described as to their
shape, color, shininess, etc. Separate copies or _i_n_s_t_a_n_c_e_s
of these objects are then placed in 3-space.
3.3 _I_n_h_e_r_i_t_a_n_c_e
The objects _i_n_h_e_r_i_t their physical properties from their
base descriptions, but an individual instance may change any
of those properties. Arranging these object definitions and
instantiations into trees gives the benefits of data-hiding
and modular software construction. An object definition may
include by reference other object descriptions, and may also
change properties inherited from those object descriptions.
Object instantiations grouped into a tree may inherit
properties from the _p_a_r_e_n_t_s of the tree. This is a very
powerful technique for describing the graphics portion of a
3D application; other techniques for data structuring can be
layered atop it as interconnections between tree members.
In PHIGS and other 3D modeling systems, these objects define
a static scene, and consist solely of graphics primitives.
- 6 -
Virtual Reality also needs to describe dynamic changes in a
world. Games need to describe the physics of object
collision, while molecular models must implement gradual
force field interactions. Many other standard programming
facilities are needed also, such as communication protocols
and I/O device drivers.
3.4 _D_a_t_a_f_l_o_w__P_r_o_g_r_a_m_m_i_n_g
5D extends the display list to a full programming language
by using the paradigm of Dataflow Programming [ref ??].
Dataflow languages express a complete program as a lattice
of operations. At the beginning of a computation, values
enter the lattice of operations. These values may be static
constants, the current value of input devices, or the
results of a previous computation. At the end of
computation, one or more values pop out of the "top" of the
lattice; these are the results of the computation.
A 5D "world" is a lattice. This lattice is not evaluated in
one computation. Instead, individual sub-lattices direct
the system when to evaluate them. Sub-lattices draw on the
screen, emit sound, send network messages, and operate
force-feedback devices as side effects of their execution.
3.4.1 _D_a_t_a_f_l_o_w__L_a_t_t_i_c_e__O_r_g_a_n_i_z_a_t_i_o_n
Each node of the lattice has an operator, one or more
super-nodes, zero or more subnodes, and zero or more
properties. For purposes of a simple language organization,
lattices are organized into expression trees wherever
possible. The object definition system (see below) makes
this feasible.
3.5 _F_e_e_d_b_a_c_k
5D objects can be connected in cyclic graphs. This does not
imply that the language can get into an endless loop! The
tree members are evaluated according to their frequency
properties. The value of a tree in a cyclic graph is
eventually fed back into the next evaluation of that tree.
Feedback is a natural method for implementing rhythmic
objects and dynamics simulations; these are generally
defined with differential equations in a feedback loop.
3.6 _O_b_j_e_c_t__O_r_i_e_n_t_a_t_i_o_n
5D is an object-oriented language. The fundamental paradigm
is object-oriented dataflow programming: a lattice, or
directed acyclic graph, of arithmetic expressions feeds a
set of software operations with numerical information.
These operations may draw geometric objects, make sounds,
- 7 -
send messages over communications channels, or control
force-feedback devices.
Since these I/O devices must be controlled in real-time, 5D
does not contain constructs which require an unpredictable
amount of time to execute. Whether this or that construct
is "efficient" is irrelevant to real-time work;
predictability is the issue. Thus, very high-level language
concepts like actors, object messaging, dynamic
instantiation, etc. are not used. The contents of the
lattice is limited to operations of known execution time.
Otherwise, the frame rate of the system would randomly vary
from several frames per second to several seconds per frame.
Objects are used as the organizing principle for defining
the possible componenents of the lattice, and their possible
interconnection. There is a large built-in library of
_p_r_i_m_i_t_i_v_e _c_l_a_s_s_e_s. Programs may also define their own
classes. References to user-defined classes are _r_e_w_r_i_t_t_e_n
according to their class definitions until the lattice is
entirely in terms of the primitive classes. The resulting
lattice is incrementally compiled and executed repetitively.
4. _L_a_n_g_u_a_g_e__R_e_f_e_r_e_n_c_e
5D uses an extremely simple language. It is built on
several elements: objects, classes, properties, templates,
trees, and IDs. These language elements are used to
describe rich, complex user interaction environments in a
very dense format.
4.1 _O_b_j_e_c_t_s__a_n_d__C_l_a_s_s_e_s
An _o_b_j_e_c_t is an element of an interactive environment. A
_c_l_a_s_s is a generic description of a type of object. Classes
may be modified and combined to create new classes. The
original classes are called _p_a_r_e_n_t- or _s_u_p_e_r_c_l_a_s_s_e_s. A deck
starts off with many pre-defined _p_r_i_m_i_t_i_v_e _c_l_a_s_s_e_s. A 5D
program may include new class definitions which derive from
the primitive ones. A class may contain two or more objects
from different parent classes. This means that a class is
always an extended or modified version of its parents. It
may add and delete operators and properties, possibly
overriding definitions inherited from the parent classes.
Objects are instances of their class definition. Objects
may be leaf nodes, or may be _c_o_n_s_t_r_u_c_t_e_d from objects of
other classes.
- 8 -
4.1.1 _T_y_p_e_s
Some classes are types, some are not. _A_b_s_t_r_a_c_t _s_u_p_e_r_c_l_a_s_s_e_s
are defined only so that child classes may be derived from
them. They are not useful for instancing objects, and thus
do not allow this to occur. Types are classes which may be
used for instancing objects.
4.2 _T_e_m_p_l_a_t_e_s
A _t_e_m_p_l_a_t_e describes a space of possible 5D program trees.
Templates are used several ways in 5D. Most important,
templates are used to describe the space of possible uses of
an operator in a class definition. This allows an operator
definition to handle several different invocations.
Templates are also used to verify a tree downloaded from a
network connection; they supply a "syntax check" for
accepted trees which can be used to decide whether to
execute a downloaded tree.
4.2.1 _T_e_m_p_l_a_t_e__s_y_n_t_a_x__[__p_r_o_p_o_s_e_d__]
Template trees are separate type of tree node. There are
several forms of template node, defined by the _k_i_n_d=
keyword. Here are the values of the _k_i_n_d= keyword and the
associated sub-tree formats:
multi (X) maps to 0 or more occurrences of the
tree node (X).
order (X) (Y) maps to the tree pair (X) (Y) or the
tree pair (Y) (X).
sub (X) maps to an arbitrary-shaped tree of
nodes described by (X).
and (X) (Y) maps to the boolean AND of the trees
described by (X) and (Y).
or (X) (Y) maps to the boolean OR of the trees
described by (X) and (Y).
not (X) maps to the boolean NOT of the tree
described by (X).
Notes:
The _o_r_d_e_r, _a_n_d, and _o_r nodes may contain two or more
children.
Templates are, by nature, underspecified. A template
without the _k_i_n_d keyword may use _t_y_p_e. A _t_y_p_e template may
optionally use _v_a_l_u_e. This template describes 0 or more
Numbers:
- 9 -
(template kind=multi
(template type=Number))
Tree templates may be used in combination. The template:
(template kind=sub
(template kind=or
(template type=Void)
(template type=Number)))
corresponds to one or more trees of algebraic expressions.
Since the Number class does not operate on Voids, thus legal
5D trees matching this template can be a one or more Number
expressions hanging under a tree of Voids, or one Number
expression with no Voids at all.
Templates may be assigned IDs.
A nodes of type Address may substitute at any place for any
other node, if its referent node matches a template. Nodes
of type Address may also be specified in a template.
[ Templates have proven the thorniest design task in 5D.
I'm still not happy with the design. ]
4.3 _P_r_o_p_e_r_t_i_e_s
If objects are nouns, properties are adjectives. Properties
influence the nature of objects. Drawable objects, as
mentioned above, have colors and reflectivity. Other
objects have other properties: sound channels, for example,
have the property of volume. The value of a property may be
specified by a separate 5D program tree. The one restriction
here is that no object used in the program tree may itself
have properties.
However, a property itself has a few attributes:
Inheritance The properties of a node may be
inherited automatically down the tree.
Every node of type X may use or set the
properties defined for class X. An
inheritable property which is set at a
node overrides the inherited value of
those properties. The new setting is
visible to all of its children of the
same type.
Default Every property description includes a
default value for a property. If a
value is not specified or inherited for
that property, the default is used.
- 10 -
Writeability A property may or may not be changed by
a node. A read-only property may be set
at the top of a tree and then not reset
by its children.
4.4 _T_r_e_e_s_,__L_a_t_t_i_c_e_s_,__a_n_d__C_y_c_l_i_c__G_r_a_p_h_s
First, some basic Graph Theory: a _g_r_a_p_h is a collection of
nodes connected by edges. A graph where the edges have a
direction assigned to them is a _d_i_r_e_c_t_e_d _g_r_a_p_h. A _t_r_e_e is a
graph in which there are no loops at all. A _l_a_t_t_i_c_e is a
directed graph in which there are no loops at all. Unlike a
tree, a lattice may have two or more edges "pointing" at the
same node. A _d_i_r_e_c_t_e_d _c_y_c_l_i_c _g_r_a_p_h may have loops where the
edges form a circle.
In 5D a program is described by a directed graph which has
aspects of a tree, a lattice, and a directed cyclic graph.
A program is specified as a tree. Each branch or leaf of
the tree is called a _n_o_d_e. Special _p_o_i_n_t_e_r _n_o_d_e_s may refer
to other nodes, which may in fact be _p_a_r_e_n_t _n_o_d_e_s. Thus,
with pointer nodes the tree can become a lattice or even a
cyclic graph. [ Think of the UNIX file system with symbolic
links. ]
4.4.1 _P_r_o_p_e_r_t_y__I_n_h_e_r_i_t_a_n_c_e__v_i_a__p_o_i_n_t_e_r_s
Properties are inherited statically, not dynamically. When
trees are executed via pointers, they still inherit their
properties from their tree parent, not via pointing node.
4.5 _I_D_s
Any node in a 5D program tree may have a name attached to
it. This name must be unique within a subset of the tree.
Names are assigned via the ID keyword.
IDs is useful in several contexts. Class definitions name
themselves this way. Variables named with IDs are used to
transform the program tree into a lattice. Certain IDs have
special pre-defined meanings.
4.6 _T_r_e_e__c_o_n_s_t_r_u_c_t_i_o_n_
Each node of the tree is one of a few node types. One or
more keywords modify the node type.
4.6.1 _N_o_d_e__t_y_p_e_s
5D has several types of tree nodes:
Class indicates that the entire tree is a
class definition. A class node must
- 11 -
have the keywords IIIIDDDD and ssssuuuuppppeeeerrrr.
Property specifies a property of this node. In a
class definition, a property node
defines a property which instances of
this class have. In an object
instantiation, an property node sets a
property of this node. A property node
must have the keywords IIIIDDDD and _t_y_p_e, and
must have a subtree containing the
default value of the property.
Input in a class definition specifies a
collection of superclass objects which
form this class.
Data in a class definition specifies a
collection of superclass objects which
are secret to an instantiation of this
class.
Op specifies an operation node. In a class
definition, an operation node and
subtree indicate a method the class
implements. In an object instantiation,
an operation node invokes the
corresponding method in the class
definition. An op node may have the
keywords IIIIDDDD and nnnnaaaammmmeeee.
Template specifies a variable-format tree. A
template tree defines a space of
possible tree shapes. It must have the
ffffoooorrrrmmmmaaaatttt keyword.
Rewrite specifies the replacement tree in a
method.
Comment is used for multi-line commentary.
Set is the dataflow lattice connection
operation. Set assigns the value of the
right-hand tree to the left-hand
nodename.
4.6.2 _M_o_d_i_f_i_e_r_s
5D has several basic modifiers:
ID assigns a unique name to this node. Any
node may have a name attached to it.
This name must be unique, subject to
- 12 -
certain restrictions noted below in the
section "Scoping Rules".
Super indicates a superclass. This is used
several ways in class definitions. In
the class definition node, it names the
parent classes. In the operator and
property definition nodes, it may be
used to refer to properties defined by
parent classes.
Type indicates the class of a property or
operation by naming the class definition
node.
Name indicates the name of the operation in
an operation node
Value indicates the actual value contained by
a leaf node. A value is a number in
standard C decimal, octal, or hex
format.
Format defines the type of a template node in a
template subtree.
Refer means that this node is an indirect
node. The value of the Refer keyword is
an ID. This node receives its type and
value from the ID'd node. This node may
also possess a Type keyword, which must
match the type of the ID'd node. [ TTTThhhhiiiissss
iiiissss uuuuggggllllyyyy.... IIIItttt sssshhhhoooouuuulllldddd nnnnooootttt eeeexxxxiiiisssstttt.... CCCCllllaaaassssssss
AAAAddddddddrrrreeeessssssss hhhhaaaannnnddddlllleeeessss tttthhhhiiiissss.... EEEEiiiitttthhhheeeerrrr tttthhhhaaaatttt,,,, oooorrrr
ccccllllaaaassssssss AAAAddddddddrrrreeeessssssss sssshhhhoooouuuulllldddd nnnnooootttt eeeexxxxiiiisssstttt aaaannnndddd aaaallllllll
ppppooooiiiinnnntttteeeerrrrssss sssshhhhoooouuuulllldddd bbbbeeee ddddoooonnnneeee wwwwiiiitttthhhh RRRReeeeffffeeeerrrr.... ]
IsType is a boolean expression for whether or
not a class definition is a _t_y_p_e. A
class definition which is not a type may
only be used as an abstract superclass,
it may not be used in a program.
Inherited is a boolean expression for whether or
not a property is inherited. If it is
not, it must be explicitly specified in
each use of the object.
Remove deletes an inherited operator or
property from a class definition.
- 13 -
writeable is a Boolean value in property
definitions. If false, the property may
not be changed by its heirs or by the
"set properties" operator in the Void
object.
Along with keywords, there may be arbitrary text surrounded
by double quotes ("). These are comments and are ignored by
the 5D interpreter.
4.6.2.1 _C_o_m_m_e_n_t__c_o_n_v_e_n_t_i_o_n_s
The 5D development system has several conventions for
comments. A comment beginning with the string "Summary:" is
considered to be a short (one-line) summary of this tree
node, and should be used in class, operator, and property
definition nodes. A comment beginning with the string
"Treetype:" is a directive to the TTTTeeeerrrrrrrraaaaFFFFoooorrrrmmmmeeeerrrr that a tree is
a specific type of database, such as a 3D model or a
differential equation, and should be displayed or edited
with a special application.
4.7 _T_r_e_e__e_n_c_o_d_i_n_g
There are two possible tree encodings, ascii & ASN.1 binary
format.
4.7.1 _A_s_c_i_i__F_o_r_m_a_t
The 5D ASCII syntax is rudimentary, to say the least. It is
designed to be very quick to parse, both by a deck and by
the TerraFormer. It is in standard US 7-bit ASCII, with 8-
bit and 16-bit text allowed in comments. You may send it in
e-mail, and control it with SCCS or RCS. You're just not
expected to read it, and you are strongly urged not to write
it.
A tree node is started by left parentheses (LP) and stopped
by right parentheses (RP). After the LP comes one of the
above node type strings. After the node type are zero or
more keywords. Some of the keywords may be of the form
aaaaa=bbbbb. These keywords are accepted by the node type
keyword according to its wont. After these keywords comes,
you guessed it, another LP or an RP. A series of RP's may
be expressed by a right bracket (RB). An RB substitutes for
RP only if there can be nothing but the RP at that location.
The exact syntax of the contents of data nodes is not final.
Numbers are stored in the standard C "printf" floating point
formats. Images are stored in PBM format. Sound samples
are stored as a series of text numbers, unsigned. Ascii
text strings are not supported as data. See section "Text".
- 14 -
4.7.2 _A_S_N_._1
A 5D program is encoded as one large tree. The node
contains the type and whatever keywords are there as a data
structure of strings.
Existing source code from an SNMP agent which encodes and
decodes a pre-defined ASN.1 grammar looks quite time-
efficient. Binary data is stored in the ASN.1 format in
very compact formats.
It may be necessary to process a received tree "on the fly"
without storing the entire tree in source form. The ASN.1
format might work better in postfix format rather than the
ASCII format's prefix format, Simple tree nodes are
processed first, then knitted together. The "incoming
stack" maintains the database of processed trees which await
the processing of their controlling nodes.
4.7.3 _T_r_e_e__E_n_c_o_d_i_n_g__S_u_m_m_a_r_y
The ASCII format is readable, and may be mailed and used
under software control systems. But, it is not very dense,
and in particular uses very inefficient methods for storing
binary data. The ASCII format is used as a fluid medium for
experiments in rearranging the 5D syntax.
The ASCII format will be the dominant use in development,
authoring, and workstation environments, but the broader
network-based users will use ASN.1 almost exclusively
because its an international standard and because of its
space-efficiency.
4.8 _C_l_a_s_s__d_e_f_i_n_i_t_i_o_n
A class definition has up to five sections:
Superclass The superclasses used to derive this
class.
Property The properties used by the class.
Data Secret data objects used by a member of
this class.
Input Some classes are ordered lists of parent
objects.
Method The rewrite rules for the class.
The Property, Data, and Input sections are optional.
- 15 -
4.8.1 _S_u_p_e_r_c_l_a_s_s__S_e_c_t_i_o_n
The superclass section defines all the parent classes of a
class. The 5D class heirarchy is a lattice: at the top is
the class Object which effectively does nothing. It is the
only class with no superclass. All other classes have one
or more superclasses. The properties and operators defined
in the parent classes are automatically inherited by the
class.
4.8.2 _P_r_o_p_e_r_t_y__S_e_c_t_i_o_n
The property section defines any properties which may affect
the operation of this class. For example, class Drawable
contains 3D visible objects and thus has the properties of
color, reflectivity, etc. But, class Number has no
properties: "5 + 4" is always 9.
4.8.3 _D_a_t_a__S_e_c_t_i_o_n
The Data section defines secret data objects. These are
unique to each instantiation of a class, and may only be
manipulated within the class definition.
4.8.4 _I_n_p_u_t__S_e_c_t_i_o_n
Classes which contain Input sections are "aggregations" or
collections of objects. For example, a Point is 3 Numbers.
The Input section is optional. Classes without Input
sections may redefine the behavior of a parent class, or
create a new class with behaviors of several parent classes.
Operations on the members of the Input section are inherited
_i_n _t_o_t_o: see the definition of addition and subtraction on
Complex numbers below.
4.8.5 _M_e_t_h_o_d__s_e_c_t_i_o_n_s
The Method sections give the substition rules for a class.
A "method" handles a given operation on an object. For
example, class Number has a method `+' which handles adding
two or more numbers. Tree templates are used to describe
possible invocations of an operator in the context of this
type. A second tree of object operations is substituted for
the matched tree. This second tree is called the _r_e_w_r_i_t_e
rule, because operator invocations are _r_e_w_r_i_t_t_e_n.
The template facility is a powerful context-sensitive device
for describing the use of an object. It describes the
replacement expression tree for each operation that can be
performed on the object. For example, the operation
Vertex_Normal on a Point is substituted with the appropriate
mathematics on the constituent Numbers.
When an object instance is evaluated, one of the methods in
the object's tuple list is evaluated and its outputs are the
outputs of the instance. Which method? _T_h_e _o_n_e _w_h_o_s_e
- 16 -
_t_e_m_p_l_a_t_e _m_a_t_c_h_e_s _t_h_e _s_h_a_p_e _o_f _t_h_e _t_r_e_e _s_u_r_r_o_u_n_d_i_n_g _t_h_e
_e_v_a_l_u_a_t_i_o_n _o_f _t_h_e _i_n_s_t_a_n_c_e. There may not be two templates
which both match the same tree. [I think it is possible to
discover this with static analysis of the entire class
definition lattice.] [On second thought, this may be
"halting problem" material, or at least NP-nasty.]
4.8.6 _C_l_a_s_s__I_n_h_e_r_i_t_a_n_c_e
Classes automatically inherit properties and methods from
all superclasses. Properties which have the same name are
disambiguated by class name. Operators with the same name
must be redefined. The parent operators may be invoked
within the rewrite rule via the _s_u_p_e_r=ppppaaaarrrreeeennnntttt keyword.
4.8.6.1 _C_l_a_s_s_:__C_o_m_p_l_e_x__N_u_m_b_e_r
For example, an abridged object definition for complex
numbers:
( class
ID=Complex
superclass=Number
( input
(type=Number ID=re)
(type=Number ID=im)
)
/ create a Complex number from two Numbers
( op name=Complex type=Complex
( template
(type=Number ID=input1)
(type=Number ID=input2)
)
( rewrite
(set (output.re, input1))
(set (output.im, input2))
)
)
/ decompose a Complex number into its constituent Numbers
( op name=Real type=Number
( template
ID=output
(type=Complex ID=input)
)
( rewrite
(set (output, input1.re))
)
)