Tutorial On Prolog (Lab) : Text Book: Introduction To Turbo Prolog
Tutorial On Prolog (Lab) : Text Book: Introduction To Turbo Prolog
Chapter 2
Starting of Turbo Prolog
You have a compressed file named Turbo_prolog in web. Please download this file and
unzipped it. The name should be the same. So now you have a directory call
Turbo_Prolog. Open the directory and find the exe file named PROLOG. Click on any
one exe dos version or windows version and you will see the following screen in the
monitor.
Click F5 to get 4 windows in your screen.
If you did not find 4 windows (Editor, Dialog, Message and Trace) clearly then type
Alt+S, then the following screen will be seen. Thereafter, click on the Window size. Then
make changes the size of any window by moving the up-down, left-right key.
The Six Options:
Details of each Option will be given in Chapter 2, Page 14-28.
Chapter 3
How to run a Prolog program
1. F10 to get all windows in screen
2. Goto Edit in menubar and press Enter
3. Write the following codes into the Editor Window
/*Simple test Program */
predicates
likes(symbol,symbol)
clauses
likes(frank,sue).
likes(Harold,ruth).
4. Save this program (Alt+F to go to file Menu Option and then select “write to”
options to save in a specific file name (please give the file name “prog1.pro”).
5. Goto the Run Menubar Option and press Enter
6. (You are now in a Dialog window where you have Goal: ) Write your query there,
let you are going to type
likes (Harold, ruth)
7. After typing the query press enter
8. Your program will execute and give the following result
True
Goal:
1. Facts
2. Domains, Domain types, Predicates, Clauses
3. Adding Comments
4. Using Trace Procedure
a. Open program prog1.pro
b. Change the program as following
/*Simple test Program */
domains
person1, person2=symbol
predicates
likes (person1,person2)
clauses
likes (frank, sue).
likes (Harold, ruth).
c. Save the program at any name and do the same activities that you have
done with prog1.pro (run will all goals)
d. After successfully running write the following commend any place above
domain section
Trace
e. Now again Save and Run this program with any one goal
f. Watch carefully, inside the Trace window and Editor Window …Where
the cursor in Editor Window is and what is written inside the Trace
Window..Try to understand…
g. To traverse the program in each step Press F10 to proceed step by step.
5. Variables
a. Bound and Free Variables
b. Anonymous Variables
After Trace procedure successfully executed, give the following
commends beside Goal:
1. likes(_,ruth)
2. likes (frank,_)
Chapter 4
1. Definitions of Rules and working procedure
Page 58: program write and run
2. Compound facts
3. Unification and Rules of Unification (page 63)
4. not predicate and its uses and problems (page 65)
5. write, writef, writedevice predicates
6. readln, readchar, readint, readreal predicates
7. inkey(Char), keypressed predicates
8. Using Windows , “clearwindow” commend
9. Run program on (page 79)
10. fail predicate
11. Run program on (page 85, 87, 88), find out the difference and why this
differences are occurring.
Your Work:
Write program that will satisfy the following relations
1. For all X and Y, Y is an offspring of X if X is a parent of Y.
2. For all X and Y, X is a parent of Y if Y is an offspring of X.
3. For all X and Y, X is the mother of Y if X is a parent of Y and X is a female.
4. For all X, Y and Z, X is a grandparent of Z if X is a parent of Y and Y is a parent
of Z.
Chapter 5
1. The concept of Recursion
2. program practice and trace page 93 (both).
3. program practice and trace on page 95 (using repeat).
4. Find out the difference of program on page 93 and program on page 95 ( by
forcely stop you may need to use Ctrl+Break ).
5. Rules of Recursion
a. A program must include some method of terminating the recursion loop.
b. Variable binding in a rule or fact applies only to the current layer. When a
copy of the rule or fact in invoked, the variables in the copy are bound
through the process of unification, just as in any other invocation.
c. In most applications, the recursive procedure should do its work on the
way down.
6. Concept of Unwinding
a. Modify your previous program as program in page 98.Carefully watch the
difference.
b. Recursion involves two phases: “winding down” and “unwinding”.
Predicates before recursive call are invoked during winding down.
Predicates after the recursive call are invoked during unwinding.
7. Now modify the login program as like program on page 99, look the difference.
Exercise:
a. Page 100.
b. Write a program that will invoke an input (an integer) and find out the
factorial of that number recursively.
c. Write a program that will invoke two inputs and find out the first seven (7)
Fibonacci numbers from their Fibonacci series.