Finding all alternatives in Prolog

There are no uninstantiated variables in a query like route(a, b). and so Prolog replies with either yes or no. However, if there are variables in a query, then all the different variable instantiations can be seen by simply typing ";" after each solution Prolog offers.

How does Prolog find multiple solutions? It does this in exactly the same way as it recovers from failure. It simply undoes the very last node of the search tree that it completed and looks for an alternative. Because its method of choosing the node to undo is always done on the basis of the latest completed node, this method is sometimes known as chronological backtracking.

Take time to work through Self-Test 2.

--------------------------------------------------------------------------

Navigation Menu

--------------------------------------------------------------------------