Linguistics 482
          Computational Linguistics
Dr. A. C. Brett & Laura J. Proctor
Department of Linguistics
University of Victoria

Prolog Introductory Notes

Prolog is usually identified as a descriptive or declarative programming language because almost all Prolog statements represent declarations of facts, or assertions of relationships among facts. There are a few special statements in the Prolog language that communicate instructions or commands, and some Prolog statements might also be seen as posing questions, but such statements can be viewed more as assertions of facts or relationships that are to be tested. Thus, most statements in the Prolog language are analogous to the declarative, or perhaps indicative mood sentences in a natural language.

The essentially descriptive nature of the Prolog language can be contrasted with the procedural or injunctive nature of almost all other programming languages. These languages often do include some special statements that are descriptive or declarative, but virtually all other statements are analogous to imperative mood natural language sentences. Thus, they are more nearly like the statements one would normally expect of a programming language since they consist of the commands one might give a computer. A program in a procedural language then consists of a self-contained sequence of commands or instructions detailing how a task is to be performed or a problem is to be solved.

A Prolog program, on the other hand, consists of a collection of statements describing what is known about a particular domain or universe of discourse. Thus, a collection of Prolog statements defining a particular domain might be more appropriately identified as a database, rather than as a program, although the term "program" is still frequently used to describe such collections of statements.

A Prolog program, or more appropriately a Prolog database, might consist of statements of fact specifying the lexical categories of some words in a natural language, together with other Prolog statements identifying the relationships among the lexical categories which determine the constituents that make up the sentences in the natural language. Other Prolog statements might then be used to specify sequences of words in order to test, on the basis of the facts and relationships in the database, what sequences of words comprise sentences in the natural language.

Prolog statements are themselves analogous to the sentences or clauses of a natural language. Like natural language sentences, Prolog statements are constructed by combining word- or morpheme-like entities according to the syntax of the language. Prolog syntax is extremely simple, and while somewhat more complicated, the morphology of the word-like entities of Prolog is also very straightforward.

The word-like entities of Prolog are called terms, and the sentence-like constructs of the language are called either clauses or assertions. Related clauses can, and usually are combined into predicates which are something like compound sentences. The morphology of the word-like terms of Prolog and the sentence-like clauses and predicates of the language are described on other pages.

The sentence-like constructs of programming languages such as Prolog are intended to communicate information or instructions to a computer. Hence, programming languages are sometimes called "computer languages." One might expect that, when information or instructions are communicated to a computer in one of these languages, the machine will "understand" the information or instructions in the sense that it will perform the intended operations. Such is not generally the case, however.

While they might be called computer languages, such languages as Prolog are actually "foreign" to a computer. One can no more communicate directly with a computer using Prolog, or using any other common programming language, than one can do word processing without word processing software. In order that one communicate with a computer using the Prolog language, Prolog software must be installed on the machine. Information about the particular Prolog software installed on the machines we are using in this course is included on the Prolog Software page.

A Prolog software package includes programs that, in effect, interpret the Prolog language for a computer, or translate Prolog into the language of the machine. Computers actually do have their own "native languages," called machine languages, but virtually no one writes programs in these low-level languages. There are languages that are a step removed, or a level above the low-level machine languages that are called assembly languages. Even these languages, however, must be translated into machine language, and while assembly languages are easier to master than the machine languages, they are still difficult to use. They require such detailed knowledge of the intimate workings of the machine that writing programs in assembly language often entails that more effort be dedicated to contending with apects of the operations of the computer than is devoted to the particular problem one is attempting to use the computer to solve.

Unless one is actually working on a problem that directly involves the low-level operations of the computer, one normally writes programs in a high-level language such as Prolog. The term "level" used in this context refers to the extent of the remove or degree of abstraction of the programming language away from details of the inner workings of the machine. Writing a program in a higher-level language requires relatively little knowledge about how the machine actually processes the information or instructions expressed in the statements of the language.

Prolog can be regarded as exhibiting a particularly high degree of abstraction. The facts and relationships expressed in Prolog statements are almost completely divorced from any connection to the operations a machine must perform to process these facts and relationships. A procedural language, on the other hand, might be seen as possessing a relatively lower degree of abstraction than Prolog. The instructions expressed in their statements usually have a closer connection to operations performed by the machine.

While the high-level languages are removed to a greater or lesser extent from the actual operations of the machine, the meaning of their statements, and the constituents and word-like entities comprising them, is often construed in terms of the operations of the machine. For example, a variable might be interpreted as a reference to a location in the memory of the machine. The instantiation of a value on this variable may then be construed as the storing of the value at the location identified by the variable. This system for ascribing meaning is called a procedural or operational semantics. This semantics is useful for describing, and understanding, how the machine processes the constructs of a high-level language. Using this system, however, does not require that one concern oneself with how the machine actually performs the operations involved. While the constructs of a high-level language such as Prolog might be explained in terms of the operations a computer might perform to process these constructs, some variety of interpreter or translator program is still required in order that the machine itself "understand" the instructions or information communicated to it in these constructs.

A translator program for a high-level programming language such as Prolog is usually called a compiler. The term "compiler" is used because the translator program has available to it a library of the sequences of machine language instructions that perform all the operations required to run a program written in the high-level language that it is intended to translate. The process of translating a high-level language program, usually called a source language program, then consists of compiling those sequences of instructions from the translator's library that will perform the operations identified or required by the particular source program. The resulting machine language program is sometimes called an object code, or is described as an object language program.

Following compilation of a source language program into object language, the object code produced is then usually processed further by a program that is sometimes called a linker, or some variation on this name. The linker combines the object code with other programs that, for example, connect the object language program to the operating system of the computer, and enable the compiled program to execute on the computer. The result of this process, consisting of the compiled program and the operating system links, is frequently described as an executable. All the programs you might run on a computer are executables, including of course, compiler programs. A compiler is usually written, for the most part, in a high-level language. The resulting program is then compiled into object language and processed by a linker to produce an executable.

Prolog programs can be compiled into object language, but normally, particularly when one is developing and testing a Prolog program, one employs an interpreter. An interpreter, like a compiler, is usually an executable. Unlike a compiler, however,an interpreter does not translate high-level source language into object code. Rather, an interpreter takes the information and intructions written in the high-level language program and causes appropriate operations to be performed by the computer. Thus, it is the interpreter itself that is executing, rather than the high-level language program. The statements of a high-level language such as Prolog merely control the execution of the interpreter by determining the operations it instructs the machine to perform.

The statements comprising a Prolog program are normally, albeit not always, written before the interpreter is started. One normally writes a Prolog program using a text editor, a program that enables you to type, change, and save the text comprising the statements of your Prolog program. An editor is sometimes included along with the interpreter in the Prolog software package, or is accessible from the interpreter. Having written your Prolog program, and saved the file containing it, you are then ready to start the interpreter. Notes on starting the Prolog interpreter, which is sometimes called a Listener, are included on the Prolog Listener page.

Having started the Prolog interpreter, or Listener, you must then identify your program to it by picking the consult option from a menu, or by typing the consult assertion. The consult assertion is one of those Prolog statements that might be viewed as consisting of an imperative mood verb. It can also be regarded as the assertion of a claim to be tested. From the latter perspective, the claim you are making is that the file you have identified contains a program consisting of syntactically correct Prolog statements. If the file does indeed consist of syntactically correct Prolog, then the interpreter displays the message "yes." In this case, you may now pose queries, or assert claims, about the facts and relationships that comprise your Prolog program.

Any query or claim you type must comprise a Prolog statement. The interpreter checks its syntax, and then undertakes the task of testing your claim, or responding to your query. Your query is answered, or your claim is tested, by a matching process called unification. Essentially, the unification process consists of matching your claim, or query, with the facts or relationships asserted in the statements comprising your Prolog program. The interpreter has available to it a program consisting of the instructions required in order that the computer perform the unification procedure.

Consistent with the descriptive nature of Prolog, you need not know the details of how the machine performs the procedure; you need know only what the machine is doing during the unification process. An understanding of unification is required in order that you use the Prolog language effectively. Hence, a significant proportion of the time during this part of the course will be devoted to the Prolog unification process. Notes on unification are contained on the Unification in Prolog page.

Last updated: 9 October 2005

Linguistics 482 Linguistics 482 Home Page Top of Page