Prolog

From Citizendium
Revision as of 14:17, 26 November 2008 by imported>Eric Evers
Jump to navigation Jump to search
This article is a stub and thus not approved.
Main Article
Discussion
Definition [?]
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
 
This editable Main Article is under development and subject to a disclaimer.

Prolog is a declarative language, and is a general-purpose programming language. Prolog stands for "programming logic", and is built on the theory of horn clauses. Erlang is a language that shares some syntax with prolog. Prolog is most often used to program artificial intelligence applications such as expert systems. One of the more famous versions of prolog is Quintus Prolog. Other versions of Prolog include SWI-Prolog and GNU Prolog at www.gprolog.org. The classic text for Prolog is: Programming in Prolog by William F. Clocksin (Author), Christopher S. Mellish [1].

Unification

One rather unique ability of prolog is called unification. Unification is a two way syntactic equality over terms(pattern matching) that happens within a prolog clause.

Ref:Roman Barták - Charles University, Prague (CZ) http://ktiml.mff.cuni.cz/~bartak - lecture #3 - pg 2 - Programming with Logic and Constraints. http://kti.mff.cuni.cz/~bartak/ESSLLI2005/files/lecture3.pdf

Two way means that it happens left to right and right to left. Variables on the left are unified with values on the right and variables on the right are unified with values on the left.

For example from gprolog:

 [1,[2,C]] = [A,[2,3]].
 A = 1
 C = 3
 yes

The prior statement would cause A to unify with(equal) 1, and C to unify with(equal) 3. Unification for this example would succeed once with the given values and then fail.

The following is an example of a constraint. An example from gprolog:

 3 = 2 + 1.
 no

The prior statement fails becuase this is a semantic(meaning) match rather than a sytactic(form) match. This is the difference between logic programming and Constraint programming. Erlang only unifies left to right with syntax. Python matches lists of variables but only with specific nested structures from left to right.

Constraints             > Unification > Pattern matching(one way) > variable matching
constraint programming  >   prolog    >    erlang                 > python (specific nesting)

Standard versions

At the Prolog command line we can use:
| ?- print('hello world!').
to produce:
hello world!

See also

References

  1. The classic text for Prolog is: Programming in Prolog by William F. Clocksin (Author), Christopher S. Mellish.