MathBus |
|
[ Term
Structure | Algebra
| Geometry | Logic | Drawing ]
[ Language Bindings
| C++ | Java | Lisp | ML ]
All symbols used by the Lisp implementation of the MathBus tools are contained in the mathbus package. The symbols that appear in this section are all exported.
The registry of the Lisp MathBus implementation cannot be directly initialized from the standard registry file format. Instead, a Lisp file must be generated from the standard registry file format, and the Lisp file is then loaded with the rest of the MathBus tools to initialize the MathBus system.
generate-label-declaration &optional outfile
infile
Converts a file in the standard registry file format into a Lisp
file that can be loaded quickly. Whenever a new registry file is
generated, this function should be called to create the
appropriate Lisp file for use when the MathBus system is loaded.
The registry is initialized using the following function to read the Lisp file created by the above function.
read-registry &optional file
file is the name of a file containing registry
information. Loads the contents of file into the registry
of the current Lisp process. This is a relatively slow process,
but can be used to load foreign registry information into a Lisp
process.
The following three functions are used to read and write the registry. The first two are used to read entries in the registry, while the second writes new values into the local registry. The global registry can currently be written only by modifying the standard registry file.
registry-lookup-value identifier RegistryType
Returns the value stored in the registry for this
identifier.
registry-lookup-identifier RegistryType Value
For those RegistryTypes that are declared to be bi-directional,
returns the unique identifier string that has this value.
registry-store-local identifier RegistryType Value
Assigns Value to the RegistryType property of identifier
in the local copy of the registry. This operation does not update
any global information.
declare-local-stringId label &optional
subtypes
This function allocates a local label if it doesn't already
exist. The first argument to the functional can be either string
or a symbol, in which case the symbol's string is used. If the
second argument is provided then second entry will be added to
the local registry that indicates the subtypes of nodes with this
label.
numeric-label sym
Given a Lisp symbol or string corresponding to a label, this
function returns corresponding numeric label. Here, as elsewhere
in the Lisp implementation the case of the identifier is ignored.
This should probably be corrected.
symbolic-label num
Given a Lisp number this function returns string of the
corresponding symbolic label.
The Lisp implementation of the MathBus term bindings represents MathBus terms as arrays of two or elements. The first element of the array is the numeric label of the node. The number of sub-terms is not explicitly stored, since it can be determined from the length of the array, which is maintained by Lisp. The sub-terms of the node are in succeeding elements of the array, thus sub-term indexed by i is stored in array element i.
Attributes are handled in the following fashion. A reference to a node may be either to the node itself, or to an attribute node that contains the node. Routines for accessing properties or sub-terms of a node act on the node contained within the attribute node, not the attribute node itself. Internal routines are provided for accessing the properties and sub-terms of an attribute node, but they are not normally used.
The following functions are available for creating and manipulating MathBus terms.
make-mbnode label length
Creates a MathBus node labeled with label. Label can be a symbol or a string representing the symbolic form of the label or it can be number that is the numeric label that is actually stored in the node. The sub-term slots of the node are left uninitialized.
mbnode label subnode1
subnode2 …subnoden
This is the more common way of constructing a node. A node is created with n sub-terms, labeled with label. The sub-nodes are then inserted into the newly created node after ensuring that they are of the right type.
The following three functions are used to extract components from a MathBus node. If node is an Attributes node, then this function returns the index sub-term of the node sub-term of the Attributes node. For example, if node is the node:
(Attributes (Plus (AlgVariable 'x') [1]) 'Color' "Blue" 'Font' "TimesRoman")
then mbnode-label will return 'Plus', mbnode-nSubterms will return 3, etc. The internal functions mbnode-labelq will return 'Attributes', mbnode-nSubtermsq will return 5, etc.
mbnode-label node
Returns the numeric label of node.
mbnode-nSubterms node
Returns the number of sub-terms in node. The value
returned does not depend on whether the sub-terms have been
initialized or not.
mbnode-subterm node index
Returns sub-term number index of node. The first sub-term
is number 1.
mbnode-subterm-float node index
Interprets the sub-terms index and index + 1 of node
to be a pair of floating point numbers. It returns a Lisp
floating point number.
The attributes of a node can be manipulated using the following three routines. In each of these routines, the attribute identifier can be either a string or the string identifier corresponding to the string.
get-attribute node attribId
Returns the attribute of node associated with attribId.
set-attribute node attribId value
Causes the attribId attribute of the node to have value
associated with it. Returns a modified version of node or
wraps node in an Attributes node if needed.
delete-attribute node attribId
Deletes the attribId attribute of the node if it is
present. If node has no attributes then it is returned
unchanged. Otherwise a modified version of node is
returned.
The following four functions are quick, internal versions of the term accessors given above. They do not check to see if the node is an Attributes node. These functions should be used very carefully.
mbnode-labelq node
Returns the numeric label of node.
mbnode-nSubtermsq node
Returns the number of sub-terms in node. The value
returned does not depend on whether the sub-terms have been
initialized or not.
mbnode-subtermq node index
Returns sub-term number index of node. The first sub-term
is number 1.
mbnode-subterm-floatq node index
Interprets the sub-terms index and index + 1 of node
to be a pair of floating point numbers. It returns a Lisp
floating point number.
The following three pairs of functions are used to convert between Lisp stings, integers and floating point numbers and MathBus nodes.
mb-string symb
string-value node
mb-string takes a Lisp string or symbol and returns a
MathBus term. String-value accepts a MathBus term that
has the String label and returns a Lisp string. If the
node is not labeled with String, then an error is signaled.
mb-integer int
integer-value node
mb-integer takes a Lisp integer and returns a MathBus
term labeled with LongInteger. Integer-value
accepts a MathBus term that is labeled with LongInteger
and returns a Lisp number. If the node is not labeled with
LongInteger, then an error is signaled.
mb-float int
float-value node
mb-float takes a Lisp integer and returns a MathBus term
labeled with IEEEFloat. Float-value accepts a MathBus
term that is labeled with IEEEFloat and returns a Lisp
number. If the node is not labeled with IEEEFloat, then
an error is signaled.
The attributes of a node can be manipulated using the following functions.
get-attribute node attrib
Returns the node associated with the Attrib attribute. Attrib
is the attributes index. If the current node does not have the
indicated attribute then nil is returned.
store-attribute node attrib value
Returns a node whose attrib attribute now has the value value.
This may modify node. If the node is an attributes node, then and
additional attribute is added to the node, or the existing
attribute with this identifier is modified.
map-over-attributes node function
[Lisp function
function is a function of two arguments. It is
called once for each attribute of node. The first argument
is the index of the an attribute and the second is the value
associated with the attribute.
Terms can be converted between the Weyl internal representations and MathBus terms using the weyli::convert-to-mb and weyli::convert-to-weyl functions.
write-node node &optional stream
Writes the object node out to stream (including the
header and trailer structures). The precise format that is used
depends upon *stream-mode*. The default value of *stream-mode*
is :base64, which means that the Base64 byte stream
specified in the MathBus terms structure document. For debugging,
*stream-mode* can be set to :debug-byte which
makes the byte stream easier for users to read-each 32-bit word
is output as a sequence of four decimal numbers surrounded by
square brackets.
If stream is not provided then *standard-output* is used.
read-node &optional stream
Creates a MathBus term from the data available on the stream.
If stream is not provided then *standard-input*
is used.
print-node node &optional stream
This function is mostly used for debugging, generating error messages and similar activities. print-node outputs the parenthesized form of the node we have been using in this document onto stream.
hash-code node
Returns the 32-bit integer that is the standard hash code of a
MathBus term according to the MathBus term structure
specification. Unfortunately, in most Lisp implementations this
hash code will be a large precision integer.
loop-over-subterms node (ind type) &body body
This is one of the most commonly used special forms when
working with MathBus nodes. The body forms are evaluated once for
each sub-terms of a node in an environment where the variables ind
and type are bound as follows. The index ind is
initially bound to 1, then 2, etc. until reaching the number of
sub-terms in node. The variable type is bound so as
to indicate the type of the sub-term indexed by ind. The
possible values are:
Type | Meaning |
nil | The sub-term is a pointer to another node. |
:stringId | The sub-term is a string identifier. |
:32bit | The sub-term is a 32-bit integer. |
node-iterate term function &optional context
Function is a function that accepts three arguments, a MathBus node, a state indicator and a binding context. Node-iterate applies function to term and to each sub-term of term. The values returned by function for each node can be used to control whether or not function is recursively applied to each sub-node. By calling special routines described below, function can access and modify the attributes of each node. By invoking other routines, the traversal of the sub-terms can be modified from depth first to breadth first or any combination or variation in between.