Author(s): Daniel Cabeza, Manuel Carro.
Version: 1.11#222 (2004/5/24, 13:8:7 CEST)
Version of last change: 1.11#3 (2003/4/7, 13:48:19 CEST)
Prolog implementations traditionally implement the concept of dynamic predicates: predicates which can be inspected or modified at run-time, adding or deleting individual clauses. The power of this feature comes at a cost: as new clause bodies can be arbitrarily added to the program, new predicate calls can arise which are not 'visible' at compile-time, thus complicating global analysis and optimization of the code. But it is the case that most of the time what the programmer wants is simply to store data, with the purpose of sharing it between search branches, predicates, or even execution threads. In Ciao the concept of data predicate serves this purpose: a data predicate is a predicate composed exclusively by facts, which can be inspected, and dynamically added or deleted, at run-time. Using data predicates instead of normal dynamic predicates brings benefits in terms of speed, but above all makes the code much easier to analyze automatically and thus allows better optimization.
Also, a special kind of data predicates exists, concurrent predicates, which can be used to communicate/synchronize among different execution threads (see section Low-level concurrency/multithreading primitives).
Data predicates must be declared through a
data/1
declaration. Concurrent data predicates must be declared through a
concurrent/1
declaration.
data_facts
)data_facts
)
asserta_fact(Fact)
Fact
is added to the corresponding
data predicate. The fact becomes the first clause of the predicate concerned.
Meta-predicate with arguments: asserta_fact(fact)
.
Usage:
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
asserta_fact(Fact, Ref)
Same as
asserta_fact/1
, instantiating Ref
to a unique identifier of the asserted fact.
Meta-predicate with arguments: asserta_fact(fact,?)
.
Usage:
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
Ref
is a free variable.
(term_typing:var/1
)
Ref
is a reference of a dynamic or data clause.
(data_facts:reference/1
)
assertz_fact(Fact)
Fact
is added to the corresponding
data predicate. The fact becomes the last clause of the predicate concerned.
Meta-predicate with arguments: assertz_fact(fact)
.
Usage:
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
assertz_fact(Fact, Ref)
Same as
assertz_fact/1
, instantiating Ref
to a unique identifier of the asserted fact.
Meta-predicate with arguments: assertz_fact(fact,?)
.
Usage:
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
Ref
is a free variable.
(term_typing:var/1
)
Ref
is a reference of a dynamic or data clause.
(data_facts:reference/1
)
current_fact(Fact)
Gives on backtracking all the facts defined as data or concurrent which unify with Fact
. It is faster than calling the predicate explicitly, which do invoke the meta-interpreter. If the Fact
has been defined as concurrent and has not been
closed,
current_fact/1
will wait (instead of failing) for more clauses to appear after the last clause of Fact
is returned.
Meta-predicate with arguments: current_fact(fact)
.
Usage:
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
current_fact(Fact, Ref)
Fact
is a fact of a
data predicate and Ref
is its reference identifying it uniquely.
Meta-predicate with arguments: current_fact(fact,?)
.
Usage 1:
Fact
, instantiating Ref
to a unique identifier for each fact.
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
Ref
is a free variable.
(term_typing:var/1
)
Ref
is a reference of a dynamic or data clause.
(data_facts:reference/1
)
Usage 2:
Ref
, unifies Fact
with the fact identified by it.
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
Ref
is a reference of a dynamic or data clause.
(data_facts:reference/1
)
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
retract_fact(Fact)
Unifies Fact
with the first matching fact of a
data predicate, and then erases it. On backtracking successively unifies with and erases new matching facts. If Fact
is declared as
concurrent and is non-
closed,
retract_fact/1
will wait for more clauses or for the closing of the predicate after the last matching clause has been removed.
Meta-predicate with arguments: retract_fact(fact)
.
Usage:
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
retractall_fact(Fact)
Erase all the facts of a
data predicate unifying with Fact
. Even if all facts are removed, the predicate continues to exist.
Meta-predicate with arguments: retractall_fact(fact)
.
Usage:
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
current_fact_nb(Fact)
Behaves as
current_fact/1
but a fact is never waited on even if it is
concurrent and non-closed.
Meta-predicate with arguments: current_fact_nb(fact)
.
Usage:
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
retract_fact_nb(Fact)
Behaves as
retract_fact/1
, but never waits on a fact, even if it has been declared as
concurrent and is non-
closed.
Meta-predicate with arguments: retract_fact_nb(fact)
.
Usage:
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
close_predicate(Pred)
Changes the behavior of the predicate Pred
if it has been declared as a
concurrent predicate: calls to this predicate will fail (instead of wait) if no more clauses of Pred
are available.
Meta-predicate with arguments: close_predicate(fact)
.
Usage:
Pred
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
open_predicate(Pred)
Reverts the behavior of
concurrent predicate Pred
to waiting instead of failing if no more clauses of Pred
are available.
Meta-predicate with arguments: open_predicate(fact)
.
Usage:
Pred
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
set_fact(Fact)
Sets Fact
as the unique fact of the corresponding
data predicate.
Meta-predicate with arguments: set_fact(fact)
.
Usage:
Fact
is a term which represents a goal, i.e., an atom or a structure.
(basic_props:callable/1
)
erase(Ref)
Deletes the clause referenced by Ref
.
Usage:
Ref
is a reference of a dynamic or data clause.
(data_facts:reference/1
)
data_facts
)
Usage: :- data Predicates
.
Predicates
as a
data predicate. If a predicate is defined data in a file, it must be defined data in every file containing clauses for that predicate. The directive should precede all clauses of the affected predicates. This directive is defined as a prefix operator in the compiler.
Predicates
is a sequence or list of predname
s.
(basic_props:sequence_or_list/2
)
Usage: :- concurrent Predicates
.
Predicates
as a
concurrent predicate. If a predicate is defined concurrent in a file, it must be defined concurrent in every file containing clauses for that predicate. The directive should precede all clauses of the affected predicates. This directive is defined as a prefix operator in the compiler.
Predicates
is a sequence or list of predname
s.
(basic_props:sequence_or_list/2
)
Usage: reference(R)
R
is a reference of a dynamic or data clause.
Go to the first, previous, next, last section, table of contents.