[Previous] [Up] [Next]
Go backward to Programming
Go up to Introduction to Programming
Go forward to Further Reading

Prolog

Logic Programming

Although Prolog is a computer programming language, it is very different from conventional programming languages. Conventional programming languages conform to the model of specifying computation in terms of an algorithm together with a data structure. Prolog, however, is a declarative language, and moreover, it is a logic programming language.

Most programming languages describe computation in terms of instructions, i.e. in terms of how to perform a task. The result of running the program is that the task is completed. But a declarative language does not specify how to perform a task, they describe what happens instead. The difference is roughly as follows: with a conventional language, the programmer writes the equivalent of "go and compute one plus two". If the execution is successful, the machine comes back shouting "three" (and has no recollection of what made it say that). In a declarative language, the programmer says "I want the result of adding one and two", and the machine comes back saying "one and two is three".

Logic programming languages are a particular type of declarative language. In these languages, computation is specified by a logic together with a control mechanism. The logic is a set of statements (effectively premises) in a formal language with properties similar to a formal logic. These statements make up the program. Computation is a matter of proving a statement given the program. This is carried out by checking if the statement follows from the premises. The concept of control stands for the method of trying the premises in the program to prove the statement.

Writing a Prolog Program

The procedure of writing and running a Prolog programme usually follows the following steps:

  1. The programmer starts by using an editor to construct a file which consists of the statements that make up the program. When the program is completed, the file is saved.
  2. A Prolog interpreter is loaded into the memory of the computer.
  3. The program is loaded into the interpreter (Prolog programs can be compiled as well, but you would usually at least try them out in interpreted form).
  4. The program is tested by feeding statements to the Prolog interpreter. The interpreter tries to prove the statements using the statements in the program. Hence, it is the interpreter which implements the control.
If the programmer wants to, it is possible to trace the execution of the interpreted program step by step.

Relevance of the Practical Tasks So Far

This section briefly explains how the things I have asked you to do so far are relevant to the course.


<a.von.klopp@bangor.ac.uk>

[Previous] [Up] [Next]