Prolog


Introduction

1 Presentation of Prolog
  1.1 What is a Prolog program
      1.1.1 The Program
      1.1.2 The Query

2 The Facts
  2.1 Simple facts
  2.2 Facts with arguments
  2.3 How to query

3 Variables and Unification
  3.1 Simple unifications
  3.2 Variables unification example

4 Rules
  4.1 Rules
  4.2 How to add a rule with a program
      4.2.1 The instructions
      4.2.2 Example

5 Backtracking
  5.1 Fail
  5.2 Cut
  5.3 Not

6 Recursion
  6.1 What is recursion
  6.2 Examples of Recursion
      6.2.1 Example of the ancestors
      6.2.2 Factorial

7 Lists
  7.1 What is a list in Prolog
  7.2 How to manipulate list

8 Others Elements of Prolog
  8.1 Operators
  8.2 Arithmetic

9 Input and Output
  9.1 Input Output commands
  9.2 Read and Write
  9.3 Examples
      9.3.1 Calculating the cube of an integer
      9.3.2 Treating the terms of a file
      9.3.3 ASCII characters
      9.3.4 Using Another Program

10 SWI-Prolog
  10.1 What is SWI-Prolog
  10.2 Author
  10.3 Platforms
  10.4 FTP Sites


Appendix

A Meta Logical Constructs

B Input and Output
  B.1 input
  B.2 Output

C Some Others usefull predicats
  C.1 True
  C.2 Repeat
  C.3 Call
  C.4 Setof
  C.5 Bagof

D Comparison Operators
  D.1 Arithmetic Comparison Operators
  D.2 Term Comparison


This Report in LaTeX
About us
Links

C   Some others usefull predicates

C.1   True

The goal True/0 always succeeds.
     father(jim,fred).
is in fact equivalent to :
     father=(jim,fred) :- true.

C.2   repeat

The goal repeat/0 is used to do a loop. The predicate in witch it is used is repated until every goal succeeds. Example :
     test :- repeat, 
             write('Please enter a number'), 
             read(X), 
             (X=:=42).
In this example the program will ask you to enter a number until you enter 42.

C.3   Call

This predicate is used to launch another predicat. For example call(p) will run p.
Example :
     call(write((``Hello World!'',nl))).
Note that we can't write call(write('Hello World'),nl). because the predicate call/2 is not avaible in every Prolog.

C.4   Setof

setof/3 can be usefull if you want to find all the solutions of a predicate. For example if we have this database :
     knows(jim,fred).

     knows(alf,bert).
If we want to find all the solutions of knows(X,Y). we can enter :
     setof([X,Y],knows(X,Y),Z).
     Z = [[jim,fred],[alf,bert]]

C.5   bagof

Bagof/3 is simmillar to setof/3. The difference is that bageof/3 leaves all repeated solutions while setof/3 removes them.




-
Comparison Operators -->