EnvironmentImpl.mesa
Arnon, April 29, 1987 3:32:19 pm PDT
Values for variables
DIRECTORY
List,
MathDB,
MathExpr,
AlgebraClasses,
Environment,
Rope;
EnvironmentImpl: CEDAR PROGRAM
IMPORTS List, MathDB
EXPORTS Environment ~
BEGIN OPEN AC: AlgebraClasses;
Abbreviations from Imported Interfaces
ROPE: TYPE ~ Rope.ROPE;
EXPR: TYPE = MathExpr.EXPR;
Object: TYPE = AC.Object;
Method: TYPE = AC.Method;
The Environment
Table: List.AList ← NIL;
DataBase Operations
ResetEnvironment: PUBLIC PROC[] ~ {
effects: Resets (i.e. destroys) the Environment
Table ← NIL;
};
InstallVariable: PUBLIC PROC[var: ATOM, value: EXPR] ~ {
effects: Installs value for variable in Environment
add to database - not very efficient, but does the job
Table ← List.PutAssoc[key: var, val: value, aList: Table];
};
RemoveVariable: PUBLIC PROC[var: ATOM] ~ {
effects: delete the Environment value associated with var, if present. Only needed when want to delete a variable name entirely, not if just want to replace.
Table ← MathDB.KillAssoc[key: var, aList: Table];
};
LookupVariable: PUBLIC PROC[var: ATOM] RETURNS[value: EXPR] ~ {
effects: Returns the value associated with variable.
value ← NARROW[List.Assoc[key: var, aList: Table]];
RETURN[value];
};
Signals & Errors
notFound: PUBLIC ERROR = CODE;
Start Code
ResetEnvironment[];
END.