PropertiesImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Christian Jacobi, September 19, 1985 3:33:07 pm PDT 4:15 pm
Christian Jacobi, September 19, 1985 5:51:52 pm PDT
DIRECTORY
Properties;
PropertiesImpl: CEDAR MONITOR
EXPORTS Properties =
BEGIN
PropList: TYPE = Properties.PropList;
GetProp: PUBLIC ENTRY PROC [propList: PropList, prop: REF] RETURNS [REFNIL] = {
ENABLE UNWIND => NULL;
IF propList=NIL THEN RETURN [NIL];
IF propList.first.key = prop THEN RETURN [propList.first.val]
ELSE {
lst: PropList ← propList.rest;
lag: PropList ← propList;
UNTIL lst = NIL DO
rest: PropList ← lst.rest;
IF lst.first.key = prop THEN {
lag.rest ← rest;
lst.rest ← propList.rest;
propList.rest ← lst;
RETURN [lst.first.val]
};
lag ← lst;
lst ← rest;
ENDLOOP;
};
};
PutProp: PUBLIC ENTRY PROC [propList: PropList, prop: REF, val: REFNIL] RETURNS [PropList] = {
ENABLE UNWIND => NULL;
IF val=NIL THEN RETURN [RemPropInternal[propList, prop]]
ELSE RETURN [PutPropInternal[propList, prop, val]]
};
RemPropInternal: INTERNAL PROC [propList: PropList, prop: REF] RETURNS [PropList] = INLINE {
lst: PropList ← propList;
lag: PropList ← NIL;
UNTIL lst = NIL DO
rest: PropList ← lst.rest;
IF lst.first.key = prop THEN {
IF lag = NIL THEN RETURN [rest];
lag.rest ← rest;
RETURN [propList];
};
lag ← lst;
lst ← rest;
ENDLOOP;
RETURN [propList];
};
PutPropInternal: INTERNAL PROC [propList: PropList, prop: REF, val: REF] RETURNS [PropList] = INLINE {
lst: PropList ← propList;
lag: PropList ← NIL;
WHILE lst # NIL DO
IF lst.first.key = prop THEN {
--Update list element in place
lst.first.val ← val;
RETURN [propList];
};
lag ← lst;
lst ← lst.rest;
ENDLOOP;
--prop not found on property list
lst ← LIST[[key: prop, val: val]];
IF lag = NIL THEN RETURN [lst];
lag.rest ← lst;
RETURN [propList];
};
END.