Datalog
CSE 350, Spring 2003

Datalog is a subset of Prolog so obtaining a release of Prolog will allow you to do the Datalog examples in the text book


Obtaining Prolog

There are numerous releases of Prolog, many are free. One free distribution is GNU Prolog. There are source and binary versions available, including Windows and Linux versions. See http://gnu-prolog.inria.fr for more information or just get the Windows setup binary from ftp://ftp.inria.fr/INRIA/Projects/contraintes/gprolog/setup-gprolog-1.2.16.exe. Once you have downloaded it, double click it to start setup. It will create a shortcut in a program group and a desktop icon if you want it to. You may want to change the working directory (where it will look for your datalog programs) by editing the shortcut properties.

GNU Prolog is loaded on the computers in ITEB C27 (the lab says "Unix" on the outside, but the computers are Windows 2000). Also, it can be installed on your Z drive on the learning center computers.  If you load it on your Z drive on one machine, it will be on your Z drive on all of them, in E2 and ITEB learning centers. The Z drive is entirely yours so it stays until you explicitly delete it. It takes ~10 meg. Here is what to do:

Once you have Prolog installed, you'll want the to download at least the sample "college database" (DatalogCollege.txt) from the class handout. You may also want the "student database" (DatalogBook.txt) example from chapter 8 in the textbook; this file contains both facts (data) and queries. You can save them and work with them directly as text files with extension ".txt", but many people prefer to give them an extension of ".p" for Prolog. Either works fine.


Learning how it works

There are on line manuals and tutorials that can give you a "crash course" in Prolog. One very detailed tutorial, available at http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/pt_framer.html, is written for SWI Prolog but is applicable to GNU Prolog as well.

The GNU Prolog web site has a reference manual on line.


Sample session

If you want to work with the DatalogBook.txt file discussed above, here is how a sample session might look. Blank lines have been removed to save space and comments (marked with %%) have been added, but your output should look very similar.

%% When the session begins I load my program, the "singleton variables"
%% warnings just mean I could have been more efficient by using
%% anonymous variables when I don't use their contents.
?- consult('C:/usr/rs/sch/CSE350/Working/DatalogBook.txt').
 
compiling C:\usr\rs\dev\prolog\DatalogTest.txt for byte code...
C:\usr\rs\dev\prolog\DatalogBook.txt:14 warning: singleton variables [Major,Grade1,Grade2] for firstreq/1
C:\usr\rs\dev\prolog\DatalogBook.txt:15 warning: singleton variables [Major] for scndreq/1 C:\usr\rs\dev\prolog\DatalogBook.txt:19 warning: singleton variables [Grade] for hastaken/2
C:\usr\rs\dev\prolog\DatalogBook.txt compiled, 20 lines read - 3638 bytes written, 150 ms
yes
%% End of their report, begin my typing queries.
| ?- firstreq(Name).
Name = 'Jim Jones' ? a
Name = 'Jim Black'
no
%% observe that Prolog only gave me one match,
%% I typed 'a' to get all the rest (just 1 in this case)
| ?- scndreq(Name).
Name = 'Jim Jones' a
Name = 'Jim Black'
(20 ms) no
| ?- scndreq2(Name).
Name = 'Jim Jones' ? a
Name = 'Jim Black'
no
| ?- lacks_cs143(Name).
no
| ?- lacks_cs123(Name).
Name = 'Jim Jones' ? a
Name = 'Jim Black'
yes
%% I'm done, I want to quit
| ?- halt.

Important Notes


This page last updated on 9/29/03