Using Prolog on Unix

  On cs26, type ``sicstus''
  On cs12 or cs13, type ``prolog''
  
  To load a file, type

	| ?- [file].

  Note: A .pl extension will be added if necessary.  You may need
  to quote the filename---it must be a Prolog atom.

  To quit from Prolog, use halt/0 or type EOF (^D) at the
  prompt.

Debugging

You can

  Look at each clause as it is selected (trace/0,
    creap)
  Look only at particular predicates ((spy)/1),
    skip)
  Look at the call stack (goals)
  Retry an earlier goal (retry)
  Break out into another ``top-level''
  

Debugger ``ports''

  [Call] Predicate has been called
  [Exit] Predicate succeeded
  [Redo] Fail occured later on; try alternative solutions
  [Fail] Predicate failed
  
  Quintus Prolog will also tell you which clause is being tested.

  If you run MacX, try ``qui''!


``Advice''

  Available only under Quintus Prolog.

  Put your own tests on a call, exit, redo or fail port.

  
:- add_advice( mypred(A,B), call,
               (bad_data(A,B),
                spy mypred/2) ).
  

  Can use used for specifying pre/post conditions on all predicates.

  Turn on advice checking for all/some predicates

  
     ?- check_advice( mypred/4 ).

     ?- check_advice.
  

The Greek Gods

This is a simple Prolog program that you can trace with the debugger. Compare the length of the trace on each of the grandfather/2 predicates.

The Greek gods family tree looks like this:

parent(uranus, cronus).
parent(gaea,   cronus).
parent(gaea,   rhea).
parent(rhea,   zeus).
parent(cronus, zeus).
parent(rhea,   hera).
parent(cronus, hera).
parent(cronus, hades).
parent(rhea,   hades).
parent(cronus, hestia).
parent(rhea,   hestia).
parent(zeus,   hermes).
parent(maia,   hermes).
parent(zeus,   athena).
parent(zeus,   ares).
parent(hera,   ares).
parent(zeus,   hephaestus).
parent(hera,   hephaestus).
parent(zeus,   apollo).
parent(leto,   apollo).
parent(zeus,   artemis).
parent(leto,   artemis).
parent(semele, dionysius).
parent(aphrodite, harmonia).
parent(ares,   harmonia).
parent(harmonia, semele).
parent(demeter, persephone).

female(gaea).
female(rhea).
female(hera).
female(hestia).
female(demeter).
female(athena).
female(metis).
female(maia).
female(persephone).
female(aphrodite).
female(artemis).
female(leto).

male(uranus).
male(cronus).
male(zeus).
male(hades).
male(hermes).
male(apollo).
male(dionysius).
male(hephaestus).
male(poseidon).
The grandfather/2 predicate is defined as

grandfather(GrandPop, Kid) :-
	parent(GrandPop, Person),
	parent(Person, Kid),
	male(GrandPop).
You can reorder the goals in the body of the grandfather/2 clause in any way you like. The answers it produces will remain the same, but the time it takes to derive the answers can change dramatically.