PropImpl.mesa
Copyright © 1984, Xerox Corporation. All rights reserved.
Doug Wyatt, August 15, 1984 5:41:00 pm PDT
DIRECTORY
Atom USING [DottedPair, DottedPairNode],
Prop USING [PropList];
PropImpl: CEDAR PROGRAM
EXPORTS Prop
~ BEGIN
This property list mechanism regards a PropList as an immutable value. We don't use the procedures from Atom since 1) they might smash an existing PropList, and 2) they hold a global monitor in AtomImpl.
PropList: TYPE ~ Prop.PropList;
Put: PUBLIC PROC[propList: PropList, key: REF, value: REF] RETURNS[PropList] ~ {
rest: PropList ~ Rem[propList, key];
IF value=NIL THEN RETURN[rest]
ELSE {
pair: Atom.DottedPair ~ NEW[Atom.DottedPairNode ← [key, value]];
RETURN[CONS[pair, rest]];
};
};
Rem: PUBLIC PROC[propList: PropList, key: REF] RETURNS[PropList] ~ {
IF propList=NIL THEN RETURN[NIL]
ELSE IF propList.first.key=key THEN RETURN[propList.rest]
ELSE {
rest: PropList ~ Rem[propList.rest, key];
IF rest=propList.rest THEN RETURN[propList]
ELSE RETURN[CONS[propList.first, rest]];
};
};
Get: PUBLIC PROC[propList: PropList, key: REF] RETURNS[value: REF] ~ {
FOR list: PropList ← propList, list.rest UNTIL list=NIL DO
pair: Atom.DottedPair ~ list.first;
IF pair.key=key THEN RETURN[pair.val];
ENDLOOP;
RETURN[NIL];
};
END.