Encyclopedia > Prolog programming language

  Article Content


Redirected from Prolog programming language

Prolog is a leading logical programming language. It was created by Alain Colmerauer[?] around 1970s. It was an attempt to make a programming language that enables to express logic instead of carefully specifing instructions on the computer.


Prolog is based on predicate calculus (more precisely first-order predicate calculus; however it is restricted to allow only Horn clauses[?]. Fundamental concepts are unification, tail recursion and backtracking.

Table of contents

Data types



The text constants are introduced by means of atoms. An atom is a sequence consisting of letters, numbers and underscore, 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).


Most Prolog implementations don't differ between integral and real numbers.


Variable is denoted by a string consisting of letters, numbers and underscore characters, which begins with a 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.

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





  1. atom [] is an empty list


  • Prepending single element: [abc | L1]







 ?- cat(tom).

 ?- cat(X).
      X = tom;





Some predicates are built in into the language, and alow a Prolog program to perform routine activities (such as input/output, using graphics and otherwise communicating with the operating system). For example, the predicate write can be used for output to the screen. Thus,


will display the word 'Hello' on the screen.

Rules The second type of statements in Prolog is rules. An example of a rule is

 light(on) :- switch(on). 

The ":-" means "if"; this rule means power(on) is true if switch(on) is true. Rules can also make use of variables; variables begin with capital letters while constants begin with lower case letters. For example,


This means "if someone is a parent of someone and he's male, he is a father". The ancedent and consequent are in reverse order to that normally found in logic. Furthermore, rules can only have a single predicate as a consequent. It is possible to place multiple predicates in a consequent, joined with conjunction, for example:

 a,b,c :- d.

which is simply equivalent to three separate rules:

 a :- d. 
 b :- d. 
 c :- d.

What is not allowed is rules like

 a;b :- c.





  Search Encyclopedia

Search over one million articles, find something about almost anything!
  Featured Article
Hip bone

... bone. The pelvis is symmetrical and each side is actually made up of three separate bones - the ilium[?], ischium[?], and pubis[?]. These three bones fus ...