ReverseName.mesa              --(note 1.1) 
Copyright Ó 1990, 1992 by Xerox Corporation. All rights reserved.
Brian Oki, May 14, 1990 10:27 am PDT
Christian Jacobi, May 14, 1992 2:22 pm PDT
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]
Reverses the user's login name and prints it out in the CommandTool window.
userName: ROPE ¬ SystemNames.UserName[];    --(note 1.6)
out: IO.STREAM ¬ cmd.out; -- cmd is an arg to ReverseName.
backwordsName: ROPE ¬ NIL;
Remove anything after the period in user name, e.g., ".PA", and check for the name Weiser.
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"];
Now reverse the name and concatenate them in reverse order.
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)
};
Start code registers a ReverseName command, which must be invoked for this program to do anything:
--(note 1.16)
Commander.Register[key: "ReverseName", proc: ReverseName, doc: "Reverses your user name"];
END.