Science  People  Locations  Timeline
Index: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Home > Prolog


 Contents
Prolog is a logical programming language. The name Prolog is taken from programmation en logique ("logic programming"). It was created by Alain Colmerauer around 1972. It was an attempt to make a programming language that enabled the expression of logic instead of carefully specified instructions on the computer.

Prolog is used in many artificial intelligence programs and in computational linguistics (especially natural language processing). Its syntax and semantics are considered very simple and clear. (The original goal was to provide a tool for computer-illiterate linguists.) A lot of the research leading up to modern implementations of Prolog came from spin-off effects caused by the fifth generation computer systems project (FGCS) which chose to use a variant of Prolog named Kernel Language for their operating system.

Prolog is based on predicate calculus (more precisely first-order predicate calculus); however it is restricted to allow only Horn clauses. Execution of a Prolog program is effectively an application of theorem proving by first-order resolution. Fundamental concepts are unification, tail recursion, and backtrackingBacktracking is a strategy for finding solutions to constraint satisfaction problems. These are problems with a complete solution, whereby the order of elements does not matter. The problems consist of a set of variables each of which must be assigned a v.

1 Data types

Prolog does not employ data types in the way usual in the common programming languages. We may rather speak about Prolog lexical elements instead of data types.

1.1 Atoms

The text constants are introduced by means of atoms. An atom is a sequence consisting of letters, numbers and underscores, which begins with a lower-case letter. Usually, if non-alphanumeric atom is needed, it is surrounded with apostrophes (e.g. '+' is an atom, + is an operator).

1.2 Numbers

Most Prolog implementations don't distinguish integers from real numbers.

1.3 Variables

Variables are denoted by a string consisting of letters, numbers and underscore characters, and beginning with an upper-case letter. In the Prolog environment, a variable is not a container, which can be assigned to (unlike procedural programming languages). Its behaviour is closer to a pattern, which is increasingly specified by unification.

The so called anonymous variable is written as a single underscore (_).

1.4 Terms

Terms are the only way Prolog can represent complex data. A term consists of a head, also called functor (which must be an atom) and parameters (unrestricted types). The number of parameters, so called arityIn mathematics, the arity of a function or an operator is the number of arguments or operands it takes, A function or operator can thus be described as unary binary ternary etc. Terms such as 7-ary or n ary are also used. Sometimes, it is useful to consid of term, is significant. A term is identified by its head and arity, usually written as functor/arity.

1.5 Lists

A list isn't a standalone data type, because it is defined by a recursive construction (using term '.'/2):

  1. atom [] is an empty list
  2. if T is a list and H is an element, then the term '.'(H, T) is a list.

The first element, called the head, is H, which is followed by the contents of the rest of the list, designated T or tail. The list [1, 2, 3] would be represented internally as '.'(1, '.'(2 , 3 )) A syntactic shortcut is [H | T], which is mostly used to construct rules. The entirety of a list can be processed by processing the first element, and then the rest of the list, in a recursiveSee: Recursion Recursive function Recursive set Recursively enumerable set Recursively enumerable language Primitive recursive function. manner.

For programmer's convenience, the lists can be constructed and deconstructed in a variety of ways.



Read more »

Non User