Professional Documents
Culture Documents
ภาษาโปรล็อก
ภาษาโปรล็อก
(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
(Closed world assumption)
( )
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).
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!