/* This module tests the printing system when there are possible * circularities. The system uses references to objects that have * already been printed to control this. As a pleasant side * effect in some circumstances this also saves space. */ // Test simple self-reference class reflex { reflex r; }; reflex r = (); r.r = r; print(r); // Test indirect reference loops. class a { string name; b b; } class b { int number; a a; } a a = (); b b = (); a.name = "a"; a.b = b; b.number = 2; b.a = a; print(a); print(b); // Make a more elaborate tree-like structure and print it. class taxon { taxon next; taxon children; short type; string name; } to newTaxon(short type, string name) into taxon t { t = (); t.type = type; t.name = name; } taxon root = newTaxon(0, "root"); taxon animals = newTaxon(1, "animals"); root.children = animals; taxon landCritters = newTaxon(2, "land critters"); animals.children = landCritters; taxon waterCritters = newTaxon(2, "water critters"); landCritters.next = waterCritters; taxon cats = newTaxon(3, "cats"); landCritters.children = cats; taxon fish = newTaxon(3, "fish"); waterCritters.children = fish; taxon frogs = newTaxon(3, "frogs"); cats.next = frogs; fish.next = frogs; taxon plants = newTaxon(1, "plants"); animals.next = plants; taxon ferns = newTaxon(2, "ferns"); plants.children = ferns; taxon trees = newTaxon(2, "trees"); ferns.next = trees; print(root); // Print the same tree but in a prettier fashion printTaxon(0, root); to printTaxon(int level, taxon p) { int i; for (i=0; i