1. Prolog Programming Language
CSE 337
Concepts of Programming Languages
Qassim University
College of Computer –IT department
Ms.Sadaf Ambreen Abbasi.
Reham AL blihed
Muna AL rajhi
1
2. Outline
• About Prolog programming language
• Simple idea of prolog program
• Prolog Syntax
• General purpose arithmetic
2
3. About prolog programming language
•Prolog
• Prolog is one of the most widely used programming languages in artificial
intelligence research.
• It is a declarative programming language unlike most common programming
languages.
3
4. Simple Idea about Prolog Program
• Prolog programs specify relationships among objects and
properties of objects.
4
PrologEnglish
father(ibrahim,reham).Ibrahim is the father of Reham.
eats(ibrahim,pizza).Ibrahim eats pizza.
happy(muna).Muna is happy.
5. Prolog Syntax
• Terms
• Terms are of four kinds: atoms, numbers, variables, and compound terms.
• Example atom:
• Example variables:
• Example compound term:
5
elephant, b, abcXYZ, x_123
X, Elephant, _
is_bigger(horse, X), f(g(X, _), 7),
6. Prolog Syntax
• Clauses and Queries
Clauses Facts & Rules
A fact is a predicate followed by a full stop.
Example:
A rule consists of a head and a body .Head and body are separated by the sign :-
Example:
Queries
it is a sequence of predicates separated by commas and terminated by a full stop.
Example:
6
bigger(whale, _).
Head :- Body.
is_smaller(X, Y) :- is_bigger(Y, X).
aunt(Aunt, Child) :-
sister(Aunt, Parent),
parent(Parent, Child).
?- weather(City,summer), temp(City,40).
8. General purpose arithmetic
• The is-Operator for Arithmetic Evaluation
• The expression in the right of the is-Operator is evaluated and bound to
the left hand argument.
• = does not cause evaluation of its arguments:
• Example:
8
9. Lists in Prolog Programming language
• List contain of head and tail and separated by bar sign | (bar).
• Example:
• Example:
9