Docsity

SWI-PROLOG for Prolog Programming - Lab | CECS 424, Lab Reports of Computer Science

Toggle sidebar
bg1
CECS 424 Lab on 12/1/05
Do the following:
1. Start SWI-PROLOG for Prolog programming.
2. Learn to program in Prolog.
1. Type the following lines and save into a file named relations in your 424/Prolog subdirectory:
/* ~/424/Prolog/relations */
parent(kim,holly).
parent(margaret,kim).
parent(margaret,kent).
parent(esther,margaret).
parent(herbert,margaret).
parent(herbert,jean).
grandparent(GP,GC) :-
parent(GP,P), parent(P,GC).
greatgrandparent(GGP,GGC) :-
grandparent(GGP,P), parent(P,GGC).
ancestor(X,Y) :- parent(X,Y).
ancestor(X,Y) :-
parent(Z,Y), ancestor(X,Z).
male(kent).
male(herbert).
female(kim).
female(holly).
female(margaret).
female(esther).
female(jean).
grandfather(X,Y) :-
parent(X,Z), parent(Z,Y), male(X).
grandmother(X,Y) :-
parent(X,Z), parent(Z,Y), female(X).
Start SWI-PROLOG, and type each of the following lines and see what happens. Note that Prolog is
case sensitive, and a term cannot have embedded blanks.
consult(relations).
ancestor(kim,holly).
grandparent(Margaret,holly).
grandparent(X,kim).
ancestor(esther,Y).
greatgrandparent(X,holly).
greatgrandparent(X,kim).
grandmother(Margaret,Y).
grandfather(X,Y).
Assignment 7 (20 points) : Do the exercise problems 10, and 18-21 in Chapter 19.
Due Thursday, 12/8/05, in Lab.
pf2

Partial preview of the text

Download SWI-PROLOG for Prolog Programming - Lab | CECS 424 and more Lab Reports Computer Science in PDF only on Docsity!

CECS 424 Lab on 12/1/

Do the following:

  1. Start SWI-PROLOG for Prolog programming.
  2. Learn to program in Prolog. 1. Type the following lines and save into a file named relations in your 424/Prolog subdirectory: /* ~/424/Prolog/relations */ parent(kim,holly). parent(margaret,kim). parent(margaret,kent). parent(esther,margaret). parent(herbert,margaret). parent(herbert,jean). grandparent(GP,GC) :- parent(GP,P), parent(P,GC). greatgrandparent(GGP,GGC) :- grandparent(GGP,P), parent(P,GGC). ancestor(X,Y) :- parent(X,Y). ancestor(X,Y) :- parent(Z,Y), ancestor(X,Z). male(kent). male(herbert). female(kim). female(holly). female(margaret). female(esther). female(jean). grandfather(X,Y) :- parent(X,Z), parent(Z,Y), male(X). grandmother(X,Y) :- parent(X,Z), parent(Z,Y), female(X). Start SWI-PROLOG, and type each of the following lines and see what happens. Note that Prolog is case sensitive, and a term cannot have embedded blanks. consult(relations). ancestor(kim,holly). grandparent(Margaret,holly). grandparent(X,kim). ancestor(esther,Y). greatgrandparent(X,holly). greatgrandparent(X,kim). grandmother(Margaret,Y). grandfather(X,Y). Assignment 7 (20 points) : Do the exercise problems 10, and 18-21 in Chapter 19. Due Thursday, 12/8/05, in Lab.

HOWTO for Running Prolog (pl) Interactive System

1. The Prolog interpreter pl is installed in /usr/local/pl-4.0.10/src on our Linux system. To run pl , you will have to add the Prolog interpreter to your PATH, which can be achieved by following the instructions below. a. Add the following two lines to your. profile (e.g., add to the end of the file). The first line tells where pl is located and the second line adds the correct directory to your PATH. export PLROOT=/usr/local/pl-4.0.10/src PATH="$PATH:$PLROOT" b. Save your. profile. Logout and log back in to Linux again. 2. To start Prolog, do the following. These instructions assume that you have already performed the necessary setup to use sh , bash , or the ksh (they will not work on csh ). If not, follow the HOWTO Start bash procedure below for setting up and using bash. a. Type the following line to start bash: % exec –bash # % here is taken as the csh prompt. May be # different on your Linux system. b. Create a prolog subdirectory within your 424 subdirectory for all your Prolog programs. To start Prolog, type the following (it’s PL in lower case, not P-one): $ pl # Again $ is taken as the bash prompt. May be # different on your Linux system.