MathBus |
|
[ Term
Structure | Algebra
| Geometry | Logic | Drawing ]
[ Language Bindings
| C++ | Java | Lisp | ML ]
The basic term structure is only capable of representing trees. To represent more complex structures, the MathBus term structure includes a mechanism that allows one to name terms and then, by referring to these names, reuse the named terms one or more times in a larger term. The "names" used are nodes given the label MBVariable. A "binding" mechanism is also provided that restricts the scope of these variables. In addition, variables may have global values. These global values are maintained in a context.
MBVariable strId [Node]
Procedural variables are terms constructed with the MBVariable operator. The StrId is a string identifier used to identify the variable. To ease allocation, the string identifiers 'Temp00' through 'Temp99' are predefined in the global registry. The MBBind and MBGlobalAssign terms are used define binding scopes for procedural variables. The MBBind statement declares the variable to have local scope, while MBGlobalAssign gives the variable global scope.
The Bind term is used to give temporary variables meaning. The Bind statement is also used to declare the scope of a temporary variable. A term that uses a temporary variable whose scope has not been declared, or which is used outside of its declared scope is ill-formed.
Procedural variables are used to allow the tree structure provided by the MathBus term structure to be used to represent directed acyclic graphs. The globally bound variables allow sub-terms to be shared among different terms.
MBBind var1 val1 … varn valn term [Node]
The Bind term is used to declare the scope of one or more temporary variables and gives them initial meanings. The meaning of a Bind term is the meaning of its term. Thus, the term
(MBBind [Temp00] (Sine x) (Plus [Temp00] [Temp00])
has the meaning
(Plus (Sine x) (Sine x))
Standard lexical scoping rules are used when binding temporary variables, so
(MBBind [Temp00] (Sine x) (MBBind [Temp00] (Cosine x) (Plus [Temp00] [Temp00]))))
has the meaning
(Plus (Cosine x) (Cosine x))
where the two sub-terms are the same, not just copies of each other. When more than one variable is bound using a single MBBind term, the variables should be thought of as being bound simultaneously. Thus, none of the variables being bound can be used to define the meanings of other variables in a single MBBind term.
MBSelectContext ContextID [Command]
This term is only used when transmitting terms and within the Sequence term. It indicates which context should be used when looking up variables that are not bound by a MBBind term. If no context with the indicated ID exists, one will be allocated.
MBGlobalAssign variable term [Command]
The MBGlobalAssign command checks to see if there is lexical binding of variable (using MBBind), and if so signals an error. If there is not a global binding of variable then one is created. Finally, the global binding of variable is modified to be term.
Sequence Term1 Term2 … Termn [Command]
The simplest of the programming language terms is the Sequence term. The meaning of this term is the meaning of Termn. The earlier terms are used to cause side effects using command nodes like SelectContext and GlobalAssign.