Prolog: Difference between revisions
imported>Alexander Wiebel m (→Unification: typo) |
imported>Alexander Wiebel m (→Unification: spaces) |
||
Line 32: | Line 32: | ||
no | no | ||
The prior statement fails because this is a semantic(meaning) match rather than a syntactic(form) match. This is the difference between logic programming and [[Constraint_programming|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. | The prior statement fails because this is a semantic (meaning) match rather than a syntactic (form) match. This is the difference between logic programming and [[Constraint_programming|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 | Constraints > Unification > Pattern matching(one way) > variable matching |
Revision as of 02:56, 28 November 2008
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:
10 = 4 + 6.
no
The prior statement fails because this is a semantic (meaning) match rather than a syntactic (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
- ↑ The classic text for Prolog is: Programming in Prolog by William F. Clocksin (Author), Christopher S. Mellish.