8.1 Relationships


Before we go into detail with what a structure is, we need to look at what a relationship is.

Three examples

For example, the following are all relationships, expressed in the syntax of Prolog:

  1. father(abraham, isaac)
  2. child(isaac, abraham)
  3. plus(2,3,5)

Meaning of the examples

The first relationship says that Abraham is the father of Isaac. The second relationship says that Isaac is the child of Abraham. The third relationship says that two plus three equals five. We will get to the details of the syntax in due course.

Relationships are central

When describing an application-domain in Prolog, relationships are central. Therefore, it is necessary to learn how to identify relationships, their participants, and their central or main participant (if any).

Primary and secondary participants

For example, in the "father" relationship, there are two participants: The father and the son (or daughter). In this relationship, the father is the central or main participant, since the relationship gets its name after him. It is customary (but not necessary) to write the central or main participant as the first participant in the relationship. That is why the above relationship is written as "father(abraham, isaac)" rather than "father(isaac, abraham)".

In the "plus(2,3,5)" example, the two first participants ("2" and "3") are equally important, but they are both more important than the result ("5"). Therefore, we place the result at the end of the relationship.

We can also say that the two numbers to be added are "primary", whereas the result is "secondary". Likewise, in the "father" relationship, the father is "primary", whereas the son or daughter is "secondary".


Exercise: Can you identify the relationship, the three participants, and the primacy of each participant, in the following sentence: "John gave Marty a book"?


Thus relationships are central in Prolog programming, all relationships have at least one participant, the participants can usually be assigned an importance amongst themselves, and we usually place the more important participants first in the written form of the relationship.

PrevLite: 8 Terms
NextLite: 8.2 Structures

Prev: 8 Terms
Up: 8 Terms
Next: 8.2 Structures