Next: Some Exercises Up: Prolog TermsBacktracking Previous: Backtracking

Declarative and Procedural Views of Programs

At this point it is worth thinking a bit about what Prolog programs mean. There are generally two ways to look at any Prolog rule - as a declarative statement about what is true, or as a procedural statement about how to do something. One of the claimed advantages of Prolog is that it is often possible to think of programs purely declaratively. How Prolog proves things should be of less concern. However, for any reasonably complex program, as we discussed earlier, it often becomes important to think about how it executes the program. For example, the order of subgoal execution may be crucial to the efficiency of the program, and variables may be used in a way that does not have a simple declarative reading. Prolog also allows non-logical statements, like write statements and assertions. When these are included in a program it becomes even more important to think about what Prolog is doing.

To state a bit more clearly what we mean by declarative and procedural readings of programs, if we have a rule:


   p :- q, r.

The declarative reading is: ``p is true if q is true and r is true''. The procedural reading can be stated as ``to solve problem p, first solve problem q and then solve problem r'', or alternatively ``to satisfy p, first satisfy q and then r''.


alison@
Fri Aug 19 10:42:17 BST 1994