public override void print(Node t, int n, bool p) { // Indent (if necessary) for (int i = 0; i < n; i++) { Console.Write(" "); } // Get the car and cdr Node car = t.getCar(), cdr = t.getCdr(); Console.Write("("); // ( car.print(n, true); // Condition Console.WriteLine(); // Carriage return n++; // Increase indentation for the // subsequent arguments // Set form to regular so it can all print on the same line // Use false parameter to tell the regular form to not print the // carriage return t.setForm(new Regular(false)); while (!cdr.isNil()) { // Print cond's conditions and expressions for (int i = 0; i < n; i++) { // Indent the parameters of cond Console.Write(" "); } cdr.getCar().print(0, false); // Implicitly recur on cars Console.WriteLine(); // Carriage return cdr = cdr.getCdr(); // Recur down the right side of the tree } // Decrease indentation because only the arguments needed to // be indented n--; // Indent (if necessary), print the final right parenthesis and the // final carriage return for (int i = 0; i < n; i++) { Console.Write(" "); } // Print final right paren and carriage return cdr.print(0, true); Console.WriteLine(); }
public override void print(Node t, int n, bool p) { // Indent (if necessary) for (int i = 0; i < n; i++) { Console.Write(" "); } // Get the car and cdr Node car = t.getCar(), cdr = t.getCdr(); Console.Write("("); // ( car.print(n, true); // Begin Console.WriteLine(); // Carriage return n++; // Increase indentation // Set form to regular so it can all print on the same line // Use false parameter to tell the regular form to not print the // carriage return t.setForm(new Regular(false)); while (!cdr.isNil()) { // Indent the parameters of begin if necessary for (int i = 0; i < n; i++) { Console.Write(" "); } // Print the cadr // (This implicitly recurs on the left of the tree) cdr.getCar().print(0, false); Console.WriteLine(); // Recur on the right of the tree. cdr = cdr.getCdr(); } // Print the final right parenthesis with no indentation // and carriage return cdr.print(0, true); Console.WriteLine(); }
public override void print(Node t, int n, bool p) { // Indent (if necessary) for (int i = 0; i < n; i++) Console.Write(" "); // Get the car and cdr Node car = t.getCar(), cdr = t.getCdr(); // Print "(begin " Console.Write("("); car.print(n, true); Console.WriteLine(); n++; // Set form to regular so it can all print on the same line // Use false parameter to tell the regular form to not print the // carriage return t.setForm(new Regular(false)); while (!cdr.isNil()) { // Indent and print all parameters (cadrs) recursively for (int i = 0; i < n; i++) Console.Write(" "); cdr.getCar().print(0, false); Console.WriteLine(); cdr = cdr.getCdr(); } // Print the final right parenthesis and carriage return cdr.print(0, true); Console.WriteLine(); }