database( { part( Part:string ), assembly( Part:string, PartsList:[quant(string,integer)] ) } ). index( part, [0] ). key( assembly, [0] ). % This example illustrates the use of recursion in LDL and, furthermore, % contains most of the more complex cases of recursion (i.e. mutual recursion, % nonlinear rules, complex terms, and embedded recursive cliques). % The predicates partsof and partsoflist in this example are mutually recursive. % The recursive rule for partsoflist is nonlinear and has an embedded recursive % clique (append). The list structures used in the rules are themselves an % application of complex terms and they contain embedded complex terms (the % quant structure). When the counting set method is applied to these rules, % all three counting indices are used and supplementary rules are generated, % illustrating the implementation of the Generalized Counting Method. export partsof($A,B). export partsof($A,$B). export partsoflist($A,B). export partsoflist($X,$B). %export my_append($L1, $L2, L3). % partsof(Part, PartsList) % PartsList is the list of all the basic parts required to construct Part. partsof(X, [X]) <- part(X). partsof(X, P) <- assembly(X, SubParts), partsoflist(SubParts, P). % partsoflist(SubPartsList, PartsList) % SubPartsList is a list of structures giving the part name and quantity of % this part that is required for the construction. PartsList is the list % of all basic parts required to construct the parts in SubPartsList. partsoflist([], []). %partsoflist(QuantPartList, PartsList) <- % QuantPartList = [quant(X,_) | Rest], partsoflist([quant(X,_) | Rest], PartsList) <- partsoflist(Rest, TailParts), partsof(X, HeadParts), append(HeadParts, TailParts, PartsList). % app(List1, List2, NewList) % NewList is List2 appended to the end of List1 app([X | L1], L2, [X | L3]) <- app(L1, L2, L3). app([], L, L). napp(L1, L2, L3) <- append(L1, L2, L3).