CIS Logo SVC Logo

   Computing & Information Systems
   Department

 

Schoology Facebook        Search CIS Site      Tutorials

Prolog


This Web page provides access to some example Prolog programs that run under yap (yet another prolog) on the Linux server. For more information on yap, see the Online Reference Manual.

Example of Usage


Those with accounts on the CIS Linux server can copy these examples from /www/carlsond/prolog. For example, to copy the list.pro example to your current directory you could use the following command:
cp /www/carlsond/prolog/list.pro .
Note the period. It represents your current directory and is NOT optional (unlike in DOS). If you simply want to copy all of the Prolog examples to your current directory you could do so as follows. Note that the * matches all files in the given directory.
cp /www/carlsond/prolog/* .
To run a Prolog program, you first start yap with the yap command at the Linux command prompt. Then consult the desired Prolog source file and give the desired goal. (Read the comments in each program to see what an appropriate goal might be for that program.) Here is an example, where it is assumed that the Prolog source code is in a file called ancestor.pro and that the desired goal is ancestor(X, Y).
consult('ancestor.pro').
ancestor(X, Y).
To exit from yap, press CTRL c and then enter e.

Another Example of Usage


As another example, let's use the tictac.pro example program. Copy it to your current directory as follows, being careful to include that final period (which stands for the current directory).
cp /www/carlsond/prolog/tictac.pro .
To run this Prolog program, you first start yap with the yap command at the Linux command prompt. Then consult the Prolog source file as follows.
consult('tictac.pro').
Next, give the appropriate goal, followed by a period. For the tictac.pro game, the goal is go, so you would enter:
go.
Follow the onscreen directions for playing tic-tac-toe.

To exit from yap, press CTRL c and then enter e to exit. Don't forget to exit from Linux as well, by entering the command exit.

Example Prolog Programs and Other Examples

Instructor: Br. David Carlson



Author: Br. David Carlson
Last updated: February 20, 2012
Disclaimer