8.2 Structures


In Prolog, relationships are expressed as "structures". This page defines what a structure is and introduces some vocabulary to describe structures.


An example of a structure could be:

birthday(Albert, 14, March, 1879)

We can interpret this to mean that a person named "Albert" was born on March 14, 1879.


A structure consists of the following:

  1. A functor (e.g., "birthday")
  2. A list of arguments (e.g., "Albert", "14", etc.) enclosed in parentheses.

The functor

The functor is simply a name we give to the structure. The functor must be an identifier. In Prolog+CG, an identifier is a sequence of letters, underscores, and digits, with the requirement that the first two characters must be letters.


Each argument to the structure can be any term.


The number of arguments is called the arity of the structure. For example, the "birthday" structure has arity 4.


The following notation is used for the name and arity of a structure:


For example:


Zero arity

A structure can have an arity of zero or more. When the arity us zero, there are no arguments, and consequently, we don't write the parentheses either. For example:


is really also a structure. We call it an atom. Thus "atom" is a special name we give to structures with arity 0.

Syntax of structures

The syntax of structures is as follows. A structure is either:

  • If the arity is 0:
    1. A functor (which must be an identifier)
  • Or, if the arity is 1 or greater:
    1. A functor (which must be an identifier)
    2. No space!
    3. An open-parenthesis
    4. A comma-separated list of arguments (which must be terms)
    5. A close-parenthesis

There must be no space between the functor and the open-parenthesis.


Structures consist of a functor and a comma-separated list of arguments enclosed in parentheses. The functor must be an identifier. The arguments must be terms. The arity of a structure is the number of arguments it has. A structure with arity 0 has no list of arguments, and is called an atom. We use the notation "functor/arity" to identify structures, e.g, "birthday/4".


It must be remembered that structures are just one kind of term. There are five other kinds of term, one of which is string constants. We look at string constants next.

PrevLite: 8.1 Relationships
NextLite: 8.3 String constants

Prev: 8.1 Relationships
Up: 8 Terms
Next: 8.3 String constants