Math 156
Discrete Mathematics for Computer Science
Fall 1999

Intro to Prolog

Toy Prolog Interpreter

The Toy Prolog interpreter (Copyright © L. Allison / 1995-1996) can be run through the wwweb. There are very tight limits set on the size and running time of programs that can be run in this way.

More information about the Toy Prolog interpreter can be found at

http://www.cs.monash.edu.au/~lloyd/tildeLogic/Prolog.toy/Ch/index.html.

Example 1

Here is a short example:

Press 'Run' and see what happens.

So what's going on here?

The main ingredients of ToyProlog

Ingredient Syntax Rules Example(s)
Predicates begin with lower case letter
followed by parenthesized parameter list
prof(), inClass(), teaches(), isStudent()
Constants begin with lower case letter pruim, math221, math156, joeSchmo, janeDoe
Variables begin with capital letter P, Stud, S
Logical operators <=, and, not Examples are obvious, but see below for restrictions on <=. Notice, there is no "or".
Implied quantifiers Invisible See below for explanation

Note: all names (of variables, constants, and predicates) are case sensitive, but are internally truncated at 10 characters.

Prolog lines

There are three kinds of lines in a prolog program. (Note that each is ended by a period.)

Using just facts and a query, we can can already do some interesting things.

Example 2


Exercises

Write Prolog Queries that do the following:
  1. Determine whether JoeSmo is in math 156.
  2. List all students in the database.
  3. List all students in math156.
  4. List all students in more than one class.