When programming in Prolog, we must pick two kinds of names:
A good predicate name makes clear what each argument means. By convention, underscores are used in names to separate the description of different arguments. This is because
Examples of good predicates names are:
Note that descriptive names are used. Imperatives are avoided. Using descriptive names is advisable because Prolog predicates can typically be used in multiple directions, and the name should be applicable also of all or none of the arguments are instantiated.
Mixed capitalization is more common when selecting names of variables. For example:
GreatestDivisor. A common convention for naming variables that denote successive states is using
S represents the final state.
There are only a few language constructs in Prolog, and several ways for indenting them are common.
No matter which style is chosen, one principle that should always be adhered to is to never place
(;)/2 at the end of a line. This is because
, look very similar, and
, frequently occurs at the end of a line. Therefore, clauses that use a disjunction should for example be written as:
( Goal1 ; Goal2 )
Ideally, Prolog predicates can be used in all directions. For many pure predicates, this is also actually the case. However, some predicates only work in particular modes, which means instantiation patterns of their arguments.
By convention, the most common argument order for such predicates is:
p(..., State0, State, ...)