<<>> <> <> <> <> <<>> DIRECTORY Commander USING [CommandProc, Register], IO USING [PutF1, PutRope, rope, STREAM], Rope USING [Concat, Equal, Fetch, Find, FromChar, Length, ROPE, Substr], SystemNames USING [UserName]; ReverseName: CEDAR PROGRAM IMPORTS Commander, IO, Rope, SystemNames ~ BEGIN --(note 1.3) ROPE: TYPE = Rope.ROPE; --(note 1.4) <<>> ReverseName: Commander.CommandProc ~ { --(note 1.5) <<[cmd: Commander.Handle] RETURNS [result: REF ANY _ NIL, msg: ROPE _ NIL]>> <<>> <> userName: ROPE ¬ SystemNames.UserName[]; --(note 1.6) out: IO.STREAM ¬ cmd.out; -- cmd is an arg to ReverseName. backwordsName: ROPE ¬ NIL; <> dotPos: INT = userName.Find["."]; --(note 1.7) IF dotPos # -1 THEN userName ¬ Rope.Substr[userName, 0, dotPos]; IF Rope.Equal[s1: userName, s2: "Weiser", case: FALSE] THEN IO.PutRope[out, "Hi, Mark!\n"]; <> FOR i: INT DECREASING IN [0..Rope.Length[userName]) DO <<--[1.1] (note 1.8)>> backwordsName ¬ Rope.Concat[backwordsName, Rope.FromChar[Rope.Fetch[userName, i]]] ENDLOOP; IO.PutF1[out, "Your user name backwards is: %g.\n", IO.rope[backwordsName]]; --(Note 1.9) }; <> --(note 1.16) Commander.Register[key: "ReverseName", proc: ReverseName, doc: "Reverses your user name"]; END.