9.1 Facts and the program database
Consider the program from the previous page:
student(Lisa, 5). student(Martin, 3). student(John, 3). student(Edward, 7).
Definition of a fact
As was said, this program consists of four facts. A fact is simply the following:
In the example above, "student(Lisa, 5)" is a structure. Structures are terms. What makes the whole expression a fact is the period that follows it.
The structure can have arity 0
A fact can be any kind of term (except a variable) followed by a period. If the term is a structure, the structure can have arity 0, in which case it is also called an atomic constant. For example, the following is a fact:
Of course, the structure can also have an arity greater than 0, just as in the example program above.
The program database
A simple program can consist entirely of facts. Together, these facts make up what we call the program database. The facts are seen as data in a database. And since the facts also simultaneously make up the program, we call them the "program database". This principle is called "program as data," where the program itself is the data. In other programming languages, there is usually a sharp distinction between what is program and what is data, but not in Prolog.
Thus a fact is a structure followed by a period. The facts of a Prolog program make up the "program database". In Prolog, there is no sharp distinction between what is program and what is data, and this principle is called "program as data".
Next, we look at queries. Queries are questions we ask of the program database.
PrevLite: 9 A simple Prolog program
NextLite: 9.2 Queries
Prev: 9 A simple Prolog program
Up: 9 A simple Prolog program
Next: 9.2 Queries