Matteo Pradella
DEI, PoliMi
May 2012
Matteo Pradella (DEI, PoliMi)
Principles of Programming Languages, 3
May 2012
1 / 54
1
Logic Programming: Prolog
2
Managing nondeterminism
3
The Prolog Language
Matteo Pradella (DEI, PoliMi)
Principles of Programming Languages, 3
May 2012
2 / 54
Introduction to Prolog
Created around 1972 by Alain Colmerauer with Philippe Roussel, based on Robert Kowalski’s procedural interpretation of Horn clauses. decidable subset: Datalog, a query and rule language for deductive databases its failure as a mainstream language traditionally due to the following: Prolog usage in Fifth Generation Computer Systems project (FGCS) FCGS was an initiative by Japan’s Ministry of International Trade and Industry, begun in 1982, to create a "fifth generation computer"
Matteo Pradella (DEI, PoliMi)
Principles of Programming Languages, 3
May 2012
2 / 54
Prolog in the real world
Prolog is not used much nowadays still, for some activities it can be very useful - probably it was just a bad idea to use it as a system programming language. There are implementations usable for parts of the logic of complex applications e.g. written in Java first of all: rapid prototyping. E.g. Prolog was used at Ericsson for implementing the first Erlang interpreter other usages: some academic intrusion detection systems; event handling middlewares; some Nokia phones with the defunct MeeGoo (namely N900, N950, and N9): the policy engine’s rules switching part is written in Prolog and drives an important part of the handsets’ functionality
Matteo Pradella (DEI, PoliMi)
Principles of Programming Languages, 3
May 2012
3 / 54
Prolog and logic: Horn clauses
in general, a logic program has the following form: ∀X1 . . . Xm i i i i φ i ⇐ θ1 ∧ θ2 ∧ . . . ∧ θn
note that φ ⇐ (θ1 ∨ θ2 ) ∧ θ3 is equivalent to (φ ⇐ θ ∧ θ3 ) ∧ (θ ⇐ θ1 ) ∧ (θ ⇐ θ2 ) we start from a