FILE ViewRecExampleClient.Mesa
last changed by Spreitzer at March 11, 1983 12:31 pm
A sample use of ViewRec
DIRECTORY Rope, IO, ViewRec, Process;
ViewRecExampleClient:
PROGRAM
IMPORTS IO, ViewRec, Process =
BEGIN
Wasnt: ERROR = CODE;
ROPE: TYPE = Rope.ROPE;
State: TYPE = {x, Y, z};
Foo: TYPE = {xyz, abc, lmn};
FuBar: TYPE = {abc, de, f, g, h, i, j, k, l, m};
Handle: TYPE = REF Rep;
Rep:
TYPE =
RECORD [
state: State ← Y,
push: PROC[inst: Instance, number: LONG CARDINAL],
pokes: LONG INTEGER ← 1,
foo: LONG CARDINAL ← 7,
fb: FuBar ← de,
char: CHAR ← '\n,
bool: BOOLEAN ← FALSE,
f: Foo ← abc,
oof: RECORD [a: REAL, b: INTEGER] ← [-47, 17701],
name: Rope.ROPE ← "fu",
SetState: PROC [h: Handle, to: State] RETURNS [was: State],
MustBe: PROC [h: Handle, what: State ← z, eq: BOOLEAN],
Negate: PROC [h: Handle],
SetName: PROC [h: Handle, newName: ROPE],
Delay: PROC [milliseconds: CARDINAL]
];
Instance: TYPE = REF InstanceBody;
InstanceBody: TYPE = RECORD[stream: IO.Handle];
count: CARDINAL ← 0;
SetState:
PROC [h: Handle, to: State]
RETURNS [was: State] =
BEGIN
was ← h.state;
h.state ← to;
h.pokes ← -(h.pokes + (IF h.pokes < 0 THEN -1 ELSE 1));
END;
MustBe:
PROC [h: Handle, what: State ← z, eq:
BOOLEAN] =
BEGIN
IF (h.state = what) # eq THEN ERROR Wasnt;
END;
Push: PROC[inst: Instance, number: LONG CARDINAL ← 20] = {inst.stream.PutF["given %g\n", IO.card[number]]};
Negate: PROC [h: Handle] = {h.pokes ← - h.pokes};
SetName: PROC [h: Handle, newName: ROPE] = {Delay[5000]; h.name ← newName};
Delay:
PROC [milliseconds:
CARDINAL] =
{Process.Pause[Process.MsecToTicks[milliseconds]]};
Doit:
PROC
RETURNS [h: Handle] =
BEGIN
instance: Instance ← NEW[InstanceBody ← [IO.CreateViewerStreams[IO.PutFR["foo#%g", IO.card[count ← count+1]]].out]];
h ←
NEW [Rep ← [
SetState: SetState,
push: Push,
MustBe: MustBe,
Negate: Negate,
SetName: SetName,
Delay: Delay]];
[] ← ViewRec.ViewRef[rec: h,
specs: ViewRec.BindAllOfATypeFromRefs[h,
NEW [Instance ← instance]].
BindingListAppend[ViewRec.BindAllOfATypeFromRefs[h, NEW[Handle ← h]]],
viewerInit: [iconic: FALSE, name: IO.PutFR["Test#%g", IO.card[count]]],
paint: TRUE];
END;
END.