What we've covered so far provides us with a reasonable working subset of Prolog. We haven't covered:
and various other things. These will be covered in tutorials as needed, or can be found in your favourite Prolog text book. However, at the beginning it is better to just use the subset we've covered so far. Most of the other features introduce non-pure/non-logical features which may result in bad habits if used too soon!
Before leaving Prolog its worth saying something about programming style. As in other programming languages, a crucial feature is the readability of your code. Programs should consist of simple, short predicate definitions, organised, as far as possible, in a way that reflects the structure of the program. Procedures should always be commented. The following illustrates a common style for commenting:
% member(?Item, ?List) % is true when List is a list, and Element occurs in it. It may be used % to test for an element or to enumerate all the elements by backtracking. % Indeed, it may be used to generate the Set! member(Item, [Item|_]). % It's a member if it matches the head. member(Item, [_|Tail]) :- member(Item, Tail). % or if its a member of the tail.
This starts of with a skeletal description of the predicate, showing the predicate name and its arguments (in order), with the names of the arguments giving an idea of the type of structure expected and a mode declaration at the start of each argument. Mode declarations are either + (if the argument is instantiated (bound) whenever the predicate is called), - (if the argument is uninstantiated when the predicate is called) or ? (if the argument can be either instantiated or uninstantiated when called). Below this is a description in English of the behaviour of the predicate. This often makes use of the argument names from the skeletal description. Here you should put whatever information might be useful to you or to your readers. Within the predicate definition you can put further comments on any obscure subgoals or particular clauses.
Thats enough about Prolog. Its much better to learn by doing and asking, so start programming, and if confused, read a book, or try to find someone who isn't!