<> <> <> DIRECTORY Rope, IO, ViewerIO, ViewRec, Process; ViewRecExampleClient: PROGRAM IMPORTS IO, ViewerIO, 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, hu, 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], Allowable: PROC [h: Handle, which: ARRAY State OF BOOLEAN _ [FALSE, TRUE, FALSE]], Negate: PROC [h: Handle], SetName: PROC [h: Handle, newName: ROPE], Delay: PROC [milliseconds: CARDINAL], stuff: SEQUENCE length: CARDINAL OF ARRAY BOOLEAN OF REAL ]; Instance: TYPE = REF InstanceBody; InstanceBody: TYPE = RECORD[stream: IO.STREAM]; 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; Allowable: PROC [h: Handle, which: ARRAY State OF BOOLEAN _ [FALSE, TRUE, FALSE]] = {IF NOT which[h.state] THEN ERROR}; 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 _ [ViewerIO.CreateViewerStreams[name: IO.PutFR["foo#%g", IO.card[count _ count+1]]].out]]; h _ NEW [Rep[3]]; h.state _ Y; h.pokes _ 1; h.foo _ 7; h.fb _ de; h.bool _ FALSE; h.f _ abc; h.oof _ [-47, 17701]; h.name _ "fu"; h.SetState _ SetState; h.push _ Push; h.MustBe _ MustBe; h.Allowable _ Allowable; h.Negate _ Negate; h.SetName _ SetName; h.Delay _ Delay; FOR i: CARDINAL IN [0 .. h.length) DO h[i] _ [6.9, 2.7] ENDLOOP; [] _ ViewRec.ViewRef[agg: 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.