Concepts of Programming Languages
Qassim University
Size: 231.95 KB
Language: en
Added: Mar 06, 2016
Slides: 15 pages
Slide Content
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
Outline About Prolog programming language Simple idea of prolog program Prolog Syntax General purpose arithmetic 2
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
Simple Idea about Prolog Program Prolog programs specify relationships among objects and properties of objects . 4 Prolog English father( ibrahim,reham ). Ibrahim is the father of Reham. eats( ibrahim,pizza ). Ibrahim eats pizza. happy( muna ). Muna is happy.
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),
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).
General Purpose Arithmetic 7 Numeric comparison operator:
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
Lists in Prolog Programming language List contain of head and tail and separated by bar sign | ( bar). Example: Example: 9
Some Built-in Predicates for List Manipulation: Length Sum 10
General Example of prolog personal Information Knowledge Based Queries 11
General Example of prolog Example on testing mark Knowledge Based Queries 12
General Example of prolog Example of prolog program about the Weather Knowledge Based Queries 13
General Example of prolog Maximum of two numbers Knowledge Based Queries 14
General Example of prolog Example: Knowledge Based Queries Example: 15