Language Reference/Clauses

Clauses Sections
A clauses section consists of a set of clauses. The clauses section contains implementations of predicates or initial values of facts.

A single clause section can have clauses for several predicates and facts. On the other hand, all clauses for one predicate/fact (the same name and arity) must be grouped together in one clauses section and without intervening clauses of other predicates/facts.

 : clauses -dot-term-list-opt

See also in Monitors.

Clauses
Clauses are used to define predicates. A single predicate is defined by a set of clauses. Each clause is executed in turn until one of them succeeds, or there is no more clauses left to execute. If no clause succeeds the predicate fails.

If a clause succeeds and there are more relevant clauses in a predicate left, the program control can later backtrack to the clauses of this predicate to search for other solutions.

Thus, a predicate can fail, succeed, and even succeed multiple times.

Each clause has a head and optionally a body.

When a predicate is called the clauses are tried in turn (from top to bottom). For each clause the head is unified with the arguments from the call. If this unification succeeds then the body of the clause (if such one exist) is executed. The clause succeeds if the match of the head succeeds and the body succeeds. Otherwise it fails.

A clause consists of a head and an optional body.

 :  -opt -opt.

 :  ( -comma-sep-list-opt )

 : = 

 : :- <Term>

See also in Monitors.

Goal Section
The goal</vp> section is the entry to a program. When the program starts it executes the goal</vp>, when the goal</vp> is executed, the program exits.

<GoalSection> : goal <Term>.

The goal</vp> section consists of a clause body. The goal</vp> section defines its own scope, therefore all invocations should contain class qualifications.

The goal must have procedure</vp> mode.