IPMathImpl.mesa
Copyright © 1984 Xerox Corporation. All rights reserved.
Doug Wyatt, August 17, 1984 1:39:31 pm PDT
DIRECTORY
IPInterpreter;
IPMathImpl: CEDAR PROGRAM
IMPORTS IPInterpreter
EXPORTS IPInterpreter
~ BEGIN OPEN IPInterpreter;
NonNIL: PROC[x: Any] RETURNS[Any] ~ {
IF x=NIL THEN x ← NumberFromAny[x]; -- raise a warning and return zero
IF x=NIL THEN ERROR ELSE RETURN[x];
};
Eq: PUBLIC PROC[a, b: Any] RETURNS[BOOL] ~ {
WITH a SELECT FROM
a: Number => WITH b SELECT FROM
b: Number => RETURN[a.value=b.value];
ENDCASE;
a: Identifier => WITH b SELECT FROM
b: Identifier => RETURN[a.atom=b.atom];
ENDCASE;
ENDCASE;
IF a=NIL OR b=NIL THEN RETURN[Eq[NonNIL[a], NonNIL[b]]]
ELSE RETURN[FALSE];
};
EqVector: PROC[a, b: Vector] RETURNS[BOOL] ~ {
shape: VectorShape ~ Shape[a];
IF Shape[b]#shape THEN RETURN[FALSE];
FOR i: Integer IN[shape.l..shape.l+shape.n) DO
IF NOT Eq[Get[a, i], Get[b, i]] THEN RETURN[FALSE];
ENDLOOP;
RETURN[TRUE];
};
EqName: PUBLIC PROC[a, b: Any] RETURNS[BOOL] ~ {
IF Eq[a, b] THEN RETURN[TRUE];
WITH a SELECT FROM
a: Vector => WITH b SELECT FROM
b: Vector => RETURN[EqVector[a, b]];
ENDCASE;
ENDCASE;
RETURN[FALSE];
};
Type: PUBLIC PROC[a: Any] RETURNS[TypeCode] ~ {
WITH a SELECT FROM
x: Number => RETURN[$Number];
x: Identifier => RETURN[$Identifier];
x: Vector => RETURN[$Vector];
x: Operator => RETURN[$Operator];
x: Transformation => RETURN[$Transformation];
x: PixelArray => RETURN[$PixelArray];
x: Color => RETURN[$Color];
x: Trajectory => RETURN[$Trajectory];
x: Outline => RETURN[$Outline];
ENDCASE;
IF a=NIL THEN RETURN[Type[NonNIL[a]]]
ELSE RETURN[$Other];
};
END.