HomeContents: |
## 8.2 Structures## IntroductionIn Prolog, relationships are expressed as "structures". This page defines what a structure is and introduces some vocabulary to describe structures. ## ExampleAn 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. ## DefinitionA structure consists of the following: - A functor (e.g., "birthday")
- A list of
*arguments*(e.g., "Albert", "14", etc.) enclosed in parentheses.
## The functorThe ## ArgumentsEach ## ArityThe number of arguments is called the ## NotationThe following notation is used for the name and arity of a structure:
For example:
## Zero arityA 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: Albert is really also a structure. We call it an ## Syntax of structuresThe syntax of structures is as follows. A structure is either: - If the arity is
**0**:- A functor (which must be an identifier)
- Or, if the arity is
**1 or greater**:- A functor (which must be an identifier)
- No space!
- An open-parenthesis
- A comma-separated list of arguments (which must be terms)
- A close-parenthesis
There must be no space between the functor and the open-parenthesis. ## SummaryStructures 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". ## NextIt 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 RelationshipsNextLite: 8.3 String constantsPrev: 8.1 RelationshipsUp: 8 TermsNext: 8.3 String constants |