
Allegro CL 
ANSI Common Lisp 4 Types and Classes 4.3 Classes 4.3.5 Determining the Class Precedence List
4.3.5.1 Topological SortingTopological sorting proceeds by finding a class C in S_{C} such that no other class precedes that element according to the elements in R. The class C is placed first in the result. Remove C from S_{C}, and remove all pairs of the form (C,D), D S_{C}, from R. Repeat the process, adding classes with no predecessors to the end of the result. Stop when no element can be found that has no predecessor.If S_{C} is not empty and the process has stopped, the set R is inconsistent. If every class in the finite set of classes is preceded by another, then R contains a loop. That is, there is a chain of classes C_{1}, ... ,C_{n} such that C_{i} precedes C_{i+1}, 1 <= i<n, and C_{n} precedes C_{1}. Sometimes there are several classes from S_{C} with no predecessors. In this case select the one that has a direct subclass rightmost in the class precedence list computed so far. (If there is no such candidate class, R does not generate a partial ordering  the R_{c}, c S_{C}, are inconsistent.)
In more precise terms, let {N_{1}, ... ,N_{m}}, m The effect of this rule for selecting from a set of classes with no predecessors is that the classes in a simple superclass chain are adjacent in the class precedence list and that classes in each relatively separated subgraph are adjacent in the class precedence list. For example, let T_{1} and T_{2} be subgraphs whose only element in common is the class J. Suppose that no superclass of J appears in either T_{1} or T_{2}, and that J is in the superclass chain of every class in both T_{1} and T_{2}. Let C_{1} be the bottom of T_{1}; and let C_{2} be the bottom of T_{2}. Suppose C is a class whose direct superclasses are C_{1} and C_{2} in that order, then the class precedence list for C starts with C and is followed by all classes in T_{1} except J. All the classes of T_{2} are next. The class J and its superclasses appear last. 