Prologue tutorial: Writing a set of facts

After installing SWI-Prolog or GNU Prolog, you optionally log in by clicking the icon on the desktop, which opens an interactive console. Then you can enter facts, rules and questions. We will leave the system by entering:

?- halt.  

Note that any command or line of code ends with a period in Prolog.
The first thing to do in the program is to state the facts.

As the human mind thinks, using references, words representing things, the prologue uses references before adding relationships to them. These references and their relationships are called "facts ."

Example of facts:

alyssa.
fille(alyssa).
fille(kiera).

There are no uppercase initials with names because it's only for variables, which we'll see below. But you can write:

fille('Alyssa').
fille('Kiera'). 

Add a fact to the program space, link or relationship, as you just did, claims their existence. Then you can ask if something is true.

But earlier, in order not to enter the same data in each session, these facts will be placed in the original .pl extension file, such as faits.pl.

The following command in the prolog console:

consult(faits.pl)

loads the contents of this file into memory and compiles it.

You can then query the system by entering queries. Exempli gratia:

?- fille('Kiera').

The system says yes, because this fact is well registered.

If you print:

?- fille('Tom').

He will answer: "No."

The prologue variable begins with a capital letter or may consist of a simple capital letter of type "X." If you ask a system with a variable rather than a reference, it will "unify" the variable with all the facts that are checked for a given relation. Exempli gratia:

?- fille(X).

The console will show:

X = 'Alyssa' ?

and will wait for you to click on the space bar to get the next line. Then she will show:

X = 'Kiera'

Facts can be used in rules to form knowledge with which more complex tasks can be solved.

  1. Prologue language.
  2. Prologue textbook: A set of facts is recorded.
  3. Prologue textbook: The problem is set out in the form of rules
  4. .
  5. Demo Prologue: Looking for an apartment
  6. .