3. ???? ??
? ????? ???? ?? ??? ????.
C ??? ???? ??~~~ ???
C C ? ??, ???(=), ???(if), ???(for) ???
C ???? ?? ?? ???? ?? ? ? ?? ?? ??
4. ?? ?? ??
? SWI Prolog for Windows
C http://www.swi-prolog.org
C ??? ????.
? ??? ??? ??
C http://en.wikipedia.org/wiki/Comparison_of_Prolog_implementatio
ns
5. ???? ??
? prologue?
C ???! Prolog. Programming in Logic ? ??
? ?? ??
C ????? Prolog ? ?? ????? ??? ? ?? ?? ??
C ???? ????? ????
? ???
C Symbolic Programming
C Declarative Programming
C Logic Programming
? ?? ???? ? ????.
6. ???? ??
? Symbolic Programming
C vs. Numeric Computation
C ????? ??? ? ???? ??? ?? ??. ??? ??? ?? ??
C ?? ?? ?? ???? ?? ???? ???? ?? ?? ???? ??
? ??????? ??? ? ???? ??? ????
? Declarative Programming
C vs. Procedural Programming
C ???? ??? ???? ?? ????? ??? ??????, ?? ?
?? ?? ?? ?? ?? ??? ???? ???, ????? ??? ?
? ??? ? ?? ??? ??? ?? ?? ? ??
? Logic Programming
C vs. Functional Programming
C ? ???, ??? ????? ??? ????
7. ???? ????
? ???? ?? ???? ???? ?,
pam tom
? ?? ??? ?? ?? ????
????? ??? ??
C bob ? ????
C pat ? ????? bob liz
C ... ? ??????
C ... ? ????
C ... ? ???? ann pat
C ... ? ????
C ... ? ????
jim
8. ???? ????
? ???? #1
parent(pam,bob). % pam is parent of bob. pam tom
parent(tom,bob).
parent(tom,liz).
parent(bob,ann). bob liz
parent(bob,pat).
parent(pat,jim).
ann pat
? ???
?- parent(bob,pat).
?- parent(liz,pat). jim
?- parent(tom,ben).
?- parent(X,liz).
9. ???? ?? ??
? clause
C ???? ???.
C parent(pam,bob). % parent ? relation ??? ??.
? atom
C ???? ??
C parent, pam, bob
? variable
C ???? ??
C X, Y
? goals
C ???? ??
C ?? ??? clause ? ???? goal? ???? ?? ???.
10. ???? ????
? ???? #2
C female(pam). % pam is female. pam tom
C male(tom).
C male(bob).
C female(liz). bob liz
C female(ann).
C female(pat).
C male(jim). ann pat
C offstring(X,Y) :- parent(Y,X).
% If Y is parent of X, X is offspring of Y.
jim
11. ???? ?? ??
? rule
C offspring(X,Y) :- parent(Y,X).
C 'head' :- 'body'.
C P :- Q, R. % If Q and R then P.
C P :- Q; R. % If Q or R, then P.
12. ???? ????
? ???? #3
C mother(X,Y) :- pam tom
parent(X,Y), female(X).
C grandparent(X,Z) :-
parent(X,Y), parent(Y,Z). bob liz
C sister(X,Y) :-
parent(Z,X),
parent(Z,Y), ann pat
female(X).
jim
13. ???? ????
? ???? #4
C predecessor(X,Z) :-
parent(X,Z).
C predecessor(X,Z) :-
parent(X,Y),
predecessor(Y,Z).
C haschid(X) :- parent( X, _ ).
14. ???? ?? ??
? List
C [ ]
C [ A ] = .( A, [] )
C [ A, B, C ] = .( A, .( B, .( C, [] ) ) )
C [ Head | Tail ]
C [ A, B, C ] = [ A | [ B, C ] ] = [ A, B | [C] ]
15. ????? ??
? Facts
C 5?? ?? ?? ??? ?? ??
C ? ??? ?? ??? ??? ??
C ? ????? ?? ???? ???, ?? ??? ??, ?? ?????
???
? Details
C ???? ?? ?? ??
C ????? ?? ???
C ????? ??? ???
C ???? ??? ?? ??? ??
C ??? ??? ??? ???
C ?? ??? ?? ??? ?? ???
C ???? ??? ?? ??? ???
16. ????? ??
? Details
C ???? ?? ??? ??? ???
C ?????? ??? ?? ??
C ??? ??? ??? ??? ???? ??? ?? ??? ??
C ?? ??? ??? ?? ??? ??? ?? ??? ??
C ????? ??? ??? ??? ??? ???
C ???? ??? ??? ???
C ?????? ???? ??? ??
C ??? ??? ??? ??? ?? ??? ?? ??? ??
? ??. ???? ??? ??? ?????
C ???...
17. ????? ??
? ??? ??
C house( Color, Nationality, Beverage, Cigarette, Pet ).
C [ House1, House2, ... , House5 ]
? Relation
C member( Item, [ Item | _ ] ).
C member( Item, [ _ | Rest ] ) :- member( Item, Rest).
C order( A, B, [ A, B | _ ] ).
C order( A, B, [ _ | Tail ] ) :- order( A, B, Tail ).
C near( A, B, List ) :- order( A, B, List) ; order( B, A, List ).