-- Example of Prolog-style declarative programming in LX -- Print all paths to the screen in a directed acyclic graph -- Import the backtracking engine and basic text I/O import D = DECLARATIVE_PROGRAMMING_SUPPORT import IO = LX.TEXT_IO -- The equivalent of the Prolog program {prolog} D.declarations PrintAllPaths is -- Clauses (the type is D.clause) using D with clause path[X, X] is IO.Write X clause path[X, Z] is edge Y, Z; path X, Y; IO.Write Z clause allPaths[X, Z] is path X, Z; IO.WriteLn; D.fail -- Facts. Syntactically, these are procedure calls to 'edge'. -- Semantically, the {prolog} pragma modifies the meaning of the -- current declaration, so that the 'edge' instruction is seen -- as a truth to verify for 'PrintAllPaths' to be true. edge A, B edge A, C edge A, D edge B, E edge C, E edge C, F edge D, F edge F, G edge G, E -- Invoking PrintAllPaths from conventional code procedure Test() is -- Check if we can find a solution to 'allPaths' D.Verify PrintAllPaths.allPaths -- Run solutions one by one (as an iterator) with D.name X, Y for PrintAllPaths.allPaths[X, Y] loop IO.WriteLn "Currently exploring X=", X, " and Y=", Y