R Oberon10.Scn.Fnt/8FoldElemsNew#Oberon10.Scn.Fnt VAR s: Texts.Scanner; BEGIN Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s); IF s.class = Texts.Name THEN COPY(s.s, n) ELSE n := "" END END GetName; 88Oberon10.Scn.Fnt,o8FoldElemsNewOberon10.Scn.FntF98FoldElemsNew Oberon10.Scn.Fnt^8FoldElemsNewOberon10.Scn.FntOberon14.Scn.Fnt)\GraphicElemsAllocRectanglesNew |@|`\@H((t@hl(lHt \Oberon10.Scn.FntY father`A new element is inserted as the right or left child0 D  Oberon10i.Scn.Fnt 8p := tree; father := NIL; WHILE p # NIL DO IF elem.name = p.name THEN RETURN END; father := p; IF elem.name < p.name THEN p := p.left ELSE p := p.right END END; see pictureOberon10i.Scn.Fnt8b8#Oberon10.Scn.Fnt||IF father = NIL THEN tree := elem ELSIF elem.name < father.name THEN father.left := elem ELSE father.right := elem END8 VAR p, father: Node; BEGIN elem.left := NIL; elem.right := NIL; find insertion place (father) insert elem under father END Ins;86d VAR x: Node; PROCEDURE Ins(elem: Node);  BEGIN NEW(x); GetName(x.name); Ins(x) END Insert; 88Oberon10.Scn.Fntq8FoldElemsNew#Oberon10.Scn.Fntmm BEGIN IF x # NIL THEN P(x.left); Texts.WriteString(x.name); Texts.WriteLn(w); P(x.right) END END P;8>Y PROCEDURE P(x: Node);  BEGIN P(tree); Texts.Append(Oberon.Log, w.buf) END Print; 88Oberon10.Scn.Fnt/8FoldElemsNew#Oberon10.Scn.FntHH VAR p, x, y, father: Node; BEGIN p := tree; father := NIL; WHILE (p # NIL) & (name # p.name) DO father := p; IF name < p.name THEN p := p.left ELSE p := p.right END END; IF p # NIL THEN IF p.right = NIL THEN x := p.left ELSIF p.right.left = NIL THEN x := p.right; x.left := p.left ELSE x := p.right; WHILE x.left # NIL DO y := x; x := x.left END; y.left := x.right; x.left := p.left; x.right := p.right END; IF father = NIL THEN tree := x ELSIF name < father.name THEN father.left := x ELSE father.right := x END END END Del;80a VAR name: Name; PROCEDURE Del(name: Name);  BEGIN GetName(name); Del(name); END Delete; 87{(* This is a short demo that shows the use of fold elements. a) Middle-click at a filled triangle (e.g. behind the procedure Insert). The procedure body is shown. Middle-click at the non-filled triangle. The procedure body is collapsed again. b) Expand procedure Insert and then its local procedure Ins. You find two pseudocode actions that can also be expanded. c) Make a new fold element by selecting some text and executing FoldElems.Insert d) Compile this file with Folds.Compile */s A (deliberate) error is reported. Set the caret at the beginning of the text and execute FoldComp.ShowError . The error location is revealed and marked with a small rectangle. middle-click at it to get the error message. e) FoldElemp.Expand expands all elements. FoldElems.Collapse collapses them all. *) MODULE FoldDemo; IMPORT Oberon, Texts; TYPE Name = ARRAY 32 OF CHAR; Node = POINTER TO NodeDesc; NodeDesc = RECORD name: Name; left, right: Node END; VAR tree: Node; w: Texts.Writer; PROCEDURE GetName(VAR n: Name);  PROCEDURE Insert*;  PROCEDURE Print*;  PROCEDURE Delete*;  BEGIN tree := NIL; Texts.OpenWriter(w) END FoldDemo.