pl10ch16 Logical Programming
pl10ch16 Logical Programming
Logic Programming
Languages
Chapter 16 Topics
• Introduction
• A Brief Introduction to Predicate Calculus
• Predicate Calculus and Proving Theorems
• An Overview of Logic Programming
• The Origins of Prolog
• The Basic Elements of Prolog
• Deficiencies of Prolog
• Applications of Logic Programming
negation a not a
disjunction ab a or b
• Declarative semantics
– There is a simple way to determine the
meaning of each statement
– Simpler than the semantics of imperative
languages
• Programming is nonprocedural
– Programs do not state now a result is to be
computed, but rather the form of the result
ancestor(mary,shelley):- mother(mary,shelley).
trace.
likes(jake, X), likes(darcie, X).
(1) 1 Call: likes(jake, _0)?
(1) 1 Exit: likes(jake, chocolate)
(2) 1 Call: likes(darcie, chocolate)?
(2) 1 Fail: likes(darcie, chocolate)
(1) 1 Redo: likes(jake, _0)?
(1) 1 Exit: likes(jake, apricots)
(3) 1 Call: likes(darcie, apricots)?
(3) 1 Exit: likes(darcie, apricots)
X = apricots
reverse([], []).
reverse([Head | Tail], List) :-
reverse (Tail, Result),
append (Result, [Head], List).