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:
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.
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:
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:
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