Naming Clauses in Prolog

Its well known that Prolog clauses can be used for multiple different uses. For example, if you're coming from a procedural background, and you want to define a procedure which gets the first element of a list, you would land at this Prolog clause:


But you will not have just made a function which takes the a list and returns the first element. You have really defined the relationship between a list, and the first element of that list. Since you have defined a relationship, you can use it for multiple purposes.

% X unifies to 1

% True

% X unifies to a list with first element being 1

This makes it difficult to name clauses coming from a procedural background, since many seek to name procedures based on one single effect/purpose. It makes the most sense in prolog to name clauses with the fact that you are defining a relationship, instead of defining a procedure which has an effect or return value.

Effectively this simple first clause has the power to construct a list, check if a list contains a value as its first element, and to extract the first element from a list.