MathDBImpl.mesa
Carl Waldspurger, July 30, 1986 11:22:37 am PDT
Math Object "DataBase" Operations
DIRECTORY
MathExpr USING [AtomClass, CompoundClass],
List USING [AList, Assoc, PutAssoc],
MathDB;
MathDBImpl: CEDAR PROGRAM
IMPORTS List
EXPORTS MathDB ~
BEGIN
Abbreviations from Imported Interfaces
AtomClass: TYPE ~ MathExpr.AtomClass;
CompoundClass: TYPE ~ MathExpr.CompoundClass;
Global "DataBase" Lists
GlobalAtomClasses: List.AList ← NIL;
GlobalCompoundClasses: List.AList ← NIL;
Exported DB Indexes
AtomClassNames: PUBLIC LIST OF ATOMNIL;
CompoundClassNames: PUBLIC LIST OF ATOMNIL;
Class "DataBase" Operations
ResetAtomClasses: PUBLIC PROC[] ~ {
effects: Resets (i.e. destroys) the global AtomClass DataBase
GlobalAtomClasses ← NIL;
AtomClassNames ← NIL;
};
ResetCompoundClasses: PUBLIC PROC[] ~ {
effects: Resets (i.e. destroys) the global CompoundClass DataBase
GlobalCompoundClasses ← NIL;
CompoundClassNames ← NIL;
};
InstallAtomClass: PUBLIC PROC[class: AtomClass] ~ {
effects: Installs class in global AtomClass DataBase
add atom class to database - not very efficient, but does the job
GlobalAtomClasses ← List.PutAssoc[key: class.name, val: class, aList: GlobalAtomClasses];
add atom class name to index
AtomClassNames ← CONS[class.name, AtomClassNames];
};
InstallCompoundClass: PUBLIC PROC[class: CompoundClass] ~ {
effects: Installs class in global CompoundClass DataBase
add compound class to database - not very efficient, but does the job
GlobalCompoundClasses ← List.PutAssoc[key: class.name, val: class, aList: GlobalCompoundClasses];
add compound class name to index
CompoundClassNames ← CONS[class.name, CompoundClassNames];
};
LookupAtomClass: PUBLIC PROC[name: ATOM] RETURNS[AtomClass] ~ {
effects: Returns the AtomClass object associated with name.
SIGNALS notFound if no association exists
atomClass: AtomClass ← NARROW[List.Assoc[key: name, aList: GlobalAtomClasses]];
IF atomClass = NIL THEN ERROR notFound;
RETURN[atomClass];
};
LookupCompoundClass: PUBLIC PROC[name: ATOM] RETURNS[CompoundClass] ~ {
effects: Returns the CompoundClass object associated with name.
SIGNALS notFound if no association exists
compoundClass: CompoundClass ← NARROW[List.Assoc[key: name, aList: GlobalCompoundClasses]];
IF compoundClass = NIL THEN ERROR notFound;
RETURN[compoundClass];
};
Signals & Errors
notFound: PUBLIC ERROR = CODE;
END.