GGUtilityImpl.mesa
Last edited by Bier on August 16, 1985 11:23:39 pm PDT.
Contents: General Purpose routines for use by Gargoyle.
DIRECTORY
GGUtility;
GGUtilityImpl: CEDAR PROGRAM
IMPORTS
EXPORTS GGUtility =
BEGIN
Utility Functions for LIST OF REF ANY.
FindEntityAndNeighbors: PROC [entity: REF ANY, entityList: LIST OF REF ANY] RETURNS [beforeEnt, ent, afterEnt: LIST OF REF ANY] = {
lastE: LIST OF REF ANYNIL;
eList: LIST OF REF ANY ← entityList;
IF eList = NIL THEN ERROR EntityNotFound;
UNTIL eList = NIL DO
IF eList.first = entity THEN {
beforeEnt ← lastE; ent ← eList; afterEnt ← eList.rest; RETURN};
lastE ← eList;
eList ← eList.rest;
ENDLOOP;
SIGNAL EntityNotFound;
};
EntityNotFound: PUBLIC SIGNAL = CODE;
IsMember: PUBLIC PROC [entity: REF ANY, entityList: LIST OF REF ANY] RETURNS [BOOL] = {
FOR list: LIST OF REF ANY ← entityList, list.rest UNTIL list = NIL DO
IF list.first = entity THEN RETURN[TRUE];
ENDLOOP;
RETURN[FALSE];
};
DeleteEntityFromList: PUBLIC PROC [entity: REF ANY, entityList: LIST OF REF ANY] RETURNS [smallerList: LIST OF REF ANY] = {
beforeEnt, ent, afterEnt: LIST OF REF ANY;
notFound: BOOLFALSE;
[beforeEnt, ent, afterEnt] ← FindEntityAndNeighbors[entity, entityList];
IF notFound THEN RETURN[entityList];
IF beforeEnt = NIL THEN smallerList ← afterEnt
ELSE {
beforeEnt.rest ← afterEnt;
smallerList ← entityList;
};
}; -- end of DeleteEntityFromList
AppendList: PUBLIC PROC [list1, list2: LIST OF REF ANY] RETURNS [result: LIST OF REF ANY] = {
pos: LIST OF REF ANY;
newCell: LIST OF REF ANY;
Non-destructive (copies the first list).
IF list1 = NIL THEN RETURN[list2];
result ← CONS[list1.first, NIL];
pos ← result;
FOR l: LIST OF REF ANY ← list1.rest, l.rest UNTIL l = NIL DO
newCell ← CONS[l.first, NIL];
pos.rest ← newCell;
pos ← newCell;
ENDLOOP;
pos.rest ← list2;
};
END.