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

B   Input and Output

B.1   input

To read in a file in Prolog the following commands are used :

see(Filename).
Open for output the file Filename.

seeing(File)
When File is a variable, File is unified with the name of the input file.

get0(C).
Reads one character from the input and unifies C to it ASCII code.

get(C).
Reads non blank chars.

seen.
Close the current input file.

consult(File).
(also [File]. in some Prologs) When File is a filemame, loads the Prolog code contained in file in the database.

reconsult(file).
Reload the the Prolog code contained in file in the database.

B.2   Output

To write in a file the following commands are used :

tell(Fillename)
Open the file for output.

telling(File).
File is unified to the name of the output file.

put(C).
When C an ACSII code Writes the character given by C.

told.
Close the current output file.



-
Some Others usefull predicats -->