(redirected from Prolog programming language)

[Home]Prolog

HomePage | Recent Changes | Preferences

Prolog is a logical programming language. It is an acronym for PROgramming in LOGic. It was created by [Alain Colmeraurer]? in 1973. Prolog is used in many artificial intelligence programs.

Prolog is based on first-order predicate calculus; however it is restricted to allow only [horn clauses]?.

Programming in Prolog is very different from programming in a procedural language. In Prolog you supply a database of facts and rules; you can then perform queries on the database. The basic unit of Prolog is the predicate. A predicate consists of a head and a number of arguments. For example: father(sally,pat). Here 'father' is the head, and 'sally' and 'pat are the arguments. A predicate can be used to express some fact the program knows about the world. In this case it must be given an interpretation by the programmer. The most natural interpretation for father(sally,pat) is "the father of sally is pat". However, the programmer could have just as easily written father(pat,sally), interpreted as "pat is the father of sally". Prolog has no idea what those statements mean; all Prolog is doing is manipulating symbols according to rules. Thus the programmer may choose either representation of the fact that "pat is the father of sally", so long as he or she uses the same interpretation throughout the program (i.e. doesn't have father(pat,sally), and father(jessica,james)).

Some predicates do more than express facts; they can also have side-effects. For example, the predicate write('Hello') displays the word 'Hello' on the screen.

Prolog databases can also contain rules. An example of a rule is power(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 father(X,Y) :- parent(X,Y),male(Y). This means "for all X, Y, if parent(X,Y) and male(Y), then father(X,Y)." 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"; but this is simply equivalent to three separate rules "a :- d. b :- d. c :- d." What is not allowed is rules like "a;b :- c", that is "if c then a or b". This is because of the restriction to Horn clauses.


HomePage | Recent Changes | Preferences
This page is read-only | View other revisions
Last edited August 17, 2001 7:53 am by 216.60.221.xxx (diff)
Search: