Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

(: Prolog)

PROgrammation en LOGique (logic programming) Alain Colmerauer ..


1972

(computational
linguistics)
( )

(fifth generation computer systems project - FGCS)
(Kernel Language)
(predicate calculus)
(first-order predicate calculus) (Horn
clause)
(first-order resolution) (unification),
(tail recursion), (backtracking)

(atom)
(underscores)
(') '+' +


(pattern)

(anonymous variable) (_)


(term) (head)
(functor) () (arity)
/

( '.'/2)
[]
T H '.'(H,T)
(H) (T tail)
[1,2,3] '.'(1, '.'(2, 3)) [H|T]
'.'


: [abc, 1, f(x), Y, g(A,rst)]
: [abc | L1]
: [abc, 1, f(x) | L2]
: '.'(abc, '.'(1, '.'(f(x), '.'(Y, '.'(g(A,rst), [])))))



(procedural langugage)
(facts) (rules) (queries)
(predicate)

cat(tom).
cat tom
?- cat(tom).
yes.
?- cat(X).
X = tom;
no.


Pat Sally
father(sally,pat).
father(pat,sally).
father pat sally sally pat



father(pat,sally).
father(jessica,james).
( /
) write

write('Hello').
Hello

(rules)
light(on) :- switch(on).
":-" "" light(on) switch(on)

father(X,Y) :- parent(X,Y), male(X).
" " ( ","
"")

a,b,c :- d.

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

a;b :- c.
" c a b" ( ";" " ")




sibling(X,Y) :- parent(Z,X), parent(Z,Y).
father(X,Y) :- parent(X,Y), male(X).
mother(X,Y) :- parent(X,Y), female(X).
parent(X,Y) :- father(X,Y).
parent(X,Y) :- mother(X,Y).
mother(trude, sally).
father(tom, sally).
father(tom, erica).
father(mike, tom).
male(tom).
female(trude).
male(mike).

?- sibling(sally, erica).
yes.
sibling(X,Y) ( ) sally X
erica Y parent(Z,sally) parent(Z,erica)
sally parent(trude,sally) Z trude parent(trude,erica)
Z tom sally erica

mother(X,Y) :- parent(X,Y), female(X).


parent(X,Y) :- father(X,Y).


male(X) :- father(X,_).


(Closed world assumption)


( )

legal(X) :- NOT illegal(X).


illegal X X X legal
(Negation by failure)





elems([],0).
elems([H|T], X) :- elems(T, Y), X is Y + 1.
0
Y+1 Y

gamble(X) :- gotmoney(X).
gamble(X) :- gotcredit(X), NOT gotmoney(X).
gotmoney

gotcredit

gamble(X) :- gotcredit(X), NOT gotmoney(X).
gamble(X) :- gotmoney(X).

(cut
operator -- !)
gamble(X) :- gotmoney(X),!.
gamble(X) :- gotcredit(X), NOT gotmoney(X).

(green cut operator)


gotmoney

gamble(X) :- gotmoney(X),!.
gamble(X) :- gotcredit(X).
(red cut operator)

Turbo Prolog Borland,


Open Prolog (http://www.cs.tcd.ie/open-prolog/)
Ciao Prolog (http://www.clip.dia.fi.upm.es/Software/Ciao)
GNU Prolog (http://gnu-prolog.inria.fr)
YAP Prolog (http://www.ncc.up.pt/~vsc/Yap)
SWI Prolog (http://www.swi-prolog.org)
Visual Prolog (http://www.visual-prolog.com)
SICStus Prolog (http://www.sics.se/sicstus/)
Amzi! Prolog (http://www.amzi.com/)
B-Prolog (http://www.probp.com/)
TuProlog (http://tuprolog.sourceforge.net/)
XSB (http://xsb.sourceforge.net/)
Trinc Prolog (http://www.trinc-prolog.com)
Strawberry Prolog (http://www.dobrev.com/)

OW Prolog

Runnable examples
A prolog interpreter that runs in the browser
Prolog: The ISO standard
Visual Prolog: An evolution of Turbo Prolog developed by Prolog Development Center at Denmark.
Prolog Tutorial
Learn Prolog Now!

You might also like