[FrontPage] [TitleIndex] [WordIndex

October 26

Note for next class: Be sure to look at the problem set before Friday.

Prolog

We are running a prolog query engine. We have to consult a file, and then that file can be queried. There are some built-in commands for prolog.

For example:

-returns yes.

Prolog is case-sensitive. Anything that begins with an uppercase is a variable.

Statements in a file are used as facts and not asked as questions.

[seats]. Loads the file seats.

Seats contains relationships between who is sitting next to whom in class.

Initially, asked next_to( kevin, mike ) but the file returned no, even though Kevin was next to Mike. This is because Lynn typed only one half of the relationship, and prolog has not been told to accept symmetry.

Seats contains assertions, basically adding entries to a database.

next_to( mike, Who). Will find everyone next to mike. next_to( Who, WhoElse). Shows a list of all the relationships.

[user]. Allows command line input instead of using a file. Ctrl + D exits user input mode.

same_table ( X, Y ) :- next_to ( X,Y ) Is the same as writing next_to( X, Y ) implies same_table ( x, y);

same_table( X, Y ) :- next_to ( X, Z ), same_table ( Z, Y ).

The trace command allows you to enter trace mode. To exit trace mode, use notrace.

Things to Know About Prolog:


2013-07-17 10:43