This is yap.info, produced by makeinfo version 4.6 from yap.tex.

START-INFO-DIR-ENTRY
* Yap: (yap).           YAP Prolog User's Manual.
END-INFO-DIR-ENTRY


File: yap.info,  Node: A Mixed Integer Linear Optimization Example,  Next: Implementation Architecture,  Prev: Compatibility Notes,  Up: CLPQR

A Mixed Integer Linear Optimization Example
===========================================

In this section we are going to exercise our solver a little by the
computation of a small mixed integer optimization problem (MIP) from
miplib, a collection of MIP models, housed at Rice University. Here are
the original comments on the example:

     NAME:         flugpl
     ROWS:         18
     COLUMNS:      18
     INTEGER:      11
     NONZERO:      46
     BEST SOLN:    1201500 (opt)
     LP SOLN:      1167185.73
     SOURCE:       Harvey M. Wagner
                   John W. Gregory (Cray Research)
                   E. Andrew Boyd (Rice University)
     APPLICATION:  airline model
     COMMENTS:     no integer variables are binary

     %
     % from file: library('clpqr/examples/mip')
     %
     example(flugpl, Obj, Vs, Ints, []) :-
       Vs = [ Anm1,Anm2,Anm3,Anm4,Anm5,Anm6,
              Stm1,Stm2,Stm3,Stm4,Stm5,Stm6,
              UE1,UE2,UE3,UE4,UE5,UE6],
       Ints = [Stm6, Stm5, Stm4, Stm3, Stm2,
               Anm6, Anm5, Anm4, Anm3, Anm2, Anm1],
     
       Obj =    2700*Stm1 + 1500*Anm1 + 30*UE1
              + 2700*Stm2 + 1500*Anm2 + 30*UE2
              + 2700*Stm3 + 1500*Anm3 + 30*UE3
              + 2700*Stm4 + 1500*Anm4 + 30*UE4
              + 2700*Stm5 + 1500*Anm5 + 30*UE5
              + 2700*Stm6 + 1500*Anm6 + 30*UE6,
     
       allpos(Vs),
       {  Stm1 = 60, 0.9*Stm1 +1*Anm1 -1*Stm2 = 0,
          0.9*Stm2 +1*Anm2 -1*Stm3 = 0, 0.9*Stm3 +1*Anm3 -1*Stm4 = 0,
          0.9*Stm4 +1*Anm4 -1*Stm5 = 0, 0.9*Stm5 +1*Anm5 -1*Stm6 = 0,
          150*Stm1 -100*Anm1 +1*UE1 >= 8000,
          150*Stm2 -100*Anm2 +1*UE2 >= 9000,
          150*Stm3 -100*Anm3 +1*UE3 >= 8000,
          150*Stm4 -100*Anm4 +1*UE4 >= 10000,
          150*Stm5 -100*Anm5 +1*UE5 >= 9000,
          150*Stm6 -100*Anm6 +1*UE6 >= 12000,
          -20*Stm1 +1*UE1 =< 0, -20*Stm2 +1*UE2 =< 0, -20*Stm3 +1*UE3 =< 0,
          -20*Stm4 +1*UE4 =< 0, -20*Stm5 +1*UE5 =< 0, -20*Stm6 +1*UE6 =< 0,
          Anm1 =< 18, 57 =< Stm2, Stm2 =< 75, Anm2 =< 18,
          57 =< Stm3, Stm3 =< 75, Anm3 =< 18, 57 =< Stm4,
          Stm4 =< 75, Anm4 =< 18, 57 =< Stm5, Stm5 =< 75,
          Anm5 =< 18, 57 =< Stm6, Stm6 =< 75, Anm6 =< 18
        }.
     
       allpos([]).
       allpos([X|Xs]) :- {X >= 0}, allpos(Xs).

   We can first check whether the relaxed problem has indeed the quoted
infimum:

     clp(r) ?- example(flugpl, Obj, _, _, _), inf(Obj, Inf).
     
     Inf = 1167185.7255923203

   Computing the infimum under the additional constraints that STM6,
STM5, STM4, STM3, STM2, ANM6, ANM5, ANM4, ANM3, ANM2, ANM1 assume
integer values at the infimum is computationally harder, but the query
does not change much:

     clp(r) ?- example(flugpl, Obj, _, Ints, _), bb_inf(Ints, Obj, Inf).
     
     Inf = 1201500.0000000005


File: yap.info,  Node: Implementation Architecture,  Next: Fragments and Bits,  Prev: A Mixed Integer Linear Optimization Example,  Up: CLPQR

Implementation Architecture
===========================

The system consists roughly of the following components:
   * A polynomial normal form expression simplification mechanism.

   * A solver for linear equations [Holzbaur 92].

   * A simplex algorithm to decide linear inequalities [Holzbaur 94].


File: yap.info,  Node: Fragments and Bits,  Next: CLPQR Bugs,  Prev: Implementation Architecture,  Up: CLPQR

Fragments and Bits
==================

The internal data structure for rational numbers is `rat(NUM,DEN)'. DEN
is always positive, i.e. the sign of the rational number is the sign of
NUM. Further, NUM and DEN are relative prime. Note that integer N looks
like `rat(N,1)' in this representation. You can control printing of
terms with `portray/1'.

   Partial Evaluation

   Once one has a working solver, it is obvious and attractive to run
the constraints in a clause definition at read time or compile time and
proceed with the answer constraints in place of the original
constraints. This gets you constant folding and in fact the full
algebraic power of the solver applied to the avoidance of computations
at runtime. The mechanism to realize this idea is to use
`call_residue/2' for the expansion of `{}/1'.

   Asserting with Constraints

   If you use the dynamic data base, the clauses you assert might have
constraints on the variables occurring in the clause. This should work
as follows:

     clp(r) ?- {A < 10}, assert(p(A)).
     
     {A < 10.0}
     yes
     
     clp(r) ?- p(X).
     
     {X<10.0}

   YAP currently does not implement this feature.


File: yap.info,  Node: CLPQR Bugs,  Next: CLPQR References,  Prev: Fragments and Bits,  Up: CLPQR

CLPQR bugs
==========

   * The fuzzy comparison of floats is the source for all sorts of
     weirdness. If a result in R surprises you, try to run the program
     in Q before you send me a bug report.

   * The projector for floundered nonlinear relations keeps too many
     variables. Its output is rather unreadable.

   * Disequations are not projected properly.

   * This list is probably incomplete.

   Please send bug reports to `christian@ai.univie.ac.at'.


File: yap.info,  Node: CLPQR References,  Prev: CLPQR Bugs,  Up: CLPQR

CLPQR References
================

[Colmerauer 90] Colmerauer A.: An Introduction to Prolog III,
Communications of the ACM, 33(7), 69-90, 1990.

   [Heintze et al. 87] Heintze N., Jaffar J., Michaylov S., Stuckey P.,
Yap R.: The CLP(R) Programmers Manual, Monash University, Clayton,
Victoria, Australia, Department of Computer Science, 1987.

   [Holzbaur 92] Holzbaur C.: A High-Level Approach to the Realization
of CLP Languages, in Proceedings of the JICSLP92 Post-Conference
Workshop on Constraint Logic Programming Systems, Washington D.C., 1992.

   [Holzbaur 92] Holzbaur C.: Metastructures vs. Attributed Variables in
the Context of Extensible Unification, in Bruynooghe M. & Wirsing
M.(eds.), Programming Language Implementation and Logic Programming,
Springer, LNCS 631, pp.260- 268, 1992.

   [Holzbaur 94] Holzbaur C.: A Specialized, Incremental Solved Form
Algorithm for Systems of Linear Inequalities, Austrian Research
Institute for Artificial Intelligence, Vienna, TR-94-07, 1994.

   [Jaffar & Michaylov 87] Jaffar J., Michaylov S.: Methodology and
Implementation of a CLP System, in Lassez J.L.(ed.), Logic Programming -
Proceedings of the 4th International Conference - Volume 1, MIT Press,
Cambridge, MA, 1987.


File: yap.info,  Node: CHR,  Next: Logtalk,  Prev: CLPQR,  Up: Top

Constraint Handling Rules
*************************

* Menu:

* CHR Copyright::
* CHR Introduction::
* CHR Introductory Examples::
* CHR Library::
* CHR Debugging::
* CHR Programming Hints::
* CHR Constraint Handlers::
* CHR Backward Compatibility::


File: yap.info,  Node: CHR Copyright,  Next: CHR Introduction,  Prev: CHR,  Up: CHR

Copyright
=========

This chapter is Copyright (C) 1996-98 LMU

   LMU (Ludwig-Maximilians-University)
Munich, Germany

   Permission is granted to make and distribute verbatim copies of this
chapter provided the copyright notice and this permission notice are
preserved on all copies.

   Permission is granted to copy and distribute modified versions of
this chapter under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.

   Permission is granted to copy and distribute translations of this
chapter into another language, under the above conditions for modified
versions, except that this permission notice may be stated in a
translation approved by LMU.


File: yap.info,  Node: CHR Introduction,  Next: CHR Introductory Examples,  Prev: CHR Copyright,  Up: CHR

Introduction
============

Experience from real-life applications using constraint-based
programming has shown that typically, one is confronted with a
heterogeneous mix of different types of constraints. To be able to
express constraints as they appear in the application and to write and
combine constraint systems, a special purpose language for writing
constraint systems called "constraint handling rules" (CHR) was
developed.  CHR have been used to encode a wide range of constraint
handlers (solvers), including new domains such as terminological and
temporal reasoning.  Several CHR libraries exist in declarative
languages such as Prolog and LISP, worldwide more than 20 projects use
CHR. You can find more information about CHR at URL:
`http://www.pst.informatik.uni-muenchen.de/personen/fruehwir/chr-intro.html'

   The high-level CHR are an excellent tool for rapid prototyping and
implementation of constraint handlers. The usual abstract formalism to
describe a constraint system, i.e. inference rules, rewrite rules,
sequents, formulas expressing axioms and theorems, can be written as
CHR in a straightforward way.  Starting from this executable
specification, the rules can be refined and adapted to the specifics of
the application.

   The CHR library includes a compiler, which translates CHR programs
into Prolog programs on the fly, and a runtime system, which includes a
stepper for debugging.  Many constraint handlers are provided in the
example directory of the library.

   CHR are essentially a committed-choice language consisting of guarded
rules that rewrite constraints into simpler ones until they are solved.
CHR define both "simplification" of and "propagation" over constraints.
Simplification replaces constraints by simpler constraints while
preserving logical equivalence (e.g.  `X>Y,Y>X <=> fail').  Propagation
adds new constraints which are logically redundant but may cause
further simplification (e.g.  `X>Y,Y>Z ==> X>Z').  Repeatedly applying
CHR incrementally simplifies and finally solves constraints (e.g.
`A>B,B>C,C>A' leads to `fail'.

   With multiple heads and propagation rules, CHR provide two features
which are essential for non-trivial constraint handling.  The
declarative reading of CHR as formulas of first order logic allows one
to reason about their correctness.  On the other hand, regarding CHR as
a rewrite system on logical formulas allows one to reason about their
termination and confluence.

   In case the implementation of CHR disagrees with your expectations
based on this chapter, drop a line to the current maintainer:
`christian@ai.univie.ac.at' (Christian Holzbaur).


File: yap.info,  Node: CHR Introductory Examples,  Next: CHR Library,  Prev: CHR Introduction,  Up: CHR

Introductory Examples
=====================

We define a CHR constraint for less-than-or-equal, `leq', that can
handle variable arguments. This handler can be found in the library as
the file `leq.pl'.  (The code works regardless of options switched on
or off.)
     :- use_module(library(chr)).
     
     handler leq.
     constraints leq/2.
     :- op(500, xfx, leq).
     
     reflexivity  @ X leq Y <=> X=Y | true.
     antisymmetry @ X leq Y , Y leq X <=> X=Y.
     idempotence  @ X leq Y \ X leq Y <=> true.
     transitivity @ X leq Y , Y leq Z ==> X leq Z.

   The CHR specify how `leq' simplifies and propagates as a constraint.
They implement reflexivity, idempotence, antisymmetry and transitivity
in a straightforward way.  CHR `reflexivity' states that `X leq Y'
simplifies to `true', provided it is the case that `X=Y'. This test
forms the (optional) guard of a rule, a precondition on the
applicability of the rule.  Hence, whenever we see a constraint of the
form `A leq A' we can simplify it to `true'.

   The rule `antisymmetry' means that if we find `X leq Y' as well as
`Y leq X' in the constraint store, we can replace it by the logically
equivalent `X=Y'. Note the different use of `X=Y' in the two rules: In
the `reflexivity' rule the equality is a precondition (test) on the
rule, while in the `antisymmetry' rule it is enforced when the rule
fires. (The reflexivity rule could also have been written as
`reflexivity   X leq X <=> true'.)

   The rules `reflexivity' and `antisymmetry' are "simplification CHR".
In such rules, the constraints found are removed when the rule applies
and fires.  The rule `idempotence' is a "simpagation CHR", only the
constraints right of `'\'' will be removed. The rule  says that if we
find `X leq Y' and another `X leq Y' in the constraint store, we can
remove one.

   Finally, the rule `transitivity' states that the conjunction `X leq
Y, Y leq Z' implies `X leq Z'.  Operationally, we add `X leq Z' as
(redundant) constraint, without removing the constraints `X leq Y, Y
leq Z'. This kind of CHR is called "propagation CHR".

   Propagation CHR are useful, as the query `A leq B,C leq A,B leq C'
illustrates: The first two constraints cause CHR `transitivity' to fire
and add `C leq B' to the query. This new constraint together with `B
leq C' matches the head of CHR `antisymmetry', `X leq Y, Y leq X'.  So
the two constraints are replaced by `B=C'. Since `B=C' makes `B' and
`C' equivalent, CHR `antisymmetry' applies to the constraints `A leq B,
C leq A', resulting in `A=B'. The query contains no more CHR
constraints, the simplification stops.  The constraint handler we built
has solved `A leq B, C leq A, B leq C' and produced the answer `A=B,
B=C':

     A leq B,C leq A,B leq C.
     % C leq A, A leq B propagates C leq B by transitivity.
     % C leq B, B leq C simplifies to B=C by antisymmetry.
     % A leq B, C leq A simplifies to A=B by antisymmetry since B=C.
     A=B,B=C.

   Note that multiple heads of rules are essential in solving these
constraints.  Also note that this handler implements a (partial) order
constraint over any constraint domain, this generality is only possible
with CHR.

   As another example, we can implement the sieve of Eratosthenes to
compute primes simply as (for variations see the handler `primes.pl'):

     :- use_module(library(chr)).
     handler eratosthenes.
     constraints primes/1,prime/1.
     
     primes(1) <=> true.
     primes(N) <=> N>1 | M is N-1,prime(N),primes(M). % generate candidates
     
     absorb(J) @ prime(I) \ prime(J) <=> J mod I =:= 0 | true.

   The constraint `primes(N)' generates candidates for prime numbers,
`prime(M)', where `M' is between `1' and `N'.  The candidates react
with each other such that each number absorbs multiples of itself. In
the end, only prime numbers remain.

   Looking at the two rules defining `primes/1', note that head
matching is used in CHR, so the first rule will only apply to
`primes(1)'. The test `N>1' is a guard (precondition) on the second
rule.  A call with a free variable, like `primes(X)', will delay
(suspend).  The third, multi-headed rule `absorb(J)' reads as follows:
If there is a constraint `prime(I)' and some other constraint
`prime(J)' such that `J mod I =:= 0' holds, i.e. `J' is a multiple of
`I', then keep `prime(I)' but remove `prime(J)' and execute the body of
the  rule, `true'.


File: yap.info,  Node: CHR Library,  Next: CHR Debugging,  Prev: CHR Introductory Examples,  Up: CHR

CHR Library
===========

CHR extend the Prolog syntax by a few constructs introduced in the next
sections. Technically, the extension is achieved through the
`user:term_expansion/2' mechanism. A file that contains a constraint
handler may also contain arbitrary Prolog code.  Constraint handling
rules can be scattered across a file. Declarations and options should
precede rules. There can only be at most one constraint handler per
module.

* Menu:

* CHR Loading the Library::
* CHR Declarations::
* CHR Syntax::
* How CHR work::
* CHR Pragmas::
* CHR Options::
* CHR Built-In Predicates::
* CHR Consulting and Compiling::
* CHR Compiler-generated Predicates::
* CHR Operator Declarations::
* CHR Exceptions::


File: yap.info,  Node: CHR Loading the Library,  Next: CHR Declarations,  Prev: CHR Library,  Up: CHR Library

Loading the Library
-------------------

Before you can load or compile any file containing a constraint handler
(solver) written in CHR, the `chr' library module has to be imported:
     | ?- use_module(library(chr)).
   It is recommended to include the corresponding directive at the
start of your files containing handlers:
       :- use_module(library(chr)).


File: yap.info,  Node: CHR Declarations,  Next: CHR Syntax,  Prev: CHR Loading the Library,  Up: CHR Library

Declarations
------------

Declarations in files containing CHR affect the compilation and thus
the behavior of the rules at runtime.

   The mandatory handler declaration precedes any other CHR specific
code.  Example:
     handler minmax.
   A handler name must be a valid Prolog `atom'.  Per module, only one
constraint handler can be defined.

   The constraints must be declared before they are used by rules.
With this mandatory declaration one lists the constraints the rules
will later talk about. The declaration can be used more than once per
handler.  Example:
     constraints  leq/2, minimum/3, maximum/3.

   The following optional declaration allows for conditional rule
compilation.  Only the rules mentioned get compiled. Rules are referred
to by their names (*note CHR Syntax::). The latest occurrence takes
precedence if used more than once per handler. Although it can be put
anywhere in the handler file, it makes sense, as with other
declarations, to use it early.  Example:
     rules antisymmetry, transitivity.

   To simplify the handling of operator declarations, in particular
during `fcompile/1', `operator/3' declarations with the same denotation
as `op/3', but taking effect during compilation and loading, are
helpful.  Example:
     operator(700, xfx, ::).
     operator(600, xfx, :).


File: yap.info,  Node: CHR Syntax,  Next: How CHR work,  Prev: CHR Declarations,  Up: CHR Library

Constraint Handling Rules, Syntax
---------------------------------

A constraint handling rule has one or more heads, an optional guard, a
body and an optional name.  A "Head" is a "Constraint". A constraint is
a callable Prolog term, whose functor is a declared constraint.  The
"Guard" is a Prolog goal.  The "Body" of a rule is a Prolog goal
(including constraints).  A rule can be named with a "Name" which can
be any Prolog term (including variables from the rule).

   There are three kinds of constraint handling rules:
     Rule           --> [Name @]
                          (Simplification | Propagation | Simpagation)
                             [pragma Pragma].
     
     Simplification --> Heads         <=> [Guard '|'] Body
     Propagation    --> Heads         ==> [Guard '|'] Body
     Simpagation    --> Heads \ Heads <=> [Guard '|'] Body
     
     Heads          --> Head | Head, Heads
     Head           --> Constraint | Constraint # Id
     Constraint     --> a callable term declared as constraint
     Id             --> a unique variable
     
     Guard          --> Ask | Ask & Tell
     Ask            --> Goal
     Tell           --> Goal
     Goal           --> a callable term,
                        including conjunction and disjunction etc.
     
     Body           --> Goal
     
     Pragma         --> a conjunction of terms usually referring to
                        one or more heads identified via #/2

   The symbol `|' separates the guard (if present) from the body of a
rule.  Since `|' is read as `;' (disjunction) by the reader, care has
to be taken when using disjunction in the guard or body of the rule.
The top level disjunction will always be interpreted as guard-body
separator `|', so proper bracketing has to be used, e.g. `a <=> (b;c) |
(d;e)' instead of `a <=> b;c | d;e' and `a <=> true | (d;e)' instead of
`a <=> (d;e)'.

   In simpagation rules, `\' separates the heads of the rule into two
parts.

   Individual head constraints may be tagged with variables via `#',
which may be used as identifiers in pragma declarations, for example.
Constraint identifiers must be distinct variables, not occurring
elsewhere in the heads.

   Guards test the applicability of a rule.  Guards come in two parts,
tell and ask, separated by `&'.  If the `&' operator is not present,
the whole guard is assumed to be of the ask type.

   Declaratively, a rule relates heads and body "provided the guard is
true".  A simplification rule means that the heads are true if and only
if the body is true.  A propagation rule means that the body is true if
the heads are true.  A simpagation rule combines a simplification and a
propagation rule.  The rule `Heads1 \ Heads2 <=> Body' is equivalent to
the simplification rule `Heads1, Heads2 <=> Heads1, Body'. However, the
simpagation rule is more compact to write, more efficient to execute
and has better termination behavior than the corresponding
simplification rule, since the constraints comprising `Heads1' will not
be removed and inserted again.


File: yap.info,  Node: How CHR work,  Next: CHR Pragmas,  Prev: CHR Syntax,  Up: CHR Library

How CHR work
------------

Each CHR constraint is associated with all rules in whose heads it
occurs by the CHR compiler. Every time a CHR constraint is executed
(called) or woken and reconsidered, it checks itself the applicability
of its associated CHR by "trying" each CHR.  By default, the rules are
tried in textual order, i.e. in the order they occur in the defining
file.  To try a CHR, one of its heads is matched against the constraint.
Matching succeeds if the constraint is an instance of the head.  If a
CHR has more than one head, the constraint store is searched for
"partner" constraints that match the other heads.  Heads are tried from
left to right, except that in simpagation rules, the heads to be
removed are tried before the head constraints to be kept (this is done
for efficiency reasons).  If the matching succeeds, the guard is
executed. Otherwise the next rule is tried.

   The guard either succeeds or fails.  A guard succeeds if the
execution of its Ask and Tell parts succeeds and in the ask part no
variable that occurs also in the heads was touched or the cause of an
instantiation error. The ask guard will fail otherwise.  A variable is
"touched" if it is unified with a term (including other variables from
other constraints) different from itself.  Tell guards, on the
contrary, are trusted and not checked for that property.  If the guard
succeeds, the rule applies.  Otherwise the next rule is tried.

   If the firing CHR is a simplification rule, the matched constraints
are removed from the store and the body of the CHR is executed.
Similarly for a firing simpagation rule, except that the constraints
that matched the heads preceding `\' are kept.  If the firing CHR is a
propagation rule the body of the CHR is executed without removing any
constraints.  It is remembered that the propagation rule fired, so it
will not fire again with the same constraints if the constraint is woken
and reconsidered.  If the currently active constraint has not been
removed, the next rule is tried.

   If the current constraint has not been removed and all rules have
been tried, it delays until a variable occurring in the constraint is
touched.  Delaying means that the constraint is inserted into the
constraint store. When a constraint is woken, all its rules are tried
again. (This process can be watched and inspected with the CHR debugger,
see below.)


File: yap.info,  Node: CHR Pragmas,  Next: CHR Options,  Prev: How CHR work,  Up: CHR Library

Pragmas
-------

Pragmas are annotations to rules and constraints that enable the
compiler to generate more specific, more optimized code. A pragma can
be a conjunction of the following terms:

`already_in_heads'
     The intention of simplification and simpagation rules is often to
     combine the heads into a stronger version of one of them.
     Depending on the strength of the guard, the new constraint may be
     identical to one of the heads to removed by the rule.  This
     removal followed by addition is inefficient and may even cause
     termination problems. If the pragma is used, this situation is
     detected and the corresponding problems are avoided.  The pragma
     applies to all constraints removed by the rule.

`already_in_head(Id)'
     Shares the intention of the previous pragma, but affects only the
     constraint indicated via ID. Note that one can use more than one
     pragma per rule.

`passive(Id)'
     No code will be generated for the specified constraint in the
     particular head position. This means that the constraint will not
     see the rule, it is passive in that rule. This changes the
     behavior of the CHR system, because normally, a rule can be
     entered starting from each head constraint.  Usually this pragma
     will improve the efficiency of the constraint handler, but care
     has to be taken in order not to lose completeness.

     For example, in the handler `leq', any pair of constraints, say `A
     leq B, B leq A', that matches the head `X leq Y , Y leq X' of the
     `antisymmetry' rule, will also match it when the constraints are
     exchanged, `B leq A, A leq B'. Therefore it is enough if a
     currently active constraint enters this rule in the first head
     only, the second head can be declared to be passive. Similarly for
     the `idempotence' rule.  For this rule, it is more efficient to
     declare the first head passive, so that the currently active
     constraint will be removed when the rule fires (instead of
     removing the older constraint and redoing all the propagation with
     the currently active constraint).  Note that the compiler itself
     detects the symmetry of the two head constraints in the
     simplification rule `antisymmetry', thus it is automatically
     declared passive and the compiler outputs `CHR eliminated code for
     head 2 in antisymmetry'.
          antisymmetry  X leq Y, Y leq X # Id <=> X=Y
                     pragma passive(Id).
          idempotence   X leq Y # Id \ X leq Y <=> true
                     pragma passive(Id).
          transitivity  X leq Y # Id, Y leq Z ==> X leq Z
                     pragma passive(Id).
     Declaring the first head of rule `transitivity' passive changes the
     behavior of the handler. It will propagate less depending on the
     order in which the constraints arrive:
          ?- X leq Y, Y leq Z.
          X leq Y,
          Y leq Z,
          X leq Z ?
          
          ?- Y leq Z, X leq Y.
          Y leq Z,
          X leq Y ?
          
          ?- Y leq Z, X leq Y, Z leq X.
          Y = X,
          Z = X ?
     The last query shows that the handler is still complete in the
     sense that all circular chains of leq-relations are collapsed into
     equalities.



File: yap.info,  Node: CHR Options,  Next: CHR Built-In Predicates,  Prev: CHR Pragmas,  Up: CHR Library

Options
-------

Options parametrise the rule compilation process.  Thus they should
precede the rule definitions. Example:
     option(check_guard_bindings, off).

   The format below lists the names of the recognized options together
with the acceptable values. The first entry in the lists is the default
value.

`option(debug_compile,         [off,on]).'
     Instruments the generated code such that the execution of the
     rules may be traced (*note CHR Debugging::).

`option(check_guard_bindings,  [on,off]).'
     Per default, for guards of type ask the CHR runtime system makes
     sure that no variables are touched or the cause of an instantiation
     error. These checks may be turned off with this option, i.e. all
     guards are treated as if they were of the tell variety. The option
     was kept for backward compatibility. Tell and ask guards offer
     better granularity.

`option(already_in_store,      [off,on]).'
     If this option is on, the CHR runtime system checks for the
     presence of an identical constraint upon the insertion into the
     store. If present, the attempted insertion has no effect. Since
     checking for duplicates for all constraints costs, duplicate
     removal specific to individual constraints, using a few
     simpagation rules of the following form instead, may be a better
     solution.
          Constraint \ Constraint <=> true.

`option(already_in_heads,      [off,on]).'
     The intention of simplification and simpagation rules is often to
     combine the heads into a stronger version of one of them.
     Depending on the strength of the guard, the new constraint may be
     identical to one of the heads removed by the rule.  This removal
     followed by addition is inefficient and may even cause termination
     problems. If the option is enabled, this situation is detected and
     the corresponding problems are avoided.  This option applies to
     all constraints and is provided mainly for backward compatibility.
     Better grained control can be achieved with corresponding pragmas.
     (*note CHR Pragmas::).


   The remaining options are meant for CHR implementors only:
`option(flatten,               [on,off]).'

`option(rule_ordering,         [canonical,heuristic]).'

`option(simpagation_scheme,    [single,multi]).'

`option(revive_scheme,         [new,old]).'

`option(dead_code_elimination, [on,off]).'


File: yap.info,  Node: CHR Built-In Predicates,  Next: CHR Consulting and Compiling,  Prev: CHR Options,  Up: CHR Library

Built-In Predicates
-------------------

This table lists the predicates made available by the CHR library.  They
are meant for advanced users, who want to tailor the CHR system towards
their specific needs.
`current_handler(?Handler, ?Module)'
     Nondeterministically enumerates the defined handlers with the
     module they are defined in.

`current_constraint(?Handler, ?Constraint)'
     Nondeterministically enumerates the defined constraints in the
     form FUNCTOR/ARITY and the handlers they are defined in.

`insert_constraint(+Constraint, -Id)'
     Inserts CONSTRAINT into the constraint store without executing any
     rules. The constraint will be woken and reconsidered when one of
     the variables in CONSTRAINT is touched. ID is unified with an
     internal object representing the constraint.  This predicate only
     gets defined when a handler and constraints are declared (*note
     CHR Declarations::).

`insert_constraint(+Constraint, -Id, ?Term)'
     Inserts CONSTRAINT into the constraint store without executing any
     rules. The constraint will be woken and reconsidered when one of
     the variables in TERM is touched. ID is unified with an internal
     object representing the constraint.  This predicate only gets
     defined when a handler and constraints are declared (*note CHR
     Declarations::).

`find_constraint(?Pattern, -Id)'
     Nondeterministically enumerates constraints from the constraint
     store that match PATTERN, i.e. which are instances of PATTERN. ID
     is unified with an internal object representing the constraint.

`find_constraint(-Var, ?Pattern, -Id)'
     Nondeterministically enumerates constraints from the constraint
     store that delay on VAR and match PATTERN, i.e. which are
     instances of PATTERN. The identifier ID can be used to refer to
     the constraint later, e.g. for removal.

`findall_constraints(?Pattern, ?List)'
     Unifies LIST with a list of `Constraint # Id' pairs from the
     constraint store that match PATTERN.

`findall_constraints(-Var, ?Pattern, ?List)'
     Unifies LIST with a list of `Constraint # Id' pairs from the
     constraint store that delay on VAR and match PATTERN.

`remove_constraint(+Id)'
     Removes the constraint ID, obtained with one of the previous
     predicates, from the constraint store.

`unconstrained(?Var)'
     Succeeds if no CHR constraint delays on VAR. Defined as:
          unconstrained(X) :-
              find_constraint(X, _, _), !, fail.
          unconstrained(_).

`notify_constrained(?Var)'
     Leads to the reconsideration of the constraints associated with
     VAR.  This mechanism allows solvers to communicate reductions on
     the set of possible values of variables prior to making bindings.


File: yap.info,  Node: CHR Consulting and Compiling,  Next: CHR Compiler-generated Predicates,  Prev: CHR Built-In Predicates,  Up: CHR Library

Consulting and Compiling Constraint Handlers
--------------------------------------------

The CHR compilation process has been made as transparent as possible.
The user deals with files containing CHR just as with files containing
ordinary Prolog predicates. Thus CHR may be consulted, compiled with
various compilation modes, and compiled to file.


File: yap.info,  Node: CHR Compiler-generated Predicates,  Next: CHR Operator Declarations,  Prev: CHR Consulting and Compiling,  Up: CHR Library

Compiler-generated Predicates
-----------------------------

Besides predicates for the defined constraints, the CHR compiler
generates some support predicates in the module containing the handler.
To avoid naming conflicts, the  following predicates must not be
defined or referred to by user code in the same module:
`verify_attributes/3'

`attribute_goal/2'

`attach_increment/2'

`'attach_F/A'/2'
     for every defined constraint F/A.

`'F/A_N_M_...'/Arity'
     for every defined constraint F/A. N,M is are integers, Arity > A.

   For the prime number example that is:
             attach_increment/2
             attach_prime/1/2
             attach_primes/1/2
             attribute_goal/2
             goal_expansion/3
             prime/1
             prime/1_1/2
             prime/1_1_0/3
             prime/1_2/2
             primes/1
             primes/1_1/2
             verify_attributes/3

   If an author of a handler wants to avoid naming conflicts with the
code that uses the handler, it is easy to encapsulate the handler.  The
module declaration below puts the handler into module `primes', which
exports only selected predicates - the constraints in our example.
             :- module(primes, [primes/1,prime/1]).
     
             :- use_module(library(chr)).
     
             handler eratosthenes.
             constraints primes/1,prime/1.
             ...


File: yap.info,  Node: CHR Operator Declarations,  Next: CHR Exceptions,  Prev: CHR Compiler-generated Predicates,  Up: CHR Library

Operator Declarations
---------------------

This table lists the operators as used by the CHR library:
     :- op(1200, xfx, @).
     :- op(1190, xfx, pragma).
     :- op(1180, xfx, [==>,<=>]).
     :- op(1180, fy,  chr_spy).
     :- op(1180, fy,  chr_nospy).
     :- op(1150, fx,  handler).
     :- op(1150, fx,  constraints).
     :- op(1150, fx,  rules).
     :- op(1100, xfx, '|').
     :- op(1100, xfx, \ ).
     :- op(1050, xfx, &).
     :- op( 500, yfx, #).


File: yap.info,  Node: CHR Exceptions,  Prev: CHR Operator Declarations,  Up: CHR Library

Exceptions
----------

The CHR runtime system reports instantiation and type errors for the
predicates:
`find_constraint/2'

`findall_constraints/3'

`insert_constraint/2'

`remove_constraint/1'

`notify_constrained/1'

   The only other CHR specific runtime error is:
`{CHR ERROR: registering <New>, module <Module> already hosts <Old>}'
     An attempt to load a second handler New into module <Module>
     already hosting handler <Old> was made.

   The following exceptional conditions are detected by the CHR
compiler:

`{CHR Compiler ERROR: syntax rule <N>: <Term>}'
     If the N-th <Term> in the file being loaded violates the CHR
     syntax (*note CHR Syntax::).

`{CHR Compiler ERROR: too many general heads in <Name>}'
     Unspecific heads in definitions like `C \ C <=> true' must not be
     combined with other heads in rule <Name>.

`{CHR Compiler ERROR: bad pragma <Pragma> in <Name>}'
     The pragma <Pragma> used in rule <Name> does not qualify.
     Currently this only happens if <Pragma> is unbound.

`{CHR Compiler ERROR: found head <F/A> in <Name>, expected one of: <F/A list>}'
     Rule <Name> has a head of given F/A which is not among the defined
     constraints.

`{CHR Compiler ERROR: head identifiers in <Name> are not unique variables}'
     The identifiers to refer to individual constraints (heads) via `#'
     in rule <Name> do not meet the indicated requirements.

`{CHR Compiler ERROR: no handler defined}'
     CHR specific language elements, declarations or rules for example,
     are used before a handler was defined. This error is usually
     reported a couple of times, i.e. as often as there are CHR forms
     in the file expecting the missing definition.

`{CHR Compiler ERROR: compilation failed}'
     Not your fault. Send us a bug report.


File: yap.info,  Node: CHR Debugging,  Next: CHR Programming Hints,  Prev: CHR Library,  Up: CHR

Debugging CHR Programs
======================

Use `option(debug_compile,on)' preceding any rules in the file
containing the handler to enable CHR debugging.  The CHR debugging
mechanism works by instrumenting the code generated by the CHR compiler.
Basically, the CHR debugger works like the Prolog debugger.  The main
differences are: there are extra ports specific to CHR, and the CHR
debugger provides no means for the user to change the flow of control,
i.e. there are currently no RETRY and FAIL options available.

* Menu:

* CHR Control Flow Model::
* CHR Debugging Predicates::
* CHR Spy-points::
* CHR Debugging Messages::
* CHR Debugging Options::


File: yap.info,  Node: CHR Control Flow Model,  Next: CHR Debugging Predicates,  Prev: CHR Debugging,  Up: CHR Debugging

Control Flow Model
------------------

The entities reflected by the CHR debugger are constraints and rules.
Constraints are treated like ordinary Prolog goals with the usual
ports: `[call,exit,redo,fail]'.  In addition, constraints may get
inserted into or removed from the constraint store (ports:
`insert,remove'), and stored constraints containing variables will be
woken and reconsidered (port: `wake') when variables are touched.

   The execution of a constraint consists of trying to apply the rules
mentioning the constraint in their heads.  Two ports for rules reflect
this process: At a `try' port the active constraint matches one of the
heads of the rule, and matching constraints for the remaining heads of
the rule, if any, have been found as well.  The transition from a `try'
port to an `apply' port takes place when the guard has been
successfully evaluated, i.e. when the rule commits. At the `apply'
port, the body of the rule is just about to be executed. The body is a
Prolog goal transparent to the CHR debugger. If the rule body contains
CHR constraints, the CHR debugger will track them again.  If the rules
were consulted, the Prolog debugger can be used to study the
evaluations of the other predicates in the body.


File: yap.info,  Node: CHR Debugging Predicates,  Next: CHR Spy-points,  Prev: CHR Control Flow Model,  Up: CHR Debugging

CHR Debugging Predicates
------------------------

The following predicates control the operation of the CHR debugger:

`chr_trace'
     Switches the CHR debugger on and ensures that the next time
     control enters a CHR port, a message will be produced and you will
     be asked to interact.

     At this point you have a number of options.  *Note CHR Debugging
     Options::.  In particular, you can just type <cr> (Return) to
     "creep" (or single-step) into your program. You will notice that
     the CHR debugger stops at many ports.  If this is not what you
     want, the predicate `chr_leash' gives full control over the ports
     at which you are prompted.

`chr_debug'
     Switches the CHR debugger on and ensures that the next time
     control enters a CHR port with a spy-point set, a message will be
     produced and you will be asked to interact.

`chr_nodebug'
     Switches the CHR debugger off.  If there are any spy-points set
     then they will be kept.

`chr_notrace'
     Equivalent to `chr_nodebug'.

`chr_debugging'
     Prints onto the standard error stream information about the current
     CHR debugging state.  This will show:

       1. Whether the CHR debugger is switched on.

       2. What spy-points have been set (see below).

       3. What mode of leashing is in force (see below).

`chr_leash(+MODE)'
     The leashing mode is set to MODE. It determines the CHR ports at
     which you are to be prompted when you "creep" through your program.
     At unleashed ports a tracing message is still output, but program
     execution does not stop to allow user interaction.  Note that the
     ports of spy-points are always leashed (and cannot be unleashed).
     MODE is a list containing none, one or more of the following port
     names:

    `call'
          Prompt when a constraint is executed for the first time.

    `exit'
          Prompt when the constraint is successfully processed, i.e.
          the applicable rules have applied.

    `redo'
          Prompt at subsequent exits generated by non-deterministic
          rule bodies.

    `fail'
          Prompt when a constraint fails.

    `wake'
          Prompt when a constraint from the constraint store is woken
          and reconsidered because one of its variables has been
          touched.

    `try'
          Prompt just before the guard evaluation of a rule, after
          constraints matching the heads have been found.

    `apply'
          Prompt upon the application of a rule, after the successful
          guard evaluation, when the rule commits and fires, just
          before evaluating the body.

    `insert'
          Prompt when a constraint gets inserted into the constraint
          store, i.e. after all rules have been tried.

    `remove'
          Prompt when a constraint gets removed from the constraint
          store, e.g.  when a simplification rule applies.


     The initial value of the CHR leashing mode is
     `[call,exit,fail,wake,apply]'. Predefined shortcuts are:
    `chr_leash(none), chr_leash(off)'
          To turn leashing off.

    `chr_leash(all)'
          To prompt at every port.

    `chr_leash(default)'
          Same as `chr_leash([call,exit,fail,wake,apply])'.

    `chr_leash(call)'
          No need to use a list if only a singular port is to be
          leashed.



File: yap.info,  Node: CHR Spy-points,  Next: CHR Debugging Messages,  Prev: CHR Debugging Predicates,  Up: CHR Debugging

CHR Spy-points
--------------

For CHR programs of any size, it is clearly impractical to creep
through the entire program.  "Spy-points" make it possible to stop the
program upon an event of interest.  Once there, one can set further
spy-points in order to catch the control flow a bit further on, or one
can start creeping.

   Setting a spy-point on a constraint or a rule indicates that you
wish to see all control flow through the various ports involved, except
during skips.  When control passes through any port with a spy-point
set on it, a message is output and the user is asked to interact.  Note
that the current mode of leashing does not affect spy-points: user
interaction is requested at _every_ port.

   Spy-points are set and removed by the following predicates, which
are declared as prefix operators:

`chr_spy SPEC'
     Sets spy-points on constraints and rules given by SPEC, which is
     is of the form:

    _ (variable)
          denoting all constraints and rules, or:

    CONSTRAINTS CS
          where CS is one of
         _ (variable)
               denoting all constraints

         C,...,C
               denoting a list of constraints C

         NAME
               denoting all constraints with this functor, regardless
               of arity

         NAME/ARITY
               denoting the constraint of that name and arity

    RULES RS
          where RS is one of:
         _ (variable)
               denoting all rules

         R,...,R
               denoting a list of rules R

         NAME
               where NAME is the name of a rule in any handler.

         ALREADY_IN_STORE
               The name of a rule implicitly defined by the system when
               the option `already_in_store' is in effect.

         ALREADY_IN_HEADS
               The name of a rule implicitly defined by the system when
               the option `already_in_heads' or the corresponding
               pragmas are in effect.

         HANDLER:NAME
               where HANDLER is the name of a constraint handler and
               NAME is the name of a rule in that handler


     Examples:

          | ?- chr_spy rules rule(3), transitivity, already_in_store.
          | ?- chr_spy constraints prime/1.

     If you set spy-points, the CHR debugger will be switched on.

`chr_nospy SPEC'
     Removes spy-points on constraints and rules given by SPEC, where
     SPEC is of the form as described for `chr_spy SPEC'.  There is no
     `chr_nospyall/0'.  To remove all CHR spy-points use `chr_nospy _'.


The options available when you arrive at a spy-point are described
later.  *Note CHR Debugging Options::.


File: yap.info,  Node: CHR Debugging Messages,  Next: CHR Debugging Options,  Prev: CHR Spy-points,  Up: CHR Debugging

CHR Debugging Messages
----------------------

All trace messages are output to the standard error stream.  This
allows you to trace programs while they are performing file I/O.  The
basic format is as follows:

     S 3 1 try eratosthenes:absorb(10) @ prime(9)#<c4>, prime(10)#<c2> ?

S is a spy-point indicator. It is printed as ` ' if there is no
spy-point, as `r', indicating that there is a spy-point on this rule,
or as `c' if one of the involved constraints has a spy-point.

   The first number indicates the current depth of the execution; i.e.
the number of direct "ancestors" the currently active constraint has.

   The second number indicates the head position of the currently active
constraint at rule ports.

   The next item tells you which port is currently traced.

   A constraint or a matching rule are printed next.  Constraints print
as `Term#Id', where ID is a unique identifier pointing into the
constraint store.  Rules are printed as `Handler:Name @', followed by
the constraints matching the heads.

   The final `?' is the prompt indicating that you should type in one
of the debug options (*note CHR Debugging Options::).


File: yap.info,  Node: CHR Debugging Options,  Prev: CHR Debugging Messages,  Up: CHR Debugging

CHR Debugging Options
---------------------

This section describes the options available when the system prompts you
after printing out a debugging message.  Most of them you know from the
standard Prolog debugger. All the options are one letter mnemonics, some
of which can be optionally followed by a decimal integer.  They are read
from the standard input stream up to the end of the line (Return,
<<cr>>). Blanks will be ignored.

   The only option which you really have to remember is `h'.  This
provides help in the form of the following list of available options.

     CHR debugging options:
        <cr>   creep            c      creep
         l     leap
         s     skip             s <i>  skip (ancestor i)
         g     ancestors
         &     constraints      & <i>  constraints (details)
         n     nodebug          =      debugging
         +     spy this
         -     nospy this       .      show rule
         <     reset printdepth < <n>  set printdepth
         a     abort            b      break
         ?     help             h      help

`c'
`<<cr>>'
     "creep" causes the debugger to single-step to the very next port
     and print a message.  Then if the port is leashed, the user is
     prompted for further interaction.  Otherwise, it continues
     creeping.  If leashing is off, creep is the same as "leap" (see
     below) except that a complete trace is printed on the standard
     error stream.

`l'
     "leap" causes the debugger to resume running your program, only
     stopping when a spy-point is reached (or when the program
     terminates).  Leaping can thus be used to follow the execution at
     a higher level than exhaustive tracing.

`s'
`s i'
     "skip" over the entire execution of the constraint.  That is, you
     will not see anything until control comes back to this constraint
     (at either the `exit' port or the `fail' port). This includes
     ports with spy-points set; they will be masked out during the skip.
     The command can be used with a numeric argument to skip the
     execution up to and including the ancestor indicated by the
     argument.  Example:
                ...
                4   - exit    prime(8)#<c6> ? g
          Ancestors:
                1   1 apply   eratosthenes:rule(2) @ primes(10)#<c1>
                2   1 apply   eratosthenes:rule(2) @ primes(9)#<c3>
                3   1 apply   eratosthenes:rule(2) @ primes(8)#<c5>
                4   - call    prime(8)#<c6>
          
                4   - exit    prime(8)#<c6> ? s 2
                2   - exit    primes(9)#<c3> ?

`g'
     "print ancestors" provides you with a list of ancestors to the
     currently active constraint, i.e. all constraints not yet exited
     that led to the current constraint in the derivation sequence.
     The format is the same as with trace messages.  Constraints start
     with `call' entries in the stack.  The subsequent application of a
     rule replaces the call entry in the stack with an `apply' entry.
     Later the constraint shows again as `redo' or `fail' entry.
     Example:
                0   - call    primes(10)#<c1> ?
                1   1 try     eratosthenes:rule(2) @ primes(10)#<c1> ? g
          
          Ancestors:
                1   - call    primes(10)#<c1>
          
                1   1 try     eratosthenes:rule(2) @ primes(10)#<c1> ?
                1   1 apply   eratosthenes:rule(2) @ primes(10)#<c1> ?
                1   - call    prime(10)#<c2> ?
                2   - insert  prime(10)#<c2>
                2   - exit    prime(10)#<c2> ? g
          
          Ancestors:
                1   1 apply   eratosthenes:rule(2) @ primes(10)#<c1>
                2   - call    prime(10)#<c2>

`&'
     "print constraints" prints a list of the constraints in the
     constraint store. With a numeric argument, details relevant
     primarily to CHR implementors are shown.

`n'
     "nodebug" switches the CHR debugger off.

`='
     "debugging" outputs information concerning the status of the CHR
     debugger as via `chr_debugging/0'

`+'
     "spy this" sets a spy-point on the current constraint or rule.

`-'
     "nospy this" removes the spy-point from the current constraint or
     rule, if it exists.

`.'
     "show rule" prints the current rule instantiated by the matched
     constraints. Example:
           8 1 apply  era:absorb(8) @ prime(4)#<c14> \ prime(8)#<c6> ? .
          
           absorb(8) @
            prime(4)#<c14> \
              prime(8)#<c6> <=>
          
              8 mod 4=:=0
              |
              true.

`<'
`< n'
     While in the debugger, a "printdepth" is in effect for limiting
     the subterm nesting level when printing rules and constraints.
     The limit is initially 10.  This command, without arguments,
     resets the limit to 10.  With an argument of N, the limit is set to
     N. An argument N of 0 disables depth limit in the debugger.

`a'
     "abort" calls the built-in predicate `abort/0'.

`b'
     "break" calls the built-in predicate `break/0', thus putting you
     at a recursive top-level.  When you end the break (entering ^D)
     you will be re-prompted at the port at which you broke. The CHR
     debugger is temporarily switched off as you call the break and will
     be switched on again when you finish the break and go back to the
     old execution.  Any changes to the CHR leashing or to spy-points
     during the break will remain in effect.

`?'
`h'
     "help" displays the table of options given above.



File: yap.info,  Node: CHR Programming Hints,  Next: CHR Constraint Handlers,  Prev: CHR Debugging,  Up: CHR

Programming Hints
=================

This section gives you some programming hints for CHR. For maximum
efficiency of your constraint handler, see also the previous subsections
on declarations and options.

   Constraint handling rules for a given constraint system can often be
derived from its definition in formalisms such as inference rules,
rewrite rules, sequents, formulas expressing axioms and theorems.  CHR
can also be found by first considering special cases of each constraint
and then looking at interactions of pairs of constraints sharing a
variable. Cases that do not occur in the application can be ignored.

   It is important to find the right "granularity" of the constraints.
Assume one wants to express that "n" variables are different from each
other.  It is more efficient to have a single constraint
`all_different(List_of_n_Vars)' than "n*n" inequality constraints
between each pair of different variables.  However, the extreme case of
having a single constraint modeling the whole constraint store will
usually be inefficient.

   Starting from an executable specification, the rules can then be
refined and adapted to the specifics of the application.  Efficiency
can be improved by weakening the guards to perform simplification as
early as needed and by strengthening the guards to do the "just right"
amount of propagation.  Propagation rules can be expensive, because no
constraints are removed.

   The more heads a rule has, the more expensive it is.  "Rules with
several heads" are more efficient, if the heads of the rule share a
variable (which is usually the case). Then the search for a partner
constraint has to consider less candidates.  In the current
implementation, constraints are indexed by their functors, so that the
search is only performed among the constraints containing the shared
variable. Moreover, two rules with identical (or sufficiently similar)
heads can be merged into one rule so that the search for a partner
constraint is only performed once instead of twice.

   As "guards" are tried frequently, they should be simple "tests" not
involving side-effects.  Head matching is more efficient than
explicitly checking equalities in the ask-part of the guard.  In the
tell part of a guard, it should be made sure that variables from the
head are never touched (e.g. by using `nonvar' or `ground' if
necessary). For efficiency and clarity reasons, one should also avoid
using constraints in guards.  Besides conjunctions, disjunctions are
allowed in the guard, but they should be used with care.  The use of
other control built-in predicates in the guard is discouraged.
Negation and if-then-else in the ask part of a guard can give wrong
results, since e.g. failure of the negated goal may be due to touching
its variables.

   "Several handlers can be used simultaneously if" they do not share
constraints with the same name. The implementation will not work
correctly if the same constraint is defined in rules of different
handlers that have been compiled separately. In such a case, the
handlers must be merged "by hand". This means that the source code has
to be edited so that the rules for the shared constraint are together
(in one module). Changes may be necessary (like strengthening guards)
to avoid divergence or loops in the computation.


File: yap.info,  Node: CHR Constraint Handlers,  Next: CHR Backward Compatibility,  Prev: CHR Programming Hints,  Up: CHR

Constraint Handlers
===================

The CHR library comes with plenty of constraint handlers written in CHR.
The most recent versions of these are maintained at:

     http://www.pst.informatik.uni-muenchen.de/~fruehwir/chr-solver.html

`arc.pl'
     classical arc-consistency over finite domains

`bool.pl'
     simple Boolean constraints

`cft.pl'
     feature term constraints according to the CFT theory

`domain.pl'
     finite domains over arbitrary ground terms and interval domains
     over integers and reals, but without arithmetic functions

`gcd.pl'
     elegant two-liner for the greatest common divisor

`interval.pl'
     straightforward interval domains over integers and reals, with
     arithmetic functions

`kl-one.pl'
     terminological reasoning similar to KL-ONE or feature trees

`leq.pl'
     standard introductory CHR example handler for less-than-or-equal

`list.pl'
     equality constraints over concatenations of lists (or strings)

`listdom.pl'
     a straightforward finite enumeration list domains over integers,
     similar to `interval.pl'

`math-elim.pl'
     solves linear polynomial equations and inequations using variable
     elimination, several variations possible

`math-fougau.pl'
     solves linear polynomial equations and inequations by combining
     variable elimination for equations with Fourier's algorithm for
     inequations, several variations possible

`math-fourier.pl'
     a straightforward Fouriers algorithm to solve polynomial
     inequations over the real or rational numbers

`math-gauss.pl'
     a straightforward, elegant implementation of variable elimination
     for equations in one rule

`minmax.pl'
     simple less-than and less-than-or-equal ordering constraints
     together with minimum and maximum constraints

`modelgenerator.pl'
     example of how to use CHR for model generation in theorem proving

`monkey.pl'
     classical monkey and banana problem, illustrates how CHR can be
     used as a fairly efficient production rule system

`osf.pl'
     constraints over order sorted feature terms according to the OSF
     theory

`oztype.pl'
     rational trees with disequality and OZ type constraint with
     intersection

`pathc.pl'
     the most simple example of a handler for path consistency - two
     rules

`primes.pl'
     elegant implementations of the sieve of Eratosthenes reminiscent
     of the chemical abstract machine model, also illustrates use of
     CHR as a general purpose concurrent constraint language

`scheduling.pl'
     simple classical constraint logic programming scheduling example
     on building a house

`tarski.pl'
     most of Tarski's axiomatization of geometry as constraint system

`term.pl'
     Prolog term manipulation built-in predicates `functor/3, arg/3,
     =../2' as constraints

`time-pc.pl'
     grand generic handler for path-consistency over arbitrary
     constraints, load via `time.pl' to get a powerful solver for
     temporal constraints based on Meiri's unifying framework.
     `time-rnd.pl' contains a generator for random test problems.

`time-point.pl'
     quantitative temporal constraints over time points using
     path-consistency

`tree.pl'
     equality and disequality over finite and infinite trees (terms)

`type.pl'
     equalities and type constraints over finite and infinite trees
     (terms)


   You can consult or compile a constraint handler from the CHR library
using e.g.:
     ?- [library('chr/examples/gcd')].
     ?- compile(library('chr/examples/gcd')).
   If you want to learn more about the handlers, look at their
documented source code.

   In addition, there are files with example queries for some handlers,
their file name starts with `examples-' and the file extension
indicates the handler, e.g. `.bool':

     examples-adder.bool
     examples-benchmark.math
     examples-deussen.bool
     examples-diaz.bool
     examples-fourier.math
     examples-holzbaur.math
     examples-lim1.math
     examples-lim2.math
     examples-lim3.math
     examples-puzzle.bool
     examples-queens.bool
     examples-queens.domain
     examples-stuckey.math
     examples-thom.math


File: yap.info,  Node: CHR Backward Compatibility,  Prev: CHR Constraint Handlers,  Up: CHR

Backward Compatibility
======================

In this section, we discuss backward compatibility with the CHR library
of Eclipse Prolog.

  1. The restriction on at most two heads in a rule has been abandoned.
     A rule can have as many heads as you like. Note however, that
     searching for partner constraints can be expensive.

  2. By default, rules are compiled in textual order. This gives the
     programmer more control over the constraint handling process. In
     the Eclipse library of CHR, the compiler was optimizing the order
     of rules. Therefore, when porting a handler, rules may have to be
     reordered. A good heuristic is to prefer simplification to
     simpagation and propagation and to prefer rules with single heads
     to rules with several heads. Instead of manually rearranging an
     old handler one may also use the following combination of options
     to get the corresponding effect:
          option(rule_ordering,heuristic).
          option(revive_scheme,old).

  3. For backward compatibility, the `already_in_store',
     `already_in_head' and `guard_bindings' options are still around,
     but there are CHR syntax extensions: *Note CHR Syntax:: and
     pragmas *Note CHR Pragmas:: offering better grained control.

  4. The Eclipse library of CHR provided automatic built-in labeling
     through the `label_with' declaration. Since it was not widely used
     and can be easily simulated, built-in labeling was dropped.  The
     same effect can be achieved by replacing the declaration
     `label_with Constraint if Guard' by the simplification rule
     `chr_labeling, Constraint <=> Guard | Constraint', chr_labeling'
     and by renaming the head in each clause `Constraint :- Body' into
     `Constraint' :- Body' where `Constraint'' is a new predicate.
     Efficiency can be improved by declaring `Constraint' to be
     passive: `chr_labeling, Constraint#Id <=> Guard | Constraint',
     chr_labeling pragma passive(Id)'.  This translation will not work
     if `option(already_in_heads,on)'.  In that case use e.g.
     `chr_labeling(_), Constraint <=> Guard | Constraint',
     chr_labeling(_)' to make the new call to `chr_labeling' differ
     from the head occurrence.

  5. The set of built-in predicates for advanced CHR users is now larger
     and better designed. Also the debugger has been improved. The Opium
     debugging environment is not available in SICStus Prolog.


File: yap.info,  Node: Logtalk,  Next: Threads,  Prev: CHR,  Up: Extensions

Logtalk
*******

The Logtalk object-oriented extension is available once included with
the `use_module(library(logtalk))' command. Note that, although we load
Logtalk using the `use_module/1' built-in predicate, the system is not
packaged as a module not does it use modules in its implementation.

   Logtalk documentation is included in the Logtalk directory. For the
latest news, please see the URL <http://www.logtalk.org/>.


File: yap.info,  Node: Threads,  Next: Parallelism,  Prev: Logtalk,  Up: Extensions

Threads
*******

YAP implements a SWI-Prolog compatible multithreading library. Like in
SWI-Prolog, Prolog threads have their own stacks and only share the
Prolog _heap_: predicates, records, flags and other global
non-backtrackable data.  The package is based on the POSIX thread
standard (Butenhof:1997:PPT) used on most popular systems except for
MS-Windows.

* Menu:

Subnodes of Threads
* Creating and Destroying Prolog Threads::
* Monitoring Threads::
* Thread Communication::
* Thread Synchronisation::

Subnodes of Thread Communication
* Message Queues::
* Signalling Threads::
* Threads and Dynamic Predicates::


File: yap.info,  Node: Creating and Destroying Prolog Threads,  Next: Monitoring Threads,  Up: Threads

Creating and Destroying Prolog Threads
======================================

`thread_create(:GOAL, -ID, +OPTIONS)'
     Create a new Prolog thread (and underlying C-thread) and start it
     by executing GOAL.  If the thread is created succesfully, the
     thread-identifier of the created thread is unified to ID.  OPTIONS
     is a list of options.  Currently defined options are:

    `stack'
          Set the limit in K-Bytes to which the Prolog stacks of this
          thread may grow.  If omited, the limit of the calling thread
          is used.  See also the  commandline `-S' option.

    `trail'
          Set the limit in K-Bytes to which the trail stack of this
          thread may grow.  If omited, the limit of the calling thread
          is used. See also the commandline option `-T'.

    `alias'
          Associate an alias-name with the thread.  This named may be
          used to refer to the thread and remains valid until the
          thread is joined (see `thread_join/2').

    `detached'
          If `false' (default), the thread can be waited for using
          `thread_join/2'. `thread_join/2' must be called on this thread
          to reclaim the all resources associated to the thread. If
          `true', the system will reclaim all associated resources
          automatically after the thread finishes. Please note that
          thread identifiers are freed for reuse after a detached
          thread finishes or a normal thread has been joined.  See also
          `thread_join/2' and `thread_detach/1'.

     The GOAL argument is _copied_ to the new Prolog engine.  This
     implies further instantiation of this term in either thread does
     not have consequences for the other thread: Prolog threads do not
     share data from their stacks.

`thread_self(-ID)'
     Get the Prolog thread identifier of the running thread.  If the
     thread has an alias, the alias-name is returned.

`thread_join(+ID, -STATUS)'
     Wait for the termination of thread with given ID.  Then unify the
     result-status of the thread with STATUS.  After this call, ID
     becomes invalid and all resources associated with the thread are
     reclaimed.  Note that threads with the attribute `detached' `true'
     cannot be joined.  See also `current_thread/2'.

     A thread that has been completed without `thread_join/2' being
     called on it is partly reclaimed: the Prolog stacks are released
     and the C-thread is destroyed. A small data-structure representing
     the exit-status of the thread is retained until `thread_join/2' is
     called on the thread.  Defined values for STATUS are:

    `true'
          The goal has been proven successfully.

    `false'
          The goal has failed.

    `exception(TERM)'
          The thread is terminated on an exception.  See
          `print_message/2' to turn system exceptions into readable
          messages.

    `exited(TERM)'
          The thread is terminated on `thread_exit/1' using the
          argument TERM.

`thread_detach(+ID)'
     Switch thread into detached-state (see `detached' option at
     `thread_create/3' at runtime.  ID is the identifier of the thread
     placed in detached state.

     One of the possible applications is to simplify debugging. Threads
     that are created as `detached' leave no traces if they crash. For
     not-detached threads the status can be inspected using
     `current_thread/2'.  Threads nobody is waiting for may be created
     normally and detach themselves just before completion.  This way
     they leave no traces on normal completion and their reason for
     failure can be inspected.

`thread_exit(+TERM)'
     Terminates the thread immediately, leaving `exited(TERM)' as
     result-state for `thread_join/2'.  If the thread has the attribute
     `detached' `true' it terminates, but its exit status cannot be
     retrieved using `thread_join/2' making the value of TERM
     irrelevant.  The Prolog stacks and C-thread are reclaimed.

`thread_at_exit(:TERM)'
     Run GOAL just before releasing the thread resources. This is to be
     compared to `at_halt/1', but only for the current thread. These
     hooks are ran regardless of why the execution of the thread has
     been completed. As these hooks are run, the return-code is already
     available through `current_thread/2' using the result of
     `thread_self/1' as thread-identifier.

`thread_setconcurrency(+OLD, -NEW)'
     Determine the concurrency of the process, which is defined as the
     maximum number of concurrently active threads. `Active' here means
     they are using CPU time. This option is provided if the
     thread-implementation provides `pthread_setconcurrency()'. Solaris
     is a typical example of this family. On other systems this
     predicate unifies OLD to 0 (zero) and succeeds silently.


File: yap.info,  Node: Monitoring Threads,  Next: Thread Communication,  Prev: Creating and Destroying Prolog Threads,  Up: Threads

Monitoring Threads
==================

Normal multi-threaded applications should not need these the predicates
from this section because almost any usage of these predicates is
unsafe. For example checking the existence of a thread before signalling
it is of no use as it may vanish between the two calls. Catching
exceptions using `catch/3' is the only safe way to deal with
thread-existence errors.

   These predicates are provided for diagnosis and monitoring tasks.

`current_thread(+ID, -STATUS)'
     Enumerates identifiers and status of all currently known threads.
     Calling current_thread/2 does not influence any thread.  See also
     `thread_join/2'.  For threads that have an alias-name, this name is
     returned in ID instead of the numerical thread identifier.  STATUS
     is one of:

    `running'
          The thread is running.  This is the initial status of a
          thread.  Please note that threads waiting for something are
          considered running too.

    `false'
          The GOAL of the thread has been completed and failed.

    `true'
          The GOAL of the thread has been completed and succeeded.

    `exited(TERM)'
          The GOAL of the thread has been terminated using
          `thread_exit/1' with TERM as argument.  If the underlying
          native thread has exited (using pthread_exit()) TERM is
          unbound.

    `exception(TERM)'
          The GOAL of the thread has been terminated due to an uncaught
          exception (see `throw/1' and `catch/3').

`thread_statistics(+ID, +KEY, -VALUE)'
     Obtains statistical information on thread ID as `statistics/2'
     does in single-threaded applications.  This call returns all keys
     of `statistics/2', although only information statistics about the
     stacks and CPU time yield different values for each thread.

`mutex_statistics'
     Print usage statistics on internal mutexes and mutexes associated
     with dynamic predicates.  For each mutex two numbers are printed:
     the number of times the mutex was acquired and the number of
     collisions: the number times the calling thread has to wait for
     the mutex.  The collistion-count is not available on Windows as
     this would break portability to Windows-95/98/ME or significantly
     harm performance.  Generally collision count is close to zero on
     single-CPU hardware.


File: yap.info,  Node: Thread Communication,  Next: Thread Synchronisation,  Prev: Monitoring Threads,  Up: Threads

Thread communication
====================

* Menu:

Subnodes of Thread Communication
* Message Queues::
* Signalling Threads::
* Threads and Dynamic Predicates::


File: yap.info,  Node: Message Queues,  Next: Signalling Threads,  Up: Thread Communication

Message Queues
--------------

Prolog threads can exchange data using dynamic predicates, database
records, and other globally shared data. These provide no suitable means
to wait for data or a condition as they can only be checked in an
expensive polling loop. _Message queues_ provide a means for threads to
wait for data or conditions without using the CPU.

   Each thread has a message-queue attached to it that is identified by
the thread. Additional queues are created using
`message_queue_create/2'.

`thread_send_message(+QUEUEORTHREADID, +TERM)'
     Place TERM in the given queue or default queue of the indicated
     thread (which can even be the message queue of itself (see
     `thread_self/1'). Any term can be placed in a message queue, but
     note that the term is copied to the receiving thread and
     variable-bindings are thus lost. This call returns immediately.

     If more than one thread is waiting for messages on the given queue
     and at least one of these is waiting with a partially instantiated
     TERM, the waiting threads are _all_ sent a wakeup signal, starting
     a rush for the available messages in the queue.  This behaviour
     can seriously harm performance with many threads waiting on the
     same queue as all-but-the-winner perform a useless scan of the
     queue. If there is only one waiting thread or all waiting threads
     wait with an unbound variable an arbitrary thread is restarted to
     scan the queue.%

`thread_get_message(?TERM)'
     Examines the thread message-queue and if necessary blocks execution
     until a term that unifies to TERM arrives in the queue.  After a
     term from the queue has been unified unified to TERM, the term is
     deleted from the queue and this predicate returns.

     Please note that not-unifying messages remain in the queue.  After
     the following has been executed, thread 1 has the term `gnu' in
     its queue and continues execution using A is `gnat'.

             <thread 1>
             thread_get_message(a(A)),
          
             <thread 2>
             thread_send_message(b(gnu)),
             thread_send_message(a(gnat)),

     See also `thread_peek_message/1'.

`thread_peek_message(?TERM)'
     Examines the thread message-queue and compares the queued terms
     with TERM until one unifies or the end of the queue has been
     reached.  In the first case the call succeeds (possibly
     instantiating TERM.  If no term from the queue unifies this call
     fails.

`thread_message_queue_create(?QUEUE)'
     If QUEUE is an atom, create a named queue.  To avoid ambiguity on
     `thread_send_message/2', the name of a queue may not be in use as
     a thread-name.  If QUEUE is unbound an anonymous queue is created
     and QUEUE is unified to its identifier.

`thread_message_queue_destroy(+QUEUE)'
     Destroy a message queue created with message_queue_create/1.  It is
     _not_ allows to destroy the queue of a thread.  Neither is it
     allowed to destroy a queue other threads are waiting for or, for
     anynymous message queues, may try to wait for later.%

`thread_get_message(+QUEUE, +TERM)'
     As thread_get_message/1, operating on a given queue. It is allowed
     to peek into another thread's message queue, an operation that can
     be used to check whether a thread has swallowed a message sent to
     it.

   Explicit message queues are designed with the _worker-pool_ model in
mind, where multiple threads wait on a single queue and pick up the
first goal to execute.  Below is a simple implementation where the
workers execute arbitrary Prolog goals.  Note that this example provides
no means to tell when all work is done. This must be realised using
additional synchronisation.

     %	create_workers(+Id, +N)
     %
     %	Create a pool with given Id and number of workers.
     
     create_workers(Id, N) :-
     	message_queue_create(Id),
     	forall(between(1, N, _),
     	       thread_create(do_work(Id), _, [])).
     
     do_work(Id) :-
     	repeat,
     	  thread_get_message(Id, Goal),
     	  (   catch(Goal, E, print_message(error, E))
     	  ->  true
     	  ;   print_message(error, goal_failed(Goal, worker(Id)))
     	  ),
     	fail.
     
     %	work(+Id, +Goal)
     %
     %	Post work to be done by the pool
     
     work(Id, Goal) :-
     	thread_send_message(Id, Goal).


File: yap.info,  Node: Signalling Threads,  Next: Threads and Dynamic Predicates,  Prev: Message Queues,  Up: Thread Communication

Signalling Threads
------------------

These predicates provide a mechanism to make another thread execute some
goal as an _interrupt_.  Signalling threads is safe as these interrupts
are only checked at safe points in the virtual machine.  Nevertheless,
signalling in multi-threaded environments should be handled with care
as the receiving thread may hold a _mutex_ (see with_mutex).
Signalling probably only makes sense to start debugging threads and to
cancel no-longer-needed threads with `throw/1', where the receiving
thread should be designed carefully do handle exceptions at any point.

`thread_signal(+THREADID, :GOAL)'
     Make thread THREADID execute GOAL at the first opportunity.  In
     the current implementation, this implies at the first pass through
     the _Call-port_. The predicate `thread_signal/2' itself places
     GOAL into the signalled-thread's signal queue and returns
     immediately.

     Signals (interrupts) do not cooperate well with the world of
     multi-threading, mainly because the status of mutexes cannot be
     guaranteed easily.  At the call-port, the Prolog virtual machine
     holds no locks and therefore the asynchronous execution is safe.

     GOAL can be any valid Prolog goal, including `throw/1' to make the
     receiving thread generate an exception and `trace/0' to start
     tracing the receiving thread.



File: yap.info,  Node: Threads and Dynamic Predicates,  Prev: Signalling Threads,  Up: Thread Communication

Threads and Dynamic Predicates
------------------------------

Besides queues threads can share and exchange data using dynamic
predicates. The multi-threaded version knows about two types of dynamic
predicates. By default, a predicate declared _dynamic_ (see
`dynamic/1') is shared by all threads. Each thread may assert, retract
and run the dynamic predicate. Synchronisation inside Prolog guarantees
the consistency of the predicate. Updates are _logical_: visible
clauses are not affected by assert/retract after a query started on the
predicate. In many cases primitive from thread synchronysation should
be used to ensure application invariants on the predicate are
maintained.

   Besides shared predicates, dynamic predicates can be declared with
the `thread_local/1' directive. Such predicates share their attributes,
but the clause-list is different in each thread.

`thread_local(+FUNCTOR/ARITY)'
     related to the dynamic/1 directive.  It tells the system that the
     predicate may be modified using `assert/1', `retract/1', etc,
     during execution of the program.  Unlike normal shared dynamic
     data however each thread has its own clause-list for the predicate.
     As a thread starts, this clause list is empty.  If there are still
     clauses as the thread terminates these are automatically reclaimed
     by the system.  The thread_local property implies the property
     dynamic.

     Thread-local dynamic predicates are intended for maintaining
     thread-specific state or intermediate results of a computation.

     It is not recommended to put clauses for a thread-local predicate
     into a file as in the example below as the clause is only visible
     from the thread that loaded the source-file.  All other threads
     start with an empty clause-list.

          :- thread_local
          	foo/1.
          
          foo(gnat).



File: yap.info,  Node: Thread Synchronisation,  Prev: Thread Communication,  Up: Threads

Thread Synchronisation
======================

All internal Prolog operations are thread-safe. This implies two Prolog
threads can operate on the same dynamic predicate without corrupting the
consistency of the predicate. This section deals with user-level
_mutexes_ (called _monitors_ in ADA or _critical-sections_ by
Microsoft).  A mutex is a _MUT_ual _EX_clusive device, which implies at
most one thread can _hold_ a mutex.

   Mutexes are used to realise related updates to the Prolog database.
With `related', we refer to the situation where a `transaction' implies
two or more changes to the Prolog database.  For example, we have a
predicate `address/2', representing the address of a person and we want
to change the address by retracting the old and asserting the new
address.  Between these two operations the database is invalid: this
person has either no address or two addresses, depending on the
assert/retract order.

   Here is how to realise a correct update:

     :- initialization
     	mutex_create(addressbook).
     
     change_address(Id, Address) :-
     	mutex_lock(addressbook),
     	retractall(address(Id, _)),
     	asserta(address(Id, Address)),
     	mutex_unlock(addressbook).

`mutex_create(?MUTEXID)'
     Create a mutex.  if MUTEXID is an atom, a _named_ mutex is
     created.  If it is a variable, an anonymous mutex reference is
     returned.  There is no limit to the number of mutexes that can be
     created.

`mutex_destroy(+MUTEXID)'
     Destroy a mutex.  After this call, MUTEXID becomes invalid and
     further references yield an `existence_error' exception.

`with_mutex(+MUTEXID, :GOAL)'
     Execute GOAL while holding MUTEXID.  If GOAL leaves choicepoints,
     these are destroyed (as in `once/1').  The mutex is unlocked
     regardless of whether GOAL succeeds, fails or raises an exception.
     An exception thrown by GOAL is re-thrown after the mutex has been
     successfully unlocked.  See also `mutex_create/2'.

     Although described in the thread-section, this predicate is also
     available in the single-threaded version, where it behaves simply
     as once/1.

`mutex_lock(+MUTEXID)'
     Lock the mutex.  Prolog mutexes are _recursive_ mutexes: they can
     be locked multiple times by the same thread.  Only after unlocking
     it as many times as it is locked, the mutex becomes available for
     locking by other threads. If another thread has locked the mutex
     the calling thread is suspended until to mutex is unlocked.

     If MUTEXID is an atom, and there is no current mutex with that
     name, the mutex is created automatically using `mutex_create/1'.
     This implies named mutexes need not be declared explicitly.

     Please note that locking and unlocking mutexes should be paired
     carefully. Especially make sure to unlock mutexes even if the
     protected code fails or raises an exception. For most common cases
     use `with_mutex/2', wich provides a safer way for handling
     prolog-level mutexes.

`mutex_trylock(+MUTEXID)'
     As mutex_lock/1, but if the mutex is held by another thread, this
     predicates fails immediately.

`mutex_unlock(+MUTEXID)'
     Unlock the mutex. This can only be called if the mutex is held by
     the calling thread. If this is not the case, a `permission_error'
     exception is raised.

`mutex_unlock_all'
     Unlock all mutexes held by the current thread.  This call is
     especially useful to handle thread-termination using `abort/0' or
     exceptions.  See also `thread_signal/2'.

`current_mutex(?MUTEXID, ?THREADID, ?COUNT)'
     Enumerates all existing mutexes.  If the mutex is held by some
     thread, THREADID is unified with the identifier of te holding
     thread and COUNT with the recursive count of the mutex. Otherwise,
     THREADID is `[]' and COUNT is 0.


File: yap.info,  Node: Parallelism,  Next: Tabling,  Prev: Threads,  Up: Extensions

Parallelism
***********

There has been a sizeable amount of work on an or-parallel
implementation for YAP, called *YapOr*. Most of this work has been
performed by Ricardo Rocha. In this system parallelism is exploited
implicitly by running several alternatives in or-parallel. This option
can be enabled from the `configure' script or by checking the system's
`Makefile'.

   *YapOr* is still a very experimental system, going through rapid
development. The following restrictions are of note:

   * *YapOr* currently only supports the Linux/X86 and SPARC/Solaris
     platforms. Porting to other Unix-like platforms should be
     straightforward.

   * *YapOr* does not support parallel updates to the data-base.

   * *YapOr* does not support opening or closing of streams during
     parallel execution.

   * Garbage collection and stack shifting are not supported in *YapOr*.

   * Built-ins that cause side-effects can only be executed when
     left-most in the search-tree. There are no primitives to provide
     asynchronous or cavalier execution of these built-ins, as in
     Aurora or Muse.

   * YAP does not support voluntary suspension of work.

   We expect that some of these restrictions will be removed in future
releases.


File: yap.info,  Node: Tabling,  Next: Low Level Tracing,  Prev: Parallelism,  Up: Extensions

Tabling
*******

An initial cut for an implementation of tabling in the style of
XSB-Prolog is now available. Tabling was implemented by Ricardo Rocha.
To experiment with tabling use `-DTABLING' to `YAP_EXTRAS' in the
system's `Makefile'.

   You can use the directive `table' to force calls for the argument
predicate to be tabled. Tabling information is stored in a trie, as for
XSB-Prolog.


File: yap.info,  Node: Low Level Tracing,  Next: Low Level Profiling,  Prev: Tabling,  Up: Extensions

Tracing at Low Level
********************

It is possible to follow the flow at abstract machine level if YAP is
compiled with the flag `LOW_LEVEL_TRACER'. Note that this option is of
most interest to implementers, as it quickly generates an huge amount
of information.

   Low level tracing can be toggled from an interrupt handler by using
the option `T'. There are also two builtins that activate and
deactivate low level tracing:

`start_low_level_trace'
     Begin display of messages at procedure entry and retry.

`stop_low_level_trace'
     Stop display of messages at procedure entry and retry.

   Note that this compile-time option will slow down execution.


File: yap.info,  Node: Low Level Profiling,  Prev: Low Level Tracing,  Up: Extensions

Profiling the Abstract Machine
******************************

Implementors may be interested in detecting on which abstract machine
instructions are executed by a program. The `ANALYST' flag can give WAM
level information. Note that this option slows down execution very
substantially, and is only of interest to developers of the system
internals, or to system debuggers.

`reset_op_counters'
     Reinitialize all counters.

`show_op_counters(+A)'
     Display the current value for the counters, using label A. The
     label must be an atom.

`show_ops_by_group(+A)'
     Display the current value for the counters, organized by groups,
     using label A. The label must be an atom.



File: yap.info,  Node: Debugging,  Next: Efficiency,  Prev: Extensions,  Up: Top

Debugging
*********

* Menu:

* Deb Preds:: Debugging Predicates
* Deb Interaction:: Interacting with the debugger


File: yap.info,  Node: Deb Preds,  Next: Deb Interaction,  Up: Debugging

Debugging Predicates
====================

The following predicates are available to control the debugging of
programs:

`debug'
     Switches the debugger on.

`debugging'
     Outputs status information about the debugger which includes the
     leash mode and the existing spy-points, when the debugger is on.

`nodebug'
     Switches the debugger off.

`spy +P'
     Sets spy-points on all the predicates represented by P. P can
     either be a single specification or a list of specifications. Each
     one must be of the form NAME/ARITY or NAME. In the last case all
     predicates with the name NAME will be spied. As in C-Prolog,
     system predicates and predicates written in C, cannot be spied.

`nospy +P'
     Removes spy-points from all predicates specified by P.  The
     possible forms for P are the same as in `spy P'.

`nospyall'
     Removes all existing spy-points.

`notrace'
     Switches off the debugger and stops tracing.

`leash(+M)'
     Sets leashing mode to M.  The mode can be specified as:
    `full'
          prompt on Call, Exit, Redo and Fail

    `tight'
          prompt on Call, Redo and Fail

    `half'
          prompt on Call and Redo

    `loose'
          prompt on Call

    `off'
          never prompt

    `none'
          never prompt, same as `off'

     The initial leashing mode is `full'.

     The user may also specify directly the debugger ports where he
     wants to be prompted. If the argument for leash is a number N,
     each of lower four bits of the number is used to control prompting
     at one the ports of the box model. The debugger will prompt
     according to the following conditions:

        * if `N/\ 1 =\= 0'  prompt on fail

        * if `N/\ 2 =\= 0' prompt on redo

        * if `N/\ 4 =\= 0' prompt on exit

        * if `N/\ 8 =\= 0' prompt on call

     Therefore, `leash(15)' is equivalent to `leash(full)' and
     `leash(0)' is equivalent to `leash(off)'.

     Another way of using `leash' is to give it a list with the names of
     the ports where the debugger should stop. For example,
     `leash([call,exit,redo,fail])' is the same as `leash(full)' or
     `leash(15)' and `leash([fail])' might be used instead of
     `leash(1)'.

`spy_write(+STREAM,Term)'
     If defined by the user, this predicate will be used to print goals
     by the debugger instead of `write/2'.

`trace'
     Switches on the debugger and starts tracing.



File: yap.info,  Node: Deb Interaction,  Prev: Deb Preds,  Up: Debugging

Interacting with the debugger
=============================

Debugging with YAP is similar to debugging with C-Prolog. Both systems
include a procedural debugger, based in the four port model. In this
model, execution is seen at the procedure level: each activation of a
procedure is seen as a box with control flowing into and out of that
box.

   In the four port model control is caught at four key points: before
entering the procedure, after exiting the procedure (meaning successful
evaluation of all queries activated by the procedure), after
backtracking but before trying new alternative to the procedure and
after failing the procedure. Each one of these points is named a port:

                *--------------------------------------*
        Call    |                                      |    Exit
     ---------> +  descendant(X,Y) :- offspring(X,Y).  + --------->
                |                                      |
                |  descendant(X,Z) :-                  |
     <--------- +     offspring(X,Y), descendant(Y,Z). + <---------
        Fail    |                                      |    Redo
                *--------------------------------------*

`Call'
     The call port is activated before initial invocation of procedure.
     Afterwards, execution will try to match the goal with the head of
     existing clauses for the procedure.

`Exit'
     This port is activated if the procedure succeeds.  Control will
     now leave the procedure and return to its ancestor.

`Redo'
     if the goal, or goals, activated after the call port fail  then
     backtracking will eventually return control to this procedure
     through  the redo port.

`Fail'
     If all clauses for this predicate fail, then the invocation fails,
     and control will try to redo the ancestor of this invocation.

   To start debugging, the user will usually spy the relevant
procedures, entering debug mode, and start execution of the program.
When finding the first spy-point, YAP's debugger will take control and
show a message like:

     * (1)  call:  quicksort([1,2,3],_38) ?

   The debugger message will be shown while creeping, or at spy-points,
and it includes four or five fields:

   *  The first two characters are used to point out special states of
     the debugger. If the first character is a `*', execution is at a
     spy-point. If the second character is a `>', execution has returned
     either from a skip, a fail or a redo command.

   *  The second field is the activation number, and uniquely
     identifies the activation. The number will start from 1 and will
     be incremented for each activation found by the debugger.

   *  In the third field, the debugger shows the active port.

   *  The fourth field is the goal. The goal is written by `write/1'.

   If the active port is leashed, the debugger will prompt the user
with a `?', and wait for a command. A debugger command is just a
character, followed by a return. By default, only the call and redo
entries are leashed, but the `leash/1' predicate can be used in order
to make the debugger stop where needed.

   There are several commands available, but the user only needs to
remember the help command, which is `h'. This command shows all the
available options, which are:
`c - creep'
     this command makes YAP continue execution and stop at the next
     leashed port.

`return - creep'
     the same as c

`l - leap'
     YAP will continue execution until a port of a spied predicate is
     found;

`k - quasi-leap'
     similar to leap but faster since the computation history is not
     kept; useful when leap becomes too slow.

`s - skip'
     YAP will continue execution without showing any messages until
     returning to the current activation. Spy-points will be  ignored
     in this mode. This command is meaningless, and therefore illegal,
     in the fail and exit ports.

`t - fast-skip'
     similar to skip but faster since the computation history is not
     kept; useful when skip becomes too slow.

`q - quasi-leap'
     YAP will continue execution until a port of a spied predicate is
     found or until returning to the current activation.

`f - fail'
     forces YAP to fail the goal proceeding directly to the  fail port.
     The command is not available in the fail port.

`r - retry'
     after this command, YAP will retry the present goal,  and so go
     back to the call port. Note that any side effects of the goal will
     not be undone. This command is not available at the call port.

`a - abort'
     execution will be aborted, and the interpreter will return to the
     top-level.

`n - nodebug'
     stop debugging but continue execution. The command will clear all
     active spy-points, leave debugging mode and continue execution.

`e - exit'
     leave YAP.

`h - help'
     show the debugger commands.

`! Query'
     execute a query. YAP will not show the result of the query.

`b - break'
     break active execution and launch a break level. This is  the same
     as !  break.

`+ - spy this goal'
     start spying the active goal. The same as `! spy  G' where G is
     the active goal.

`- - nospy this goal'
     stop spying the active goal. The same as `! nospy G' where G is
     the active goal.

`p - print'
     shows the active goal using print/1

`d - display'
     shows the active goal using display/1

`<Depth - debugger write depth'
     sets the maximum write depth, both for composite terms and lists,
     that will be used by the debugger. For more information about
     `write_depth/2' (*note I/O Control::).

`< - full term'
     resets to the default of ten the debugger's maximum write depth.
     For more information about `write_depth/2' (*note I/O Control::).

   The debugging information, when fast-skip `quasi-leap' is used, will
be lost.


File: yap.info,  Node: Efficiency,  Next: C-Interface,  Prev: Debugging,  Up: Top

Indexing
********

The indexation mechanism restricts the set of clauses to be tried in a
procedure by using information about the status of a selected argument
of the goal (in YAP, as in most compilers, the first argument).  This
argument is then used as a key, selecting a restricted set of a clauses
from all the clauses forming the procedure.

   As an example, the two clauses for concatenate:

     concatenate([],L,L).
     concatenate([H|T],A,[H|NT]) :- concatenate(T,A,NT).

   If the first argument for the goal is a list, then only the second
clause is of interest. If the first argument is the nil atom, the
system needs to look only for the first clause. The indexation
generates instructions that test the value of the first argument, and
then proceed to a selected clause, or group of clauses.

   Note that if the first argument was a free variable, then both
clauses should be tried. In general, indexation will not be useful if
the first argument is a free variable.

   When activating a predicate, a Prolog system needs to store state
information. This information, stored in a structure known as choice
point or fail point, is necessary when backtracking to other clauses
for the predicate. The operations of creating and using a choice point
are very expensive, both in the terms of space used and time spent.
Creating a choice point is not necessary if there is only a clause for
the predicate as there are no clauses to backtrack to. With indexation,
this situation is extended: in the example, if the first argument was
the atom nil, then only one clause would really be of interest, and it
is pointless to create a choice point. This feature is even more useful
if the first argument is a list: without indexation, execution would
try the first clause, creating a choice point. The clause would fail,
the choice point would then be used to restore the previous state of
the computation and the second clause would be tried. The code
generated by the indexation mechanism would behave much more
efficiently: it would test the first argument and see whether it is a
list, and then proceed directly to the second clause.

   An important side effect concerns the use of "cut". In the above
example, some programmers would use a "cut" in the first clause just to
inform the system that the predicate is not backtrackable and force the
removal the choice point just created. As a result, less space is
needed but with a great loss in expressive power: the "cut" would
prevent some uses of the procedure, like generating lists through
backtracking. Of course, with indexation the "cut" becomes useless: the
choice point is not even created.

   Indexation is also very important for predicates with a large number
of clauses that are used like tables:

     logician(aristhoteles,greek).
     logician(frege,german).
     logician(russel,english).
     logician(godel,german).
     logician(whitehead,english).

   An interpreter like C-Prolog, trying to answer the query:

     ?- logician(godel,X).

would blindly follow the standard Prolog strategy, trying first the
first clause, then the second, the third and finally finding the
relevant clause.  Also, as there are some more clauses after the
important one, a choice point has to be created, even if we know the
next clauses will certainly fail. A "cut" would be needed to prevent
some possible uses for the procedure, like generating all logicians.  In
this situation, the indexing mechanism generates instructions that
implement a search table. In this table, the value of the first argument
would be used as a key for fast search of possibly matching clauses. For
the query of the last example, the result of the search would be just
the fourth clause, and again there would be no need for a choice point.

   If the first argument is a complex term, indexation will select
clauses just by testing its main functor. However, there is an important
exception: if the first argument of a clause is a list, the algorithm
also uses the list's head if not a variable. For instance, with the
following clauses,

     rules([],B,B).
     rules([n(N)|T],I,O) :- rules_for_noun(N,I,N), rules(T,N,O).
     rules([v(V)|T],I,O) :- rules_for_verb(V,I,N), rules(T,N,O).
     rules([q(Q)|T],I,O) :- rules_for_qualifier(Q,I,N), rules(T,N,O).

if the first argument of the goal is a list, its head will be tested,
and only the clauses matching it will be tried during execution.

   Some advice on how to take a good advantage of this mechanism:

   *  Try to make the first argument an input argument.

   *  Try to keep together all clauses whose first argument is not a
     variable, that will decrease the number of tests since the other
     clauses are always tried.

   *  Try to avoid predicates having a lot of clauses with the same key.
     For instance, the procedure:


     type(n(mary),person).
     type(n(john), person).
     type(n(chair),object).
     type(v(eat),active).
     type(v(rest),passive).

becomes more efficient with:

     type(n(N),T) :- type_of_noun(N,T).
     type(v(V),T) :- type_of_verb(V,T).
     
     type_of_noun(mary,person).
     type_of_noun(john,person).
     type_of_noun(chair,object).
     
     type_of_verb(eat,active).
     type_of_verb(rest,passive).


File: yap.info,  Node: C-Interface,  Next: YapLibrary,  Prev: Efficiency,  Up: Top

C Language interface to YAP
***************************

YAP provides the user with the necessary facilities for writing
predicates in a language other than prolog. Since, under Unix systems,
most language implementations are link-able to C, we will describe here
only the YAP interface to the C language.

   Before describing in full detail how to interface to C code, we will
examine a brief example.

   Assume the user requires a predicate `my_process_id(Id)' which
succeeds when ID unifies with the number of the process under which YAP
is running.

   In this case we will create a `my_process.c' file containing the
C-code described below.

     #include "Yap/YapInterface.h"
     
     static int my_process_id(void)
     {
          YAP_Term pid = YAP_MkIntTerm(getpid());
          YAP_Term out = YAP_ARG1;
          return(YAP_Unify(out,pid));
     }
     
     void init_my_predicates()
     {
          YAP_UserCPredicate("my_process_id",my_process_id,1);
     }

   The commands to compile the above file depend on the operating
system. Under Linux (i386 and Alpha) you should use:
           gcc -c -shared -fPIC my_process.c
           ld -shared -o my_process.so my_process.o

Under Solaris2 it is sufficient to use:
           gcc  -fPIC -c my_process.c

Under SunOS it is sufficient to use:
           gcc -c my_process.c

Under Digital Unix you need to create a `so' file. Use:
           gcc tst.c -c -fpic
           ld my_process.o -o my_process.so -shared -expect_unresolved '*'

and replace my `process.so' for my `process.o' in the remainder of the
example.

And could be loaded, under YAP, by executing the following prolog goal
           load_foreign_files(['my_process'],[],init_my_predicates).
   Note that since Yap4.3.3 you should not give the suffix for object
files. YAP will deduce the correct suffix from the operating system it
is running under.

   Yap4.3.3 now supports loading WIN/NT DLLs. Currently you must compile
YAP under cygwin to create a library yap.dll first. You can then use
this dll to create your own dlls. Have a look at the code in
library/regex to see how to create a dll under the cygwin/mingw32
environment.

   After loading that file the following prolog goal
            my_process_id(N)

would unify N with the number of the process under which Yap is running.

   Having presented a full example, we will now examine in more detail
the contents of the C source code file presented above.

   The include statement is used to make available to the C source code
the macros for the handling of prolog terms and also some Yap public
definitions.

   The function `my_process_id' is the implementation, in C, of the
desired predicate.  Note that it returns an integer denoting the success
of failure of the goal and also that it has no arguments even though the
predicate being defined has one.   In fact the arguments of a prolog
predicate written in C are accessed through macros, defined in the
include file, with names YAP_ARG1, YAP_ARG2, ..., YAP_ARG16 or with
YAP_A(N) where N is the argument number (starting with 1).  In the
present case the function uses just one local variable of type
`YAP_Term', the type used for holding Yap terms, where the integer
returned by the standard unix function `getpid()' is stored as an
integer term (the conversion is done by `YAP_MkIntTerm(Int))'. Then it
calls the pre-defined routine `YAP_Unify(YAP_Term, YAP_Term)' which in
turn returns an integer denoting success or failure of the unification.

   The role of the procedure `init_my_predicates' is to make known to
YAP, by calling `YAP_UserCPredicate', the predicates being defined in
the file.  This is in fact why, in the example above,
`init_my_predicates' was passed as the third argument to
`load_foreign_files'.

   The rest of this appendix describes exhaustively how to interface C
to YAP.

* Menu:

* Manipulating Terms:: Primitives available to the C programmer
* Unifying Terms:: How to Unify Two Prolog Terms
* Manipulating Strings:: From character arrays to Lists of codes and back
* Memory Allocation:: Stealing Memory From Yap
* Controlling Streams:: Control How Yap sees Streams
* Calling Yap From C:: From C to Yap to C to Yap
* Writing C:: Writing Predicates in C
* Loading Objects:: Loading Object Files
* Sav&Rest:: Saving and Restoring
* Yap4 Notes:: Changes in Foreign Predicates Interface


File: yap.info,  Node: Manipulating Terms,  Next: Unifying Terms,  Up: C-Interface

Terms
=====

This section provides information about the primitives available to the
C programmer for manipulating prolog terms.

   Several C typedefs are included in the header file
`yap/YapInterface.h' to describe, in a portable way, the C
representation of prolog terms.  The user should write is programs
using this macros to ensure portability of code across different
versions of YAP.

   The more important typedef is YAP_TERM which is used to denote the
type of a prolog term.

   Terms, from a point of view of the C-programmer,  can be classified
as follows
uninstantiated variables

instantiated variables

integers

floating-point numbers

database references

atoms

pairs (lists)

compound terms

   The primitive
          YAP_Bool YAP_IsVarTerm(YAP_Term T)

returns true iff its argument is an uninstantiated variable. Conversely
the primitive
           YAP_Bool YAP_NonVarTerm(YAP_Term T)

returns true iff its argument is not a variable.

   The user can create a new uninstantiated variable using the primitive
           Term  YAP_MkVarTerm()

   The following primitives can be used to discriminate among the
different types of non-variable terms:
           YAP_Bool YAP_IsIntTerm(YAP_Term T)
           YAP_Bool YAP_IsFloatTerm(YAP_Term T)
           YAP_Bool YAP_IsDbRefTerm(YAP_Term T)
           YAP_Bool YAP_IsAtomTerm(YAP_Term T)
           YAP_Bool YAP_IsPairTerm(YAP_Term T)
           YAP_Bool YAP_IsApplTerm(YAP_Term T)

   Next, we mention the primitives that allow one to destruct and
construct terms. All the above primitives ensure that their result is
dereferenced, i.e. that it is not a pointer to another term.

   The following primitives are provided for creating an integer term
from an integer and to access the value of an integer term.
           YAP_Term YAP_MkIntTerm(YAP_Int  I)
           YAP_Int  YAP_IntOfTerm(YAP_YAP_Term T)

where `YAP_Int' is a typedef for the C integer type appropriate for the
machine or compiler in question (normally a long integer). The size of
the allowed integers is implementation dependent but is always greater
or equal to 24 bits: usually 32 bits on 32 bit machines, and 64 on 64
bit machines.

   The two following primitives play a similar role for floating-point
terms
           YAP_Term YAP_MkFloatTerm(YAP_flt DOUBLE)
           YAP_flt  YAP_FloatOfTerm(YAP_YAP_Term T)

where `flt' is a typedef for the appropriate C floating point type,
nowadays a `double'

   Currently, no primitives are supplied to users for manipulating data
base references.

   A special typedef `YAP_Atom' is provided to describe prolog atoms
(symbolic constants). The two following primitives can be used to
manipulate atom terms
           YAP_Term YAP_MkAtomTerm(YAP_Atom at)
           YAP_Atom YAP_AtomOfTerm(YAP_YAP_Term T)

The following primitives are available for associating atoms with their
names
           YAP_Atom  YAP_LookupAtom(char * S)
           YAP_Atom  YAP_FullLookupAtom(char * S)
           char     *YAP_AtomName(YAP_Atom T)
   The function `YAP_LookupAtom' looks up an atom in the standard hash
table. The function `YAP_FullLookupAtom' will also search if the atom
had been "hidden": this is useful for system maintenance from C code.
The functor `YAP_AtomName' returns a pointer to the string for the atom.

   A pair is a Prolog term which consists of a tuple of two prolog
terms designated as the head and the tail of the term. Pairs are most
often used to build _lists_. The following primitives can be used to
manipulate pairs:
           YAP_Term  YAP_MkPairTerm(YAP_Term HEAD, YAP_Term TAIL)
           YAP_Term  YAP_MkNewPairTerm(void)
           YAP_Term  YAP_HeadOfTerm(YAP_Term T)
           YAP_Term  YAP_TailOfTerm(YAP_Term T)
   One can construct a new pair from two terms, or one can just build a
pair whose head and tail are new unbound variables. Finally, one can
fetch the head or the tail.

   A compound term consists of a functor and a sequence of terms with
length equal to the arity of the functor. A functor, described in C by
the typedef `Functor', consists of an atom and of an integer.  The
following primitives were designed to manipulate compound terms and
functors
           YAP_Term     YAP_MkApplTerm(YAP_Functor F, unsigned long int N, YAP_Term[] ARGS)
           YAP_Term     YAP_MkNewApplTerm(YAP_Functor F, int N)
           YAP_Term     YAP_ArgOfTerm(int argno,YAP_Term TS)
           YAP_Functor  YAP_FunctorOfTerm(YAP_YAP_Term TS)

The `YAP_MkApplTerm' function constructs a new term, with functor F (of
arity N), and using an array ARGS of N terms with N equal to the arity
of the functor. `YAP_MkNewApplTerm' builds up a compound term whose
arguments are unbound variables. `YAP_ArgOfTerm' gives an argument to a
compound term. `argno' should be greater or equal to 1 and less or
equal to the arity of the functor.

   YAP allows one to manipulate the functors of compound term. The
function `YAP_FunctorOfTerm' allows one to obtain a variable of type
`YAP_Functor' with the functor to a term. The following functions then
allow one to construct functors, and to obtain their name and arity.

           YAP_Functor  YAP_MkFunctor(YAP_Atom A,unsigned long int ARITY)
           YAP_Atom     YAP_NameOfFunctor(YAP_Functor F)
           YAP_Int      YAP_ArityOfFunctor(YAP_Functor F)

Note that the functor is essentially a pair formed by an atom, and
arity.


File: yap.info,  Node: Unifying Terms,  Next: Manipulating Strings,  Prev: Manipulating Terms,  Up: C-Interface

Unification
===========

YAP provides a single routine to attempt the unification of two prolog
terms. The routine may succeed or fail:
           Int      YAP_Unify(YAP_Term A, YAP_Term B)

The routine attempts to unify the terms A and B returning `TRUE' if the
unification succeeds and `FALSE' otherwise.


File: yap.info,  Node: Manipulating Strings,  Next: Memory Allocation,  Prev: Unifying Terms,  Up: C-Interface

Strings
=======

The YAP C-interface now includes an utility routine to copy a string
represented as a list of a character codes to a previously allocated
buffer
           int YAP_StringToBuffer(YAP_Term STRING, char *BUF, unsigned int BUFSIZE)

The routine copies the list of character codes STRING to a previously
allocated buffer BUF. The string including a terminating null character
must fit in BUFSIZE characters, otherwise the routine will simply fail.
The STRINGTOBUFFER routine fails and generates an exception if STRING
is not a valid string.

   The C-interface also includes utility routines to do the reverse,
that is, to copy a from a buffer to a list of character codes or to a
list of character atoms
           YAP_Term YAP_BufferToString(char *BUF)
           YAP_Term YAP_BufferToAtomList(char *BUF)

The user-provided string must include a terminating null character.


File: yap.info,  Node: Memory Allocation,  Next: Controlling Streams,  Prev: Manipulating Strings,  Up: C-Interface

Memory Allocation
=================

The next routine can be used to ask space from the Prolog data-base:
           void      *YAP_AllocSpaceFromYap(int SIZE)

The routine returns a pointer to a buffer allocated from the code area,
or `NULL' if sufficient space was not available.

   The space allocated with `YAP_AllocSpaceFromYap' can be released
back to Yap by using:
           void      YAP_FreeSpaceFromYap(void *BUF)

The routine releases a buffer allocated from the code area. The system
may crash if `buf' is not a valid pointer to a buffer in the code area.


File: yap.info,  Node: Controlling Streams,  Next: Calling Yap From C,  Prev: Memory Allocation,  Up: C-Interface

Controlling Yap Streams from `C'
================================

The C-Interface also provides the C-application with a measure of
control over the Yap Input/Output system. The first routine allows one
to find a file number given a current stream:
           int      YAP_StreamToFileNo(YAP_Term STREAM)

This function gives the file descriptor for a currently available
stream. Note that null streams and in memory streams do not have
corresponding open streams, so the routine will return a negative.
Moreover, Yap will not be aware of any direct operations on this
stream, so information on, say, current stream position, may become
stale.

   A second routine that is sometimes useful is:
           void      YAP_CloseAllOpenStreams(void)

This routine closes the Yap Input/Output system except for the first
three streams, that are always associated with the three standard Unix
streams. It is most useful if you are doing `fork()'.

   The next routine allows a currently open file to become a stream. The
routine receives as arguments a file descriptor, the true file name as a
string, an atom with the user name, and a set of flags:
           void      YAP_OpenStream(void *FD, char *NAME, YAP_Term T, int FLAGS)

The available flags are `YAP_INPUT_STREAM', `YAP_OUTPUT_STREAM',
`YAP_APPEND_STREAM', `YAP_PIPE_STREAM', `YAP_TTY_STREAM',
`YAP_POPEN_STREAM', `YAP_BINARY_STREAM', and `YAP_SEEKABLE_STREAM'. By
default, the stream is supposed to be at position 0. The argument NAME
gives the name by which YAP should know the new stream.


File: yap.info,  Node: Calling Yap From C,  Next: Writing C,  Prev: Controlling Streams,  Up: C-Interface

From `C' back to Prolog
=======================

Newer versions of YAP allow for calling the Prolog interpreter from
`C'. One must first construct a goal `G', and then it is sufficient to
perform:
           YAP_Bool      YapCallProlog(YAP_Term G)

the result will be `FALSE', if the goal failed, or `TRUE', if the goal
succeeded. In this case, the variables in G will store the values they
have been unified with. Execution only proceeds until finding the first
solution to the goal, but you can call `findall/3' or friends if you
need all the solutions.


File: yap.info,  Node: Writing C,  Next: Loading Objects,  Prev: Calling Yap From C,  Up: C-Interface

Writing predicates in C
=======================

We will distinguish two kinds of predicates:
deterministic predicates which either fail or succeed but are not
     backtrackable, like the one in the introduction;

backtrackable
     predicates which can succeed more than once.

   The first kind of predicates should be implemented as a C function
with no arguments which should return zero if the predicate fails and a
non-zero value otherwise. The predicate should be declared to YAP, in
the initialization routine, with a call to
           void YAP_UserCPredicate(char *NAME, YAP_Bool *FN(), unsigned long int ARITY);

where NAME is the name of the predicate, FN is the C function
implementing the predicate and ARITY is its arity.

   For the second kind of predicates we need two C functions. The first
one which is called when the predicate is first activated, and the
second one to be called on backtracking to provide (possibly) other
solutions. Note also that we normally also need to preserve some
information to find out the next solution.

   In fact the role of the two functions can be better understood from
the following prolog definition
            p :- start.
            p :- repeat,
                     continue.

where `start' and `continue' correspond to the two C functions
described above.

   As an example we will consider implementing in C a predicate
`n100(N)' which, when called with an instantiated argument should
succeed if that argument is a numeral less or equal to 100, and, when
called with an uninstantiated argument, should provide, by
backtracking, all the positive integers less or equal to 100.

   To do that we first declare a structure, which can only consist of
prolog terms, containing the information to be preserved on backtracking
and a pointer variable to a structure of that type.

     typedef struct {
         YAP_Term next_solution;  /* the next solution */
        } n100_data_type;
     
     n100_data_type *n100_data;

   We now write the `C' function to handle the first call:

     static int start_n100()
     {
           YAP_Term t = ARG1;
           YAP_PRESERVE_DATA(n100_data,n100_data_type);
           if(YAP_IsVarTerm(t)) {
               n100_data->next_solution = YAP_MkIntTerm(0);
               return(continue_n100());
            }
           if(!YAP_IsIntTerm(t) || YAP_IntOfTerm(t)<0 || YAP_IntOfTerm(t)>100) {
               YAP_cut_fail();
           } else {
               YAP_cut_succeed();
           }
     }

   The routine starts by getting the dereference value of the argument.
The call to `YAP_PRESERVE_DATA' is used to initialize the memory which
will hold the information to be preserved across backtracking. The first
argument is the variable we shall use, and the second its type. Note
that we can only use `YAP_PRESERVE_DATA' once, so often we will want
the variable to be a structure.

   If the argument of the predicate is a variable, the routine
initializes the structure to be preserved across backtracking with the
information required to provide the next solution, and exits by calling
` continue_n100' to provide that solution.

   If the argument was not a variable, the routine then checks if it was
an integer, and if so, if its value is positive and less than 100. In
that case it exits, denoting success, with `YAP_cut_succeed', or
otherwise exits with `YAP_cut_fail' denoting failure.

   The reason for using for using the functions `YAP_cut_succeed' and
`YAP_cut_fail' instead of just returning a non-zero value in the first
case, and zero in the second case, is that otherwise, if backtracking
occurred later, the routine `continue_n100' would be called to provide
additional solutions.

   The code required for the second function is
     static int continue_n100()
     {
           int n;
           Term t;
           Term sol = ARG1;
           YAP_PRESERVED_DATA(n100_data,n100_data_type);
           n = YAP_IntOfTerm(n100_data->next_solution);
           if( n == 100) {
                t = YAP_MkIntTerm(n);
                YAP_Unify(&sol,&t);
                YAP_cut_succeed();
             }
            else {
                YAP_Unify(&sol,&(n100_data->next_solution));
                n100_data->next_solution = YAP_MkIntTerm(n+1);
                return(TRUE);
             }
     }

   Note that again the macro `YAP_PRESERVED_DATA' is used at the
beginning of the function to access the data preserved from the previous
solution.  Then it checks if the last solution was found and in that
case exits with `YAP_cut_succeed' in order to cut any further
backtracking.  If this is not the last solution then we save the value
for the next solution in the data structure and exit normally with 1
denoting success. Note also that in any of the two cases we use the
function `YAP_unify' to bind the argument of the call to the value
saved in ` n100_state->next_solution'.

   Note also that the only correct way to signal failure in a
backtrackable predicate is to use the `YAP_cut_fail' macro.

   Backtrackable predicates should be declared to YAP, in a way similar
to what happened with deterministic ones, but using instead a call to
           void YAP_UserBackCPredicate(char *NAME,
                      int *INIT(), int *CONT(),
                      unsigned long int ARITY, unsigned int SIZEOF);

where NAME is a string with the name of the predicate, INIT and CONT
are the C functions used to start and continue the execution of the
predicate, ARITY is the predicate arity, and SIZEOF is the size of the
data to be preserved in the stack.


File: yap.info,  Node: Loading Objects,  Next: Sav&Rest,  Prev: Writing C,  Up: C-Interface

Loading Object Files
====================

The primitive predicate
           load_foreign_files(FILES,LIBS,INITROUTINE)

should be used, from inside YAP, to load object files produced by the C
compiler. The argument OBJECTFILES should be a list of atoms specifying
the object files to load, LIBS is a list (possibly empty) of libraries
to be passed to the unix loader (`ld') and InitRoutine is the name of
the C routine (to be called after the files are loaded) to perform the
necessary declarations to YAP of the predicates defined in the files.

   YAP will search for OBJECTFILES in the current directory first. If
it cannot find them it will search for the files using the environment
variable `YAPLIBDIR', if defined, or in the default library.

   In a.out systems YAP by default only reserves a fixed amount of
memory for object code (64 Kbytes in the current version). Should this
size prove inadequate the flag `-c n' can be passed to YAP (in the
command line invoking YAP) to force the allocation of `n' Kbytes.


File: yap.info,  Node: Sav&Rest,  Next: Yap4 Notes,  Prev: Loading Objects,  Up: C-Interface

Saving and Restoring
====================

Yap4 currently does not support `save' and `restore' for object code
loaded with `load_foreign_files'. We plan to support save and restore
in future releases of Yap.


File: yap.info,  Node: Yap4 Notes,  Prev: Sav&Rest,  Up: C-Interface

Changes to the C-Interface in Yap4
==================================

Yap4 includes several changes over the previous `load_foreign_files'
interface. These changes were required to support the new binary code
formats, such as ELF used in Solaris2 and Linux.
   * All Names of YAP objects now start with YAP_. This is designed to
     avoid clashes with other code. Use `YapInterface.h' to take
     advantage of the new interface. `c_interface.h' is still available
     if you cannot port the code to the new interface.

   * Access to elements in the new interface always goes through
     _functions_. This includes access to the argument registers,
     `YAP_ARG1' to `YAP_ARG16'. This change breaks code such as
     `unify(&ARG1,&t)', which is nowadays:
          {
             YAP_Unify(ARG1, t);
          }

   * `cut_fail()' and `cut_succeed()' are now functions.

   * The use of `Deref' is deprecated. All functions that return Prolog
     terms, including the ones that access arguments, already
     dereferenciate their arguments.

   * Space allocated with PRESERVE_DATA is ignored by garbage
     collection and stack shifting. As a result, any pointers to a
     Prolog stack object, including some terms, may be corrupted after
     garbage collection or stack shifting. Prolog terms should instead
     be stored as arguments to the backtrackable procedure.



File: yap.info,  Node: YapLibrary,  Next: Compatibility,  Prev: C-Interface,  Up: Top

Using YAP as a Library
**********************

YAP can be used as a library to be called from other programs. To do
so, you must first create the YAP library:
     make library
     make install_library
   This will install a file `libyap.a' in LIBDIR and the Prolog headers
in INCLUDEDIR. The library contains all the functionality available in
YAP, except the foreign function loader and for `Yap''s startup
routines.

   To actually use this library you must follow a five step process:

  1.  You must initialize the YAP environment. A single function,
     `YAP_FastInit' asks for a contiguous chunk in your memory space,
     fills it in with the data-base, and sets up YAP's stacks and
     execution registers. You can use a saved space from a standard
     system by calling `save_program/1'.

  2. You then have to prepare a query to give to YAP. A query is a
     Prolog term, and you just have to use the same functions that are
     available in the C-interface.

  3. You can then use `YAP_RunGoal(query)' to actually evaluate your
     query. The argument is the query term `query', and the result is 1
     if the query succeeded, and 0 if it failed.

  4. You can use the term destructor functions to check how arguments
     were instantiated.

  5. If you want extra solutions, you can use `YAP_RestartGoal()' to
     obtain the next solution.


   The next program shows how to use this system. We assume the saved
program contains two facts for the procedure b:

     #include <stdio.h>
     #include "Yap/YapInterface.h"
     
     
     int
     main(int argc, char *argv[]) {
       if (YAP_FastInit("saved_state") == YAP_BOOT_FROM_SAVED_ERROR)
         exit(1);
       if (YAP_RunGoal(YAP_MkAtomTerm(YAP_LookupAtom("do")))) {
         printf("Success\n");
         while (YAP_RestartGoal())
           printf("Success\n");
       }
       printf("NO\n");
     }

   The program first initializes YAP, calls the query for the first
time and succeeds, and then backtracks twice. The first time
backtracking succeeds, the second it fails and exits.

   To compile this program it should be sufficient to do:

     cc -o exem -I../Yap4.3.0 test.c -lYap -lreadline -lm

   You may need to adjust the libraries and library paths depending on
the Operating System and your installation of Yap.

   Note that Yap4.3.0 provides the first version of the interface. The
interface may change and improve in the future.

   The following C-functions are available from Yap:

   * YapCompileClause(`Term' CLAUSE) Compile the Prolog term CLAUSE and
     assert it as the last clause for the corresponding procedure.

   * `int' YapContinueGoal(`void') Continue execution from the point
     where it stopped.

   * `void' YapError(`char *' ERROR_DESCRIPTION) Generate an YAP System
     Error with description given by the string ERROR_DESCRIPTION.

   * `void' YapExit(`int' EXIT_CODE) Exit YAP immediately. The argument
     EXIT_CODE gives the error code and is supposed to be 0 after
     successful execution in Unix and Unix-like systems.

   * `Term' YapGetValue(`Atom' AT) Return the term VALUE associated
     with the atom AT. If no such term exists the function will return
     the empty list.

   * YapFastInit(`char *' SAVEDSTATE) Initialize a copy of YAP from
     SAVEDSTATE. The copy is monolithic and currently must be loaded at
     the same address where it was saved. `YapFastInit' is a simpler
     version of `YapInit'.

   * YapInit(`char *' SAVEDSTATE,  `int' HEAPSIZE, `int' STACKSIZE,
     `int' TRAILSIZE, `int'  NUMBEROFWORKERS, `int' SCHEDULERLOOP,
     `int' DELAYEDRELEASELOAD, `int' ARGC, `char **'  ARGV) Initialize
     YAP. In the future the arguments as a single `C' structure.

     If SAVEDSTATE is not NULL, try to open and restore the file
     SAVEDSTATE. Initially YAP will search in the current directory. If
     the saved state does not exist in the current directory YAP will
     use either the default library directory or the directory given by
     the environment variable `YAPLIBDIR'. Note that currently the
     saved state must be loaded at the same address where it was saved.

     If HEAPSIZE is different from 0 use HEAPSIZE as the minimum size
     of the Heap (or code space). If STACKSIZE is different from 0 use
     HEAPSIZE as the minimum size for the Stacks. If TRAILSIZE is
     different from 0 use TRAILSIZE as the minimum size for the Trails.

     The NUMBEROFWORKERS, NUMBEROFWORKERS, and DELAYEDRELEASELOAD are
     only of interest to the or-parallel system.

     The argument count ARGC and string of arguments ARGV arguments are
     to be passed to user programs as the arguments used to call YAP.

   * `void' YapPutValue(`Atom' AT, `Term' VALUE) Associate the term
     VALUE with the atom AT. The term VALUE must be a constant. This
     functionality is used by YAP as a simple way for controlling and
     communicating with the Prolog run-time.

   * `Term' YapRead(`int (*)(void)' GETC) Parse a Term  using the
     function GETC to input characters.

   * `int' YapRunGoal(`Term' GOAL) Execute query GOAL and return 1 if
     the query succeeds, and 0 otherwise.

   * `int' YapRestartGoal(`void') Look for the next solution to the
     current query by forcing YAP to backtrack.

   * `int' YapReset(`void') Reset execution environment (similar to the
     `abort/0' builtin). This is useful when you want to start a new
     query before asking all solutions to the previous query.

   * `void' YapWrite(`Term' T, `void (*)(int)' PUTC, `int' FLAGS) Write
     a Term T using the function PUTC to output characters. The term is
     written according to a mask of the following flags in the `flag'
     argument: `YAP_WRITE_QUOTED', `YAP_WRITE_HANDLE_VARS',  and
     `YAP_WRITE_IGNORE_OPS'.

   * `void' YapInitConsult(`int' MODE, `char *' FILENAME) Enter consult
     mode on file FILENAME. This mode maintains a few data-structures
     internally, for instance to know whether a predicate before or
     not. It is still possible to execute goals in consult mode.

     If MODE is `TRUE' the file will be reconsulted, otherwise just
     consulted. In practice, this function is most useful for
     bootstrapping Prolog, as otherwise one may call the Prolog
     predicate `compile/1' or `consult/1' to do compilation.

     Note that it is up to the user to open the file FILENAME. The
     `YapInitConsult' function only uses the file name for internal
     bookkeeping.

   * `void' YapEndConsult(`void') Finish consult mode.


   Some observations:

   * The system will core dump if you try to load the saved state in a
     different address from where it was made. This may be a problem if
     your program uses `mmap'. This problem will be addressed in future
     versions of YAP.

   * Currently, the YAP library will pollute the name space for your
     program.

   * The initial library includes the complete YAP system. In the
     future we plan to split this library into several smaller libraries
     (e.g., if you do not want to perform I/O).

   * You can generate your own saved states. Look at  the `boot.yap'
     and `init.yap' files.



File: yap.info,  Node: Compatibility,  Next: Operators,  Prev: YapLibrary,  Up: Top

Compatibility with Other Prolog systems
***************************************

YAP has been designed to be as compatible as possible with other Prolog
systems, and initially with C-Prolog. More recent work on YAP has
included features initially proposed for the Quintus and SICStus Prolog
systems.

   Developments since `Yap4.1.6' we have striven at making YAP
compatible with the ISO-Prolog standard.

* Menu:

* C-Prolog:: Compatibility with the C-Prolog interpreter
* SICStus Prolog:: Compatibility with the SICStus Prolog system
* ISO Prolog::  Compatibility with the ISO Prolog standard


File: yap.info,  Node: C-Prolog,  Next: SICStus Prolog,  Up: Compatibility

Compatibility with the C-Prolog interpreter
===========================================

* Menu:

C-Prolog Compatibility
* Major Differences with C-Prolog:: Major Differences between YAP and C-Prolog
* Fully C-Prolog Compatible:: Yap predicates fully compatible with
C-Prolog
* Not Strictly C-Prolog Compatible:: Yap predicates not strictly as C-Prolog
* Not in C-Prolog:: Yap predicates not available in C-Prolog
* Not in YAP:: C-Prolog predicates not available in YAP


File: yap.info,  Node: Major Differences with C-Prolog,  Next: Fully C-Prolog Compatible,  Up: C-Prolog

Major Differences between YAP and C-Prolog.
-------------------------------------------

YAP includes several extensions over the original C-Prolog system. Even
so, most C-Prolog programs should run under YAP without changes.

   The most important difference between YAP and C-Prolog is that, being
YAP a compiler, some changes should be made if predicates such as
`assert', `clause' and `retract' are used. First predicates which will
change during execution should be declared as `dynamic' by using
commands like:

     :- dynamic f/n.

where `f' is the predicate name and n is the arity of the predicate.
Note that  several such predicates can be declared in a single command:
      :- dynamic f/2, ..., g/1.

   Primitive predicates such as `retract' apply only to dynamic
predicates.  Finally note that not all the C-Prolog primitive predicates
are implemented in YAP. They can easily be detected using the `unknown'
system predicate provided by YAP.

   Last, by default YAP enables character escapes in strings. You can
disable the special interpretation for the escape character by using:
     `:- yap_flag(character_escapes,off).'

or by using:
     `:- yap_flag(language,cprolog).'


File: yap.info,  Node: Fully C-Prolog Compatible,  Next: Not Strictly C-Prolog Compatible,  Prev: Major Differences with C-Prolog,  Up: C-Prolog

Yap predicates fully compatible with C-Prolog
---------------------------------------------

These are the Prolog built-ins that are fully compatible in both
C-Prolog and YAP:

* Menu:

* !/0:                                   Control.
* ,/2:                                   Control.
* ;/2:                                   Control.
* </2:                                   Arithmetic.
* =../2:                                 Testing Terms.
* =:=/2:                                 Arithmetic.
* =</2:                                  Arithmetic.
* ==/2:                                  Comparing Terms.
* =\=/2:                                 Arithmetic.
* >/2:                                   Arithmetic.
* >=/2:                                  Arithmetic.
* @</2:                                  Comparing Terms.
* @>/2:                                  Comparing Terms.
* @>=/2:                                 Comparing Terms.
* [-]/1:                                 Compiling.
* []/1:                                  Compiling.
* \+/1:                                  Control.
* \==/2:                                 Comparing Terms.
* abort/0:                               Control.
* atom/1:                                Testing Terms.
* atomic/1:                              Testing Terms.
* bagof/3:                               Sets.
* break/0:                               Control.
* call/1:                                Control.
* close/1:                               Streams and Files.
* compare/3:                             Comparing Terms.
* consult/1:                             Compiling.
* current_atom/1:                        Looking at the Database.
* current_predicate/1:                   Looking at the Database.
* db_reference/1:                        Testing Terms.
* debug/0:                               Deb Preds.
* debugging/0:                           Deb Preds.
* display/1:                             I/O of Terms.
* erase/1:                               Internal Database.
* erased/1:                              Internal Database.
* exists/1:                              I/O Control.
* expand_exprs/2:                        Setting the Compiler.
* expand_term/2:                         Grammars.
* fail/0:                                Control.
* fileerrors/0:                          I/O Control.
* findall/3:                             Sets.
* functor/3:                             Testing Terms.
* get/1:                                 I/O of Characters.
* get0/1:                                I/O of Characters.
* halt/0:                                Control.
* instance/2:                            Internal Database.
* integer/1:                             Testing Terms.
* keysort/2:                             Comparing Terms.
* leash/1:                               Deb Preds.
* length/2:                              Comparing Terms.
* name/2:                                Testing Terms.
* nl/0:                                  I/O of Characters.
* nodebug/0:                             Deb Preds.
* nofileerrors/0:                        I/O Control.
* nonvar/1:                              Testing Terms.
* nospy/1:                               Deb Preds.
* not/1:                                 Control.
* number/1:                              Testing Terms.
* op/3:                                  Misc.
* primitive/1:                           Testing Terms.
* print/1:                               I/O of Terms.
* prompt/2:                              Misc.
* put/1:                                 I/O of Characters.
* read/1:                                I/O of Terms.
* reconsult/1:                           Compiling.
* recorda/3:                             Internal Database.
* recorded/3:                            Internal Database.
* recordz/3:                             Internal Database.
* rename/2:                              OS.
* repeat/0:                              Control.
* save/1:                                Saving.
* see/1:                                 C-Prolog File Handling.
* seeing/1:                              C-Prolog File Handling.
* seen/0:                                C-Prolog File Handling.
* setof/3:                               Sets.
* sh/0:                                  OS.
* skip/1:                                I/O of Characters.
* sort/2:                                Comparing Terms.
* spy/1:                                 Deb Preds.
* statistics/0:                          Misc.
* system/1:                              OS.
* tab/1:                                 I/O of Characters.
* tell/1:                                C-Prolog File Handling.
* telling/1:                             C-Prolog File Handling.
* term_expansion/2:                      Grammars.
* told/0:                                C-Prolog File Handling.
* true/0:                                Control.
* var/1:                                 Testing Terms.
* write/1:                               I/O of Terms.
* writeq/1:                              I/O of Terms.


File: yap.info,  Node: Not Strictly C-Prolog Compatible,  Next: Not in C-Prolog,  Prev: Fully C-Prolog Compatible,  Up: C-Prolog

Yap predicates not strictly compatible with C-Prolog
----------------------------------------------------

These are YAP built-ins that are also available in C-Prolog, but that
are not fully compatible:

* Menu:

* abolish/1:                             Modifying the Database.
* abolish/2:                             Modifying the Database.
* assert/1:                              Modifying the Database.
* assert/2:                              Database References.
* asserta/1:                             Modifying the Database.
* asserta/2:                             Database References.
* assertz/1:                             Modifying the Database.
* assertz/2:                             Database References.
* clause/2:                              Modifying the Database.
* clause/3:                              Modifying the Database.
* is/2:                                  Arithmetic.
* listing/0:                             Looking at the Database.
* listing/1:                             Looking at the Database.
* nth_clause/3:                          Modifying the Database.
* retract/2:                             Database References.


File: yap.info,  Node: Not in C-Prolog,  Next: Not in YAP,  Prev: Not Strictly C-Prolog Compatible,  Up: C-Prolog

Yap predicates not available in C-Prolog
----------------------------------------

These are YAP built-ins not available in C-Prolog.

* Menu:

* ->/2:                                  Control.
* =/2:                                   Testing Terms.
* \=/2:                                  Testing Terms.
* absolute_file_name/2:                  Streams and Files.
* add_edges/3:                           UGraphs.
* add_to_array_element/4:                Arrays.
* add_to_heap/4:                         Heaps.
* add_vertices/3:                        UGraphs.
* alarm/3:                               OS.
* all/3:                                 Sets.
* always_prompt_user/0:                  I/O Control.
* append/3:                              Lists.
* arg/3:                                 Testing Terms.
* array/2:                               Arrays.
* array_element/3:                       Arrays.
* assert_static/1:                       Modifying the Database.
* asserta_static/1:                      Modifying the Database.
* assertz_static/1:                      Modifying the Database.
* assoc_to_list/2:                       Association Lists.
* at_end_of_stream/0:                    Streams and Files.
* at_end_of_stream/1:                    Streams and Files.
* atom_chars/2:                          Testing Terms.
* atom_codes/2:                          Testing Terms.
* atom_concat/2:                         Testing Terms.
* atom_concat/3:                         Testing Terms.
* atom_length/2:                         Testing Terms.
* atom_to_chars/2:                       String I/O.
* atom_to_chars/3:                       String I/O.
* attribute_goal/2:                      Displaying Attributes.
* avl_insert/4:                          AVL Trees.
* avl_lookup/3:                          AVL Trees.
* bb_delete/2:                           BlackBoard.
* bb_get/2:                              BlackBoard.
* bb_put/2:                              BlackBoard.
* bb_update/3:                           BlackBoard.
* C/3:                                   Grammars.
* call_cleanup/1:                        Cleanup.
* call_cleanup/2:                        Cleanup.
* call_count_data/0:                     Call Counting.
* call_count_data/3:                     Call Counting.
* call_residue/2:                        Coroutining.
* call_with_args/n:                      Control.
* callable/1:                            Testing Terms.
* catch/3:                               Control.
* cd/1:                                  OS.
* char_code/2:                           Testing Terms.
* char_conversion/2:                     I/O of Terms.
* checklist/2:                           Apply Macros.
* checknodes/3:                          Apply Macros.
* cleanup_all/0:                         Cleanup.
* close/2:                               Streams and Files.
* close_static_array/1:                  Arrays.
* compile/1:                             Compiling.
* compile/1 (directive):                 Compiling.
* compile_expressions/0:                 Setting the Compiler.
* complement/2:                          UGraphs.
* compose/3:                             UGraphs.
* compound/1:                            Testing Terms.
* convlist/3:                            Apply Macros.
* copy_term/2:                           Testing Terms.
* create_mutable/2:                      Term Modification.
* current_char_conversion/2:             I/O of Terms.
* current_input/1:                       Streams and Files.
* current_key/2:                         Internal Database.
* current_module/1:                      Preds.
* current_module/2:                      Preds.
* current_mutex/3:                       Thread Synchronisation.
* current_op/3:                          Misc.
* current_output/1:                      Streams and Files.
* current_predicate/2:                   Looking at the Database.
* current_prolog_flag/2:                 Misc.
* current_stream/3:                      Streams and Files.
* current_thread/2:                      Monitoring Threads.
* cyclic_term/1:                         Terms.
* datime/1:                              System.
* del_vertices/3:                        UGraphs.
* delete/3 <1>:                          Red-Black Trees.
* delete/3:                              Lists.
* delete_file/1:                         System.
* delete_file/2:                         System.
* dif/2:                                 Coroutining.
* directory_files/2:                     System.
* discontiguous/1 (directive):           Setting the Compiler.
* display/1 <1>:                         I/O for Streams.
* display/1:                             I/O of Terms.
* display/2:                             I/O for Streams.
* do_not_compile_expressions/0:          Setting the Compiler.
* dynamic/1:                             Database.
* dynamic_predicate/2:                   Database.
* empty_assoc/1:                         Association Lists.
* empty_heap/1:                          Heaps.
* empty_queue/1:                         Queues.
* environ/2 <1>:                         System.
* environ/2:                             OS.
* eraseall/1:                            Internal Database.
* exec/3:                                System.
* false/0:                               Control.
* file_exists/1:                         System.
* file_exists/2:                         System.
* file_property/2:                       System.
* file_search_path/2:                    Setting the Compiler.
* findall/4:                             Sets.
* flatten/2:                             Lists.
* float/1:                               Testing Terms.
* flush_output/0:                        Streams and Files.
* flush_output/1:                        Streams and Files.
* format/2:                              I/O of Terms.
* format/3:                              I/O of Terms.
* format_to_chars/3:                     String I/O.
* format_to_chars/4:                     String I/O.
* fragile:                               Cleanup.
* freeze/2:                              Coroutining.
* frozen/2:                              Coroutining.
* garbage_collect/0:                     Control.
* garbage_collect_atoms/0:               Control.
* gc/0:                                  Control.
* gen_assoc/3:                           Association Lists.
* get/2:                                 I/O for Streams.
* get0/2:                                I/O for Streams.
* get_assoc/3:                           Association Lists.
* get_assoc/5:                           Association Lists.
* get_atts/2:                            Attribute Manipulation.
* get_byte/1:                            I/O of Characters.
* get_byte/2:                            I/O for Streams.
* get_char/1:                            I/O of Characters.
* get_char/2:                            I/O for Streams.
* get_code/1:                            I/O of Characters.
* get_code/2:                            I/O for Streams.
* get_from_heap/4:                       Heaps.
* get_label/3:                           Trees.
* get_mutable/2:                         Term Modification.
* get_value/2:                           Internal Database.
* getcwd/1:                              OS.
* getrand/1:                             Random.
* goal_expansion/3:                      Grammars.
* ground/1:                              Testing Terms.
* grow_heap/1:                           Control.
* grow_stack/1:                          Control.
* halt/1:                                Control.
* head_queue/2:                          Queues.
* heap_size/2:                           Heaps.
* heap_to_list/2:                        Heaps.
* hide/1:                                Setting the Compiler.
* hide_predicate/1:                      Setting the Compiler.
* host_id/1:                             System.
* host_name/1:                           System.
* if/3:                                  Control.
* incore/1:                              Control.
* initialization/0:                      Misc.
* initialization/1 (directive):          Setting the Compiler.
* insert/4:                              Red-Black Trees.
* is_list/1:                             Lists.
* is_mutable/1:                          Term Modification.
* join_queue/3:                          Queues.
* jump_queue/3:                          Queues.
* key_statistics/3:                      Internal Database.
* key_statistics/4:                      Internal Database.
* kill/2:                                System.
* last/2:                                Lists.
* length_queue/2:                        Queues.
* library_directory/1:                   Setting the Compiler.
* list_concat/2:                         Lists.
* list_join_queue/3:                     Queues.
* list_jump_queue/3:                     Queues.
* list_to_assoc/2:                       Association Lists.
* list_to_heap/2:                        Heaps.
* list_to_ord_set/2:                     Ordered Sets.
* list_to_queue/2:                       Queues.
* list_to_tree/2:                        Trees.
* lookup/3:                              Red-Black Trees.
* make_directory/2:                      System.
* make_queue/1:                          Queues.
* map_assoc/3:                           Association Lists.
* map_tree/3:                            Trees.
* mapargs/3:                             Apply Macros.
* maplist/3:                             Apply Macros.
* mapnodes/3:                            Apply Macros.
* member/2:                              Lists.
* memberchk/2:                           Lists.
* merge/3:                               Ordered Sets.
* meta_predicate/1 (directive):          Meta-Predicates in Modules.
* min_of_heap/3:                         Heaps.
* min_of_heap/5:                         Heaps.
* mktemp/2:                              System.
* module/1:                              Defining Modules.
* module/2 (directive):                  Defining Modules.
* module/3 (directive):                  Defining Modules.
* multifile/1 (directive):               Setting the Compiler.
* mutex_create/1:                        Thread Synchronisation.
* mutex_destroy/1:                       Thread Synchronisation.
* mutex_lock/1:                          Thread Synchronisation.
* mutex_statistics/0:                    Monitoring Threads.
* mutex_trylock/1:                       Thread Synchronisation.
* mutex_unlock/1:                        Thread Synchronisation.
* mutex_unlock_all/0:                    Thread Synchronisation.
* neighbors/3:                           UGraphs.
* neighbours/3:                          UGraphs.
* new/1:                                 Red-Black Trees.
* nl/1:                                  I/O for Streams.
* no_source/0:                           Setting the Compiler.
* nogc/0:                                Control.
* nospyall/0:                            Deb Preds.
* nth/2:                                 Lists.
* nth/4:                                 Lists.
* nth0/2:                                Lists.
* nth0/4:                                Lists.
* nth_recorded/3:                        Internal Database.
* number_atom/2:                         Testing Terms.
* number_chars/2:                        Testing Terms.
* number_codes/2:                        Testing Terms.
* number_to_chars/2:                     String I/O.
* number_to_chars/3:                     String I/O.
* numbervars/3:                          Testing Terms.
* on_cleanup/1:                          Cleanup.
* on_signal/3:                           OS.
* once/1:                                Control.
* open/3:                                Streams and Files.
* open/4:                                Streams and Files.
* open_chars_stream/2:                   String I/O.
* ord_add_element/3:                     Ordered Sets.
* ord_del_element/3:                     Ordered Sets.
* ord_disjoint/2:                        Ordered Sets.
* ord_insert/3:                          Ordered Sets.
* ord_intersect/2:                       Ordered Sets.
* ord_intersect/3:                       Ordered Sets.
* ord_list_to_assoc/2:                   Association Lists.
* ord_member/2:                          Ordered Sets.
* ord_seteq/2:                           Ordered Sets.
* ord_setproduct/3:                      Ordered Sets.
* ord_subtract/3:                        Ordered Sets.
* ord_symdiff/3:                         Ordered Sets.
* ord_union/2:                           Ordered Sets.
* ord_union/3:                           Ordered Sets.
* ord_union/4:                           Ordered Sets.
* ordsubset/2:                           Ordered Sets.
* path/1:                                Setting the Compiler.
* peek_byte/1:                           I/O of Characters.
* peek_byte/2:                           I/O for Streams.
* peek_char/1:                           I/O of Characters.
* peek_char/2:                           I/O for Streams.
* peek_code/1:                           I/O of Characters.
* peek_code/2:                           I/O for Streams.
* permutation/2:                         Lists.
* phrase/2:                              Grammars.
* phrase/3:                              Grammars.
* pid/1:                                 System.
* popen/3:                               System.
* portray_clause/1:                      Looking at the Database.
* portray_clause/2:                      Looking at the Database.
* predicate_property/2:                  Looking at the Database.
* print/2:                               I/O for Streams.
* profile_data/3:                        Profiling.
* profiled_reset/0:                      Profiling.
* project_attributes/2 <1>:              Projecting Attributes.
* project_attributes/2:                  Displaying Attributes.
* prolog_file_name/2:                    Setting the Compiler.
* prolog_flag/3:                         Misc.
* prolog_initialization/1:               Misc.
* prolog_load_context/2:                 Misc.
* public/1 (directive):                  Setting the Compiler.
* put/2:                                 I/O for Streams.
* put_assoc/4:                           Association Lists.
* put_atts/2:                            Attribute Manipulation.
* put_byte/1:                            I/O of Characters.
* put_byte/2:                            I/O for Streams.
* put_char/1:                            I/O of Characters.
* put_char/2:                            I/O for Streams.
* put_code/1:                            I/O of Characters.
* put_code/2:                            I/O for Streams.
* put_label/4:                           Trees.
* putenv/2:                              OS.
* queue_to_list/2:                       Queues.
* random/1:                              Random.
* random/3:                              Random.
* randseq/3:                             Random.
* randset/3:                             Random.
* rannum/1:                              Pseudo Random.
* ranstart/0:                            Pseudo Random.
* ranstart/1:                            Pseudo Random.
* ranunif/2:                             Pseudo Random.
* reachable/3:                           UGraphs.
* read/2:                                I/O for Streams.
* read_from_chars/2:                     String I/O.
* read_term/2:                           I/O of Terms.
* read_term/3:                           I/O for Streams.
* recorda/3:                             Internal Database.
* recorda_at/3:                          Internal Database.
* recordaifnot/3:                        Internal Database.
* recordz_at/3:                          Internal Database.
* recordzifnot/3:                        Internal Database.
* regexp/3:                              RegExp.
* regexp/4:                              RegExp.
* remove_duplicates/2:                   Lists.
* remove_from_path/1:                    Setting the Compiler.
* rename_file/2:                         System.
* reset_op_counters/0:                   Low Level Profiling.
* resize_static_array/3:                 Arrays.
* restore/1:                             Saving.
* retract/1:                             Modifying the Database.
* retractall/1:                          Modifying the Database.
* reverse/2:                             Lists.
* same_length/2:                         Lists.
* save/2:                                Saving.
* save_program/1:                        Saving.
* save_program/2:                        Saving.
* select/3:                              Lists.
* selectlist/3:                          Apply Macros.
* serve_queue/3:                         Queues.
* set_input/1:                           Streams and Files.
* set_output/1:                          Streams and Files.
* set_prolog_flag/2:                     Misc.
* set_stream_position/2:                 Streams and Files.
* set_value/2:                           Internal Database.
* setarg/3n:                             Term Modification.
* setrand/1:                             Random.
* shell/0:                               System.
* shell/1:                               System.
* show_op_counters/1:                    Low Level Profiling.
* show_ops_by_group/1:                   Low Level Profiling.
* simple/1:                              Testing Terms.
* skip/2:                                I/O for Streams.
* sleep/1:                               System.
* socket/2:                              Sockets.
* socket/4:                              Sockets.
* socket_accept/2:                       Sockets.
* socket_accept/3:                       Sockets.
* socket_bind/2:                         Sockets.
* socket_buffering/4:                    Sockets.
* socket_close/1:                        Sockets.
* socket_connect/3:                      Sockets.
* socket_listen/2:                       Sockets.
* socket_select/5:                       Sockets.
* source/0:                              Setting the Compiler.
* source_mode/2:                         Setting the Compiler.
* splay_access/5:                        Splay Trees.
* splay_delete/4:                        Splay Trees.
* splay_init/3:                          Splay Trees.
* splay_insert/4:                        Splay Trees.
* splay_join/3:                          Splay Trees.
* splay_split/5:                         Splay Trees.
* spy_write/2:                           Deb Preds.
* srandom/1:                             Arithmetic.
* start_low_level_trace/0:               Low Level Tracing.
* static_array/3:                        Arrays.
* static_array_properties/3:             Arrays.
* static_array_to_term/3:                Arrays.
* statistics/2:                          Misc.
* stream_property/2:                     Streams and Files.
* stream_select/3:                       Streams and Files.
* style_check/1:                         Setting the Compiler.
* sub_atom/5:                            Testing Terms.
* sub_edges/3:                           UGraphs.
* sublist/2:                             Lists.
* subsumes/2:                            Terms.
* subsumes_chk/2:                        Terms.
* suffix/2:                              Lists.
* sum_list/2:                            Lists.
* sumargs/4:                             Apply Macros.
* sumlist/2:                             Lists.
* sumlist/4:                             Apply Macros.
* sumnodes/4:                            Apply Macros.
* system/0:                              System.
* system/2:                              System.
* system_predicate/2:                    Looking at the Database.
* tab/2:                                 I/O for Streams.
* term_hash/2:                           Terms.
* term_hash/4:                           Terms.
* term_variables/2:                      Terms.
* thread_at_exit/1:                      Creating and Destroying Prolog Threads.
* thread_create/3:                       Creating and Destroying Prolog Threads.
* thread_detach/1:                       Creating and Destroying Prolog Threads.
* thread_exit/1:                         Creating and Destroying Prolog Threads.
* thread_get_message/1:                  Message Queues.
* thread_get_message/2:                  Message Queues.
* thread_join/2:                         Creating and Destroying Prolog Threads.
* thread_local/1 (directive):            Threads and Dynamic Predicates.
* thread_message_queue_create/1:         Message Queues.
* thread_message_queue_destroy/1:        Message Queues.
* thread_peek_message/1:                 Message Queues.
* thread_self/1:                         Creating and Destroying Prolog Threads.
* thread_send_message/2:                 Message Queues.
* thread_setconcurrency/2:               Creating and Destroying Prolog Threads.
* thread_signal/2:                       Signalling Threads.
* thread_statistics/3:                   Monitoring Threads.
* throw/1:                               Control.
* time_out/3:                            Timeout.
* tmpnam/1:                              System.
* top_sort/2:                            UGraphs.
* transitive_closure/2:                  UGraphs.
* transpose/3:                           UGraphs.
* tree_size/2:                           Trees.
* tree_to_list/2:                        Trees.
* ttyget/1:                              C-Prolog to Terminal.
* ttyget0/1:                             C-Prolog to Terminal.
* ttynl/0:                               C-Prolog to Terminal.
* ttyput/1:                              C-Prolog to Terminal.
* ttyskip/1:                             C-Prolog to Terminal.
* ttytab/1:                              C-Prolog to Terminal.
* unhide/1:                              Setting the Compiler.
* unify_with_occurs_check/2:             Testing Terms.
* unix/1:                                OS.
* unknown/2:                             Undefined Procedures.
* unknown_predicate_handler/3:           Undefined Procedures.
* update_array/3:                        Arrays.
* update_mutable/2:                      Term Modification.
* use_module/1:                          Using Modules.
* use_module/2:                          Using Modules.
* use_module/3:                          Using Modules.
* variable_in_term/2:                    Terms.
* variant/2:                             Terms.
* verify_attributes/3:                   Attributed Unification.
* version/0:                             Misc.
* version/1:                             Misc.
* vertices/2:                            UGraphs.
* vertices_edges_to_ugraph/3:            UGraphs.
* wait/2:                                System.
* when/2:                                Coroutining.
* with_mutex/2:                          Thread Synchronisation.
* with_output_to_chars/2:                String I/O.
* with_output_to_chars/3:                String I/O.
* with_output_to_chars/4:                String I/O.
* working_directory/2:                   System.
* write/2:                               I/O for Streams.
* write_depth/2:                         I/O Control.
* write_term/2:                          I/O of Terms.
* write_term/3:                          I/O for Streams.
* write_to_chars/2:                      String I/O.
* write_to_chars/3:                      String I/O.
* writeq/2:                              I/O for Streams.
* yap_flag/2:                            Misc.


File: yap.info,  Node: Not in YAP,  Prev: Not in C-Prolog,  Up: C-Prolog

Yap predicates not available in C-Prolog
----------------------------------------

These are C-Prolog built-ins not available in YAP:

`'LC''
     The following Prolog text uses lower case letters.

`'NOLC''
     The following Prolog text uses upper case letters only.


File: yap.info,  Node: SICStus Prolog,  Next: ISO Prolog,  Prev: C-Prolog,  Up: Compatibility

Compatibility with the Quintus and SICStus Prolog systems
=========================================================

The Quintus Prolog system was the first Prolog compiler to use Warren's
Abstract Machine. This system was very influential in the Prolog
community. Quintus Prolog implemented compilation into an abstract
machine code, which was then emulated. Quintus Prolog also included
several new built-ins, an extensive library, and in later releases a
garbage collector. The SICStus Prolog system, developed at SICS (Swedish
Institute of Computer Science), is an emulator based Prolog system
largely compatible with Quintus Prolog. SICStus Prolog has evolved
through several versions. The current version includes several
extensions, such as an object implementation, co-routining, and
constraints.

   Recent work in YAP has been influenced by work in Quintus and
SICStus Prolog. Wherever possible, we have tried to make YAP compatible
with recent versions of these systems, and specifically of SICStus
Prolog. You should use
     :- yap_flag(language, sicstus).

for maximum compatibility with SICStus Prolog.

* Menu:

SICStus Compatibility
* Major Differences with SICStus:: Major Differences between YAP and SICStus Prolog
* Fully SICStus Compatible:: Yap predicates fully compatible with
SICStus Prolog
* Not Strictly SICStus Compatible:: Yap predicates not strictly as
SICStus Prolog
* Not in SICstus Prolog:: Yap predicates not available in SICStus Prolog


File: yap.info,  Node: Major Differences with SICStus,  Next: Fully SICStus Compatible,  Up: SICStus Prolog

Major Differences between YAP and SICStus Prolog.
-------------------------------------------------

Both YAP and SICStus Prolog obey the Edinburgh Syntax and are based on
the WAM. Even so, there are quite a few important differences:

   * Differently from SICStus Prolog, YAP does not have a notion of
     interpreted code. All code in YAP is compiled.

   * YAP does not support an intermediate byte-code representation, so
     the `fcompile/1' and `load/1' built-ins are not available in YAP.

   * YAP implements escape sequences as in the ISO standard. SICStus
     Prolog implements Unix-like escape sequences.

   * YAP implements `initialization/1' as per the ISO standard. Use
     `prolog_initialization/1' for the SICStus Prolog compatible
     built-in.

   * Prolog flags are different in SICStus Prolog and in YAP.

   * The SICStus Prolog `on_exception/3' and `raise_exception'
     built-ins correspond to the ISO builtins `catch/3' and `throw/1'.

   * The following SICStus Prolog v3 built-ins are not (currently)
     implemented in YAP (note that this is only a partial list):
     `call_cleanup/1', `file_search_path/2', `stream_interrupt/3',
     `reinitialize/0', `help/0', `help/1', `trimcore/0', `load_files/1',
     `load_files/2', and `require/1'.

     The previous list is incomplete. We also cannot guarantee full
     compatibility for other built-ins (although we will try to address
     any such incompatibilities). Last, SICStus Prolog is an evolving
     system, so one can be expect new incompatibilities to be
     introduced in future releases of SICStus Prolog.

   * YAP allows asserting and abolishing static code during execution
     through the `assert_static/1' and `abolish/1' builtins. This is
     not allowed in Quintus Prolog or SICStus Prolog.

   * YAP implements rational trees and co-routining but they are not
     included by default in the system. You must enable these
     extensions when compiling the system.

   * YAP does not currently implement constraints.

   * The socket predicates, although designed to be compatible with
     SICStus Prolog, are built-ins, not library predicates, in YAP.

   * This list is incomplete.


   The following differences only exist if the `language' flag is set
to `yap' (the default):

   * The `consult/1' predicate in YAP follows C-Prolog semantics. That
     is, it adds clauses to the data base, even for preexisting
     procedures. This is different from `consult/1' in SICStus Prolog.

   * By default, the data-base in YAP follows "immediate update
     semantics", instead of "logical update semantics", as Quintus
     Prolog or SICStus Prolog do. The difference is depicted in the
     next example:

          :- dynamic a/1.
          
          ?- assert(a(1)).
          
          ?- retract(a(X)), X1 is X +1, assertz(a(X)).
     With immediate semantics, new clauses or entries to the data base
     are visible in backtracking. In this example, the first call to
     `retract/1' will succeed. The call to *assertz/1* will then
     succeed. On backtracking, the system will retry `retract/1'.
     Because the newly asserted goal is visible to `retract/1', it can
     be retracted from the data base, and `retract(a(X))' will succeed
     again. The process will continue generating integers for ever.
     Immediate semantics were used in C-Prolog.

     With logical update semantics, any additions or deletions of
     clauses for a goal _will not affect previous activations of the
     goal_. In the example, the call to `assertz/1' will not see the
     update performed by the `assertz/1', and the query will have a
     single solution.

     Calling `yap_flag(update_semantics,logical)' will switch YAP to
     use logical update semantics.

   * `dynamic/1' is a built-in, not a directive, in YAP.

   * By default, YAP fails on undefined predicates. To follow default
     SICStus Prolog use:
          :- yap_flag(unknown,error).

   * By default, directives in YAP can be called from the top level.



File: yap.info,  Node: Fully SICStus Compatible,  Next: Not Strictly SICStus Compatible,  Prev: Major Differences with SICStus,  Up: SICStus Prolog

Yap predicates fully compatible with SICStus Prolog
---------------------------------------------------

These are the Prolog built-ins that are fully compatible in both SICStus
Prolog and YAP:

* Menu:

* !/0:                                   Control.
* ,/2:                                   Control.
* ->/2:                                  Control.
* ;/2:                                   Control.
* </2:                                   Arithmetic.
* =../2:                                 Testing Terms.
* =/2:                                   Testing Terms.
* =:=/2:                                 Arithmetic.
* =</2:                                  Arithmetic.
* ==/2:                                  Comparing Terms.
* =\=/2:                                 Arithmetic.
* >/2:                                   Arithmetic.
* >=/2:                                  Arithmetic.
* @</2:                                  Comparing Terms.
* @>/2:                                  Comparing Terms.
* @>=/2:                                 Comparing Terms.
* \+/1:                                  Control.
* \==/2:                                 Comparing Terms.
* abort/0:                               Control.
* absolute_file_name/2:                  Streams and Files.
* add_edges/3:                           UGraphs.
* add_to_heap/4:                         Heaps.
* add_vertices/3:                        UGraphs.
* append/3:                              Lists.
* arg/3:                                 Testing Terms.
* assoc_to_list/2:                       Association Lists.
* at_end_of_stream/0:                    Streams and Files.
* at_end_of_stream/1:                    Streams and Files.
* atom/1:                                Testing Terms.
* atom_codes/2:                          Testing Terms.
* atom_concat/3:                         Testing Terms.
* atom_to_chars/2:                       String I/O.
* atom_to_chars/3:                       String I/O.
* atomic/1:                              Testing Terms.
* attribute_goal/2:                      Displaying Attributes.
* bb_delete/2:                           BlackBoard.
* bb_get/2:                              BlackBoard.
* bb_put/2:                              BlackBoard.
* bb_update/3:                           BlackBoard.
* break/0:                               Control.
* C/3:                                   Grammars.
* call/1:                                Control.
* call_cleanup/1:                        Cleanup.
* call_cleanup/2:                        Cleanup.
* call_residue/2:                        Coroutining.
* callable/1:                            Testing Terms.
* char_code/2:                           Testing Terms.
* char_conversion/2:                     I/O of Terms.
* cleanup_all/0:                         Cleanup.
* close/1:                               Streams and Files.
* compare/3:                             Comparing Terms.
* compile/1:                             Compiling.
* complement/2:                          UGraphs.
* compose/3:                             UGraphs.
* compound/1:                            Testing Terms.
* copy_term/2:                           Testing Terms.
* create_mutable/2:                      Term Modification.
* current_atom/1:                        Looking at the Database.
* current_char_conversion/2:             I/O of Terms.
* current_input/1:                       Streams and Files.
* current_key/2:                         Internal Database.
* current_module/1:                      Preds.
* current_module/2:                      Preds.
* current_op/3:                          Misc.
* current_output/1:                      Streams and Files.
* current_predicate/1:                   Looking at the Database.
* current_predicate/2:                   Looking at the Database.
* current_stream/3:                      Streams and Files.
* cyclic_term/1:                         Terms.
* datime/1:                              System.
* db_reference/1:                        Testing Terms.
* debugging/0:                           Deb Preds.
* del_vertices/3:                        UGraphs.
* delete/3:                              Lists.
* delete_file/1:                         System.
* delete_file/2:                         System.
* dif/2:                                 Coroutining.
* directory_files/2:                     System.
* discontiguous/1 (directive):           Setting the Compiler.
* display/1 <1>:                         I/O for Streams.
* display/1:                             I/O of Terms.
* display/2:                             I/O for Streams.
* empty_assoc/1:                         Association Lists.
* empty_heap/1:                          Heaps.
* empty_queue/1:                         Queues.
* environ/2 <1>:                         System.
* environ/2:                             OS.
* exec/3:                                System.
* expand_term/2:                         Grammars.
* fail/0:                                Control.
* false/0:                               Control.
* file_exists/1:                         System.
* file_exists/2:                         System.
* file_property/2:                       System.
* file_search_path/2:                    Setting the Compiler.
* fileerrors/0:                          I/O Control.
* findall/3:                             Sets.
* findall/4:                             Sets.
* flatten/2:                             Lists.
* float/1:                               Testing Terms.
* flush_output/0:                        Streams and Files.
* flush_output/1:                        Streams and Files.
* format_to_chars/3:                     String I/O.
* format_to_chars/4:                     String I/O.
* fragile:                               Cleanup.
* freeze/2:                              Coroutining.
* frozen/2:                              Coroutining.
* functor/3:                             Testing Terms.
* garbage_collect/0:                     Control.
* garbage_collect_atoms/0:               Control.
* gc/0:                                  Control.
* gen_assoc/3:                           Association Lists.
* get/1:                                 I/O of Characters.
* get/2:                                 I/O for Streams.
* get0/1:                                I/O of Characters.
* get0/2:                                I/O for Streams.
* get_assoc/3:                           Association Lists.
* get_assoc/5:                           Association Lists.
* get_atts/2:                            Attribute Manipulation.
* get_from_heap/4:                       Heaps.
* get_label/3:                           Trees.
* get_mutable/2:                         Term Modification.
* getrand/1:                             Random.
* ground/1:                              Testing Terms.
* halt/0:                                Control.
* halt/1:                                Control.
* head_queue/2:                          Queues.
* heap_size/2:                           Heaps.
* heap_to_list/2:                        Heaps.
* host_id/1:                             System.
* host_name/1:                           System.
* if/3:                                  Control.
* incore/1:                              Control.
* initialization/0:                      Misc.
* integer/1:                             Testing Terms.
* is/2:                                  Arithmetic.
* is_list/1:                             Lists.
* is_mutable/1:                          Term Modification.
* join_queue/3:                          Queues.
* jump_queue/3:                          Queues.
* keysort/2:                             Comparing Terms.
* kill/2:                                System.
* last/2:                                Lists.
* leash/1:                               Deb Preds.
* length/2:                              Comparing Terms.
* length_queue/2:                        Queues.
* list_join_queue/3:                     Queues.
* list_jump_queue/3:                     Queues.
* list_to_assoc/2:                       Association Lists.
* list_to_heap/2:                        Heaps.
* list_to_ord_set/2:                     Ordered Sets.
* list_to_queue/2:                       Queues.
* list_to_tree/2:                        Trees.
* listing/1:                             Looking at the Database.
* make_directory/2:                      System.
* make_queue/1:                          Queues.
* map_assoc/3:                           Association Lists.
* map_tree/3:                            Trees.
* member/2:                              Lists.
* memberchk/2:                           Lists.
* merge/3:                               Ordered Sets.
* meta_predicate/1 (directive):          Meta-Predicates in Modules.
* min_of_heap/3:                         Heaps.
* min_of_heap/5:                         Heaps.
* mktemp/2:                              System.
* module/1:                              Defining Modules.
* module/2 (directive):                  Defining Modules.
* module/3 (directive):                  Defining Modules.
* multifile/1 (directive):               Setting the Compiler.
* name/2:                                Testing Terms.
* neighbors/3:                           UGraphs.
* neighbours/3:                          UGraphs.
* nl/0:                                  I/O of Characters.
* nl/1:                                  I/O for Streams.
* nodebug/0:                             Deb Preds.
* nofileerrors/0:                        I/O Control.
* nogc/0:                                Control.
* nonvar/1:                              Testing Terms.
* nospy/1:                               Deb Preds.
* nospyall/0:                            Deb Preds.
* nth/2:                                 Lists.
* nth/4:                                 Lists.
* nth0/2:                                Lists.
* nth0/4:                                Lists.
* number/1:                              Testing Terms.
* number_codes/2:                        Testing Terms.
* number_to_chars/2:                     String I/O.
* number_to_chars/3:                     String I/O.
* numbervars/3:                          Testing Terms.
* on_cleanup/1:                          Cleanup.
* op/3:                                  Misc.
* open/3:                                Streams and Files.
* open_chars_stream/2:                   String I/O.
* ord_add_element/3:                     Ordered Sets.
* ord_del_element/3:                     Ordered Sets.
* ord_disjoint/2:                        Ordered Sets.
* ord_insert/3:                          Ordered Sets.
* ord_intersect/2:                       Ordered Sets.
* ord_intersect/3:                       Ordered Sets.
* ord_list_to_assoc/2:                   Association Lists.
* ord_member/2:                          Ordered Sets.
* ord_seteq/2:                           Ordered Sets.
* ord_setproduct/3:                      Ordered Sets.
* ord_subtract/3:                        Ordered Sets.
* ord_symdiff/3:                         Ordered Sets.
* ord_union/2:                           Ordered Sets.
* ord_union/3:                           Ordered Sets.
* ord_union/4:                           Ordered Sets.
* ordsubset/2:                           Ordered Sets.
* peek_char/1:                           I/O of Characters.
* permutation/2:                         Lists.
* phrase/2:                              Grammars.
* phrase/3:                              Grammars.
* pid/1:                                 System.
* popen/3:                               System.
* portray_clause/1:                      Looking at the Database.
* portray_clause/2:                      Looking at the Database.
* primitive/1:                           Testing Terms.
* print/1:                               I/O of Terms.
* print/2:                               I/O for Streams.
* project_attributes/2 <1>:              Projecting Attributes.
* project_attributes/2:                  Displaying Attributes.
* prolog_file_name/1:                    Setting the Compiler.
* prolog_flag/3:                         Misc.
* prolog_load_context/2:                 Misc.
* prompt/2:                              Misc.
* put/1:                                 I/O of Characters.
* put/2:                                 I/O for Streams.
* put_assoc/4:                           Association Lists.
* put_atts/2:                            Attribute Manipulation.
* put_label/4:                           Trees.
* queue_to_list/2:                       Queues.
* random/1:                              Random.
* random/3:                              Random.
* randseq/3:                             Random.
* randset/3:                             Random.
* reachable/3:                           UGraphs.
* read/1:                                I/O of Terms.
* read/2:                                I/O for Streams.
* read_from_chars/2:                     String I/O.
* remove_duplicates/2:                   Lists.
* rename_file/2:                         System.
* repeat/0:                              Control.
* restore/1:                             Saving.
* reverse/2:                             Lists.
* same_length/2:                         Lists.
* save_program/1:                        Saving.
* save_program/2:                        Saving.
* see/1:                                 C-Prolog File Handling.
* seeing/1:                              C-Prolog File Handling.
* seen/0:                                C-Prolog File Handling.
* select/3:                              Lists.
* serve_queue/3:                         Queues.
* set_input/1:                           Streams and Files.
* set_output/1:                          Streams and Files.
* set_stream_position/2:                 Streams and Files.
* setrand/1:                             Random.
* shell/0:                               System.
* shell/1:                               System.
* simple/1:                              Testing Terms.
* skip/1:                                I/O of Characters.
* skip/2:                                I/O for Streams.
* sleep/1:                               System.
* socket/2:                              Sockets.
* socket/4:                              Sockets.
* socket_accept/2:                       Sockets.
* socket_accept/3:                       Sockets.
* socket_bind/2:                         Sockets.
* socket_buffering/4:                    Sockets.
* socket_close/1:                        Sockets.
* socket_connect/3:                      Sockets.
* socket_listen/2:                       Sockets.
* socket_select/5:                       Sockets.
* sort/2:                                Comparing Terms.
* spy/1:                                 Deb Preds.
* stream_select/3:                       Streams and Files.
* sub_edges/3:                           UGraphs.
* sublist/2:                             Lists.
* subsumes/2:                            Terms.
* subsumes_chk/2:                        Terms.
* suffix/2:                              Lists.
* sumlist/2:                             Lists.
* system/0:                              System.
* system/2:                              System.
* system_predicate/2:                    Looking at the Database.
* tab/1:                                 I/O of Characters.
* tab/2:                                 I/O for Streams.
* tell/1:                                C-Prolog File Handling.
* telling/1:                             C-Prolog File Handling.
* term_expansion/2:                      Grammars.
* term_hash/2:                           Terms.
* term_hash/4:                           Terms.
* term_variables/2:                      Terms.
* time_out/3:                            Timeout.
* tmpnam/1:                              System.
* told/0:                                C-Prolog File Handling.
* top_sort/2:                            UGraphs.
* transitive_closure/2:                  UGraphs.
* transpose/3:                           UGraphs.
* tree_size/2:                           Trees.
* tree_to_list/2:                        Trees.
* true/0:                                Control.
* ttyget/1:                              C-Prolog to Terminal.
* ttyget0/1:                             C-Prolog to Terminal.
* ttynl/0:                               C-Prolog to Terminal.
* ttyput/1:                              C-Prolog to Terminal.
* ttyskip/1:                             C-Prolog to Terminal.
* ttytab/1:                              C-Prolog to Terminal.
* unify_with_occurs_check/2:             Testing Terms.
* unknown_predicate_handler/3:           Undefined Procedures.
* update_mutable/2:                      Term Modification.
* use_module/1:                          Using Modules.
* use_module/2:                          Using Modules.
* use_module/3:                          Using Modules.
* var/1:                                 Testing Terms.
* variant/2:                             Terms.
* verify_attributes/3:                   Attributed Unification.
* version/1:                             Misc.
* vertices/2:                            UGraphs.
* vertices_edges_to_ugraph/3:            UGraphs.
* wait/2:                                System.
* when/2:                                Coroutining.
* with_output_to_chars/2:                String I/O.
* with_output_to_chars/3:                String I/O.
* with_output_to_chars/4:                String I/O.
* working_directory/2:                   System.
* write/1:                               I/O of Terms.
* write/2:                               I/O for Streams.
* write_term/2:                          I/O of Terms.
* write_term/3:                          I/O for Streams.
* write_to_chars/2:                      String I/O.
* write_to_chars/3:                      String I/O.
* writeq/1:                              I/O of Terms.
* writeq/2:                              I/O for Streams.


File: yap.info,  Node: Not Strictly SICStus Compatible,  Next: Not in SICstus Prolog,  Prev: Fully SICStus Compatible,  Up: SICStus Prolog

Yap predicates not strictly compatible with SICStus Prolog
----------------------------------------------------------

These are YAP built-ins that are also available in SICStus Prolog, but
that are not fully compatible:

* Menu:

* [-]/1:                                 Compiling.
* []/1:                                  Compiling.
* abolish/1:                             Modifying the Database.
* abolish/2:                             Modifying the Database.
* assert/1:                              Modifying the Database.
* assert/2:                              Database References.
* asserta/1:                             Modifying the Database.
* asserta/2:                             Database References.
* assertz/1:                             Modifying the Database.
* assertz/2:                             Database References.
* atom_chars/2:                          Testing Terms.
* bagof/3:                               Sets.
* clause/2:                              Modifying the Database.
* clause/3:                              Modifying the Database.
* close/2:                               Streams and Files.
* debug/0:                               Deb Preds.
* dynamic/1:                             Database.
* erase/1:                               Internal Database.
* erased/1:                              Internal Database.
* format/2:                              I/O of Terms.
* format/3:                              I/O of Terms.
* instance/2:                            Internal Database.
* listing/0:                             Looking at the Database.
* nth_clause/3:                          Modifying the Database.
* nth_recorded/3:                        Internal Database.
* number_chars/2:                        Testing Terms.
* open/4:                                Streams and Files.
* predicate_property/2:                  Looking at the Database.
* prolog_initialization/1:               Misc.
* read_term/2:                           I/O of Terms.
* read_term/3:                           I/O for Streams.
* recorda/3:                             Internal Database.
* recordaifnot/3:                        Internal Database.
* recorded/3:                            Internal Database.
* recordz/3:                             Internal Database.
* retract/1:                             Modifying the Database.
* retract/2:                             Database References.
* retractall/1:                          Modifying the Database.
* setof/3:                               Sets.
* statistics/0:                          Misc.
* statistics/2:                          Misc.
* unknown/2:                             Undefined Procedures.
* version/0:                             Misc.


File: yap.info,  Node: Not in SICstus Prolog,  Prev: Not Strictly SICStus Compatible,  Up: SICStus Prolog

Yap predicates not available in SICStus Prolog
----------------------------------------------

These are YAP built-ins not available in SICStus Prolog.

* Menu:

* \=/2:                                  Testing Terms.
* add_to_array_element/4:                Arrays.
* alarm/3:                               OS.
* all/3:                                 Sets.
* always_prompt_user/0:                  I/O Control.
* array/2:                               Arrays.
* array_element/3:                       Arrays.
* assert_static/1:                       Modifying the Database.
* asserta_static/1:                      Modifying the Database.
* assertz_static/1:                      Modifying the Database.
* atom_concat/2:                         Testing Terms.
* atom_concat/3:                         Testing Terms.
* atom_length/2:                         Testing Terms.
* avl_insert/4:                          AVL Trees.
* avl_lookup/3:                          AVL Trees.
* call_count_data/0:                     Call Counting.
* call_count_data/3:                     Call Counting.
* call_with_args/n:                      Control.
* catch/3:                               Control.
* cd/1:                                  OS.
* checklist/2:                           Apply Macros.
* checknodes/3:                          Apply Macros.
* close_static_array/1:                  Arrays.
* compile/1 (directive):                 Compiling.
* compile_expressions/0:                 Setting the Compiler.
* consult/1:                             Compiling.
* convlist/3:                            Apply Macros.
* current_mutex/3:                       Thread Synchronisation.
* current_prolog_flag/2:                 Misc.
* current_thread/2:                      Monitoring Threads.
* delete/3:                              Red-Black Trees.
* do_not_compile_expressions/0:          Setting the Compiler.
* dynamic_predicate/2:                   Database.
* eraseall/1:                            Internal Database.
* exists/1:                              I/O Control.
* expand_exprs/2:                        Setting the Compiler.
* get_byte/1:                            I/O of Characters.
* get_byte/2:                            I/O for Streams.
* get_char/1:                            I/O of Characters.
* get_char/2:                            I/O for Streams.
* get_code/1:                            I/O of Characters.
* get_code/2:                            I/O for Streams.
* get_value/2:                           Internal Database.
* getcwd/1:                              OS.
* goal_expansion/3:                      Grammars.
* grow_heap/1:                           Control.
* grow_stack/1:                          Control.
* hide/1:                                Setting the Compiler.
* hide_predicate/1:                      Setting the Compiler.
* initialization/1 (directive):          Setting the Compiler.
* insert/4:                              Red-Black Trees.
* key_statistics/3:                      Internal Database.
* key_statistics/4:                      Internal Database.
* library_directory/1:                   Setting the Compiler.
* list_concat/2:                         Lists.
* lookup/3:                              Red-Black Trees.
* mapargs/3:                             Apply Macros.
* maplist/3:                             Apply Macros.
* mapnodes/3:                            Apply Macros.
* mutex_create/1:                        Thread Synchronisation.
* mutex_destroy/1:                       Thread Synchronisation.
* mutex_lock/1:                          Thread Synchronisation.
* mutex_statistics/0:                    Monitoring Threads.
* mutex_trylock/1:                       Thread Synchronisation.
* mutex_unlock/1:                        Thread Synchronisation.
* mutex_unlock_all/0:                    Thread Synchronisation.
* new/1:                                 Red-Black Trees.
* no_source/0:                           Setting the Compiler.
* not/1:                                 Control.
* number_atom/2:                         Testing Terms.
* on_signal/3:                           OS.
* once/1:                                Control.
* path/1:                                Setting the Compiler.
* peek_byte/1:                           I/O of Characters.
* peek_byte/2:                           I/O for Streams.
* peek_char/2:                           I/O for Streams.
* peek_code/1:                           I/O of Characters.
* peek_code/2:                           I/O for Streams.
* profile_data/3:                        Profiling.
* profiled_reset/0:                      Profiling.
* public/1 (directive):                  Setting the Compiler.
* put_byte/1:                            I/O of Characters.
* put_byte/2:                            I/O for Streams.
* put_char/1:                            I/O of Characters.
* put_char/2:                            I/O for Streams.
* put_code/1:                            I/O of Characters.
* put_code/2:                            I/O for Streams.
* putenv/2:                              OS.
* rannum/1:                              Pseudo Random.
* ranstart/0:                            Pseudo Random.
* ranstart/1:                            Pseudo Random.
* ranunif/2:                             Pseudo Random.
* reconsult/1:                           Compiling.
* recorda/3:                             Internal Database.
* recorda_at/3:                          Internal Database.
* recordaifnot/3:                        Internal Database.
* recordz_at/3:                          Internal Database.
* recordzifnot/3:                        Internal Database.
* regexp/3:                              RegExp.
* regexp/4:                              RegExp.
* remove_from_path/1:                    Setting the Compiler.
* rename/2:                              OS.
* reset_op_counters/0:                   Low Level Profiling.
* resize_static_array/3:                 Arrays.
* save/1:                                Saving.
* save/2:                                Saving.
* selectlist/3:                          Apply Macros.
* set_prolog_flag/2:                     Misc.
* set_value/2:                           Internal Database.
* setarg/3n:                             Term Modification.
* sh/0:                                  OS.
* show_op_counters/1:                    Low Level Profiling.
* show_ops_by_group/1:                   Low Level Profiling.
* source/0:                              Setting the Compiler.
* source_mode/2:                         Setting the Compiler.
* splay_access/5:                        Splay Trees.
* splay_delete/4:                        Splay Trees.
* splay_init/3:                          Splay Trees.
* splay_insert/4:                        Splay Trees.
* splay_join/3:                          Splay Trees.
* splay_split/5:                         Splay Trees.
* spy_write/2:                           Deb Preds.
* srandom/1:                             Arithmetic.
* start_low_level_trace/0:               Low Level Tracing.
* static_array/3:                        Arrays.
* static_array_properties/3:             Arrays.
* static_array_to_term/3:                Arrays.
* stream_property/2:                     Streams and Files.
* style_check/1:                         Setting the Compiler.
* sub_atom/5:                            Testing Terms.
* sum_list/2:                            Lists.
* sumargs/4:                             Apply Macros.
* sumlist/4:                             Apply Macros.
* sumnodes/4:                            Apply Macros.
* system/1:                              OS.
* thread_at_exit/1:                      Creating and Destroying Prolog Threads.
* thread_create/3:                       Creating and Destroying Prolog Threads.
* thread_detach/1:                       Creating and Destroying Prolog Threads.
* thread_exit/1:                         Creating and Destroying Prolog Threads.
* thread_get_message/1:                  Message Queues.
* thread_get_message/2:                  Message Queues.
* thread_join/2:                         Creating and Destroying Prolog Threads.
* thread_local/1 (directive):            Threads and Dynamic Predicates.
* thread_message_queue_create/1:         Message Queues.
* thread_message_queue_destroy/1:        Message Queues.
* thread_peek_message/1:                 Message Queues.
* thread_self/1:                         Creating and Destroying Prolog Threads.
* thread_send_message/2:                 Message Queues.
* thread_setconcurrency/2:               Creating and Destroying Prolog Threads.
* thread_signal/2:                       Signalling Threads.
* thread_statistics/3:                   Monitoring Threads.
* throw/1:                               Control.
* unhide/1:                              Setting the Compiler.
* unix/1:                                OS.
* update_array/3:                        Arrays.
* variable_in_term/2:                    Terms.
* with_mutex/2:                          Thread Synchronisation.
* write_depth/2:                         I/O Control.
* yap_flag/2:                            Misc.


File: yap.info,  Node: ISO Prolog,  Prev: SICStus Prolog,  Up: Compatibility

Compatibility with the ISO Prolog standard
==========================================

The Prolog standard was developed by ISO/IEC JTC1/SC22/WG17, the
international standardization working group for the programming language
Prolog. The book "Prolog: The Standard" by Deransart, Ed-Dbali and
Cervoni gives a complete description of this standard. Development in
YAP from YAP4.1.6 onwards have striven at making YAP compatible with
ISO Prolog. As such:

   * YAP now supports all of the built-ins required by the
     ISO-standard, and,

   * Error-handling is as required by the standard.

   YAP by default is not fully ISO standard compliant. You can set the
`language' flag to `iso' to obtain very good compatibility. Setting
this flag changes the following:

   * By default, YAP uses "immediate update semantics" for its
     database, and not "logical update semantics", as per the standard,
     (*note SICStus Prolog::). This affects `assert/1', `retract/1',
     and friends.

     Calling `set_prolog_flag(update_semantics,logical)' will switch
     YAP to use logical update semantics.

   * By default, YAP implements the `atom_chars/2' (*note Testing
     Terms::), and `number_chars/2', (*note Testing Terms::), built-ins
     as per the original Quintus Prolog definition, and not as per the
     ISO definition.

     Calling `set_prolog_flag(to_chars_mode,iso)' will switch YAP to
     use the ISO definition for `atom_chars/2' and `number_chars/2'.

   * By default, YAP fails on undefined predicates. To follow the ISO
     Prolog standard use:
          :- set_prolog_flag(unknown,error).

   * By default, YAP allows executable goals in directives. In ISO mode
     most directives can only be called from top level (the exceptions
     are `set_prolog_flag/2' and `op/3').

   * Error checking for meta-calls under ISO Prolog mode is stricter
     than by default.

   * The `strict_iso' flag automatically enables the ISO Prolog
     standard. This feature should disable all features not present in
     the standard.


   The following incompatibilities between YAP and the ISO standard are
known to still exist:

   * Currently, YAP does not handle overflow errors in integer
     operations, and handles floating-point errors only in some
     architectures. Otherwise, YAP follows IEEE arithmetic.


   Please inform the authors on other incompatibilities that may still
exist.


File: yap.info,  Node: Operators,  Next: Predicate Index,  Prev: Compatibility,  Up: Top

Summary of Yap Predefined Operators
***********************************

The Prolog syntax caters for operators of three main kinds:

   * prefix;

   * infix;

   * postfix.

   Each operator has precedence in the range 1 to 1200, and this
precedence is used to disambiguate expressions where the structure of
the term denoted is not made explicit using brackets. The operator of
higher precedence is the main functor.

   If there are two operators with the highest precedence, the ambiguity
is solved analyzing the types of the operators. The possible infix
types are: xfx, xfy, yfx.

   With an operator of type xfx both sub-expressions must have lower
precedence than the operator itself, unless they are bracketed (which
assigns to them zero precedence). With an operator type xfy only the
left-hand sub-expression must have lower precedence. The opposite
happens for yfx type.

   A prefix operator can be of type fx or fy, and a postfix operator,
xf, yf.  The meaning of the notation is analogous to the above.
     a + b * c

means
     a + (b * c)

as + and * have the following types and precedences:
     :-op(500,yfx,'+').
     :-op(400,yfx,'*').

   Now defining
     :-op(700,xfy,'++').
     :-op(700,xfx,'=:=').
     a ++ b =:= c
    means
     a ++ (b =:= c)

   The following is the list of the declarations of the predefined
operators:

     :-op(1200,fx,['?-', ':-']).
     :-op(1200,xfx,[':-','-->']).
     :-op(1150,fx,[block,dynamic,mode,public,multifile,meta_predicate,
                   sequential,table,initialization]).
     :-op(1100,xfy,[';','|']).
     :-op(1050,xfy,->).
     :-op(1000,xfy,',').
     :-op(999,xfy,'.').
     :-op(900,fy,['\+', not]).
     :-op(900,fx,[nospy, spy]).
     :-op(700,xfx,[@>=,@=<,@<,@>,<,=,>,=:=,=\=,\==,>=,=<,==,\=,=..,is]).
     :-op(500,yfx,['\/','/\','+','-']).
     :-op(500,fx,['+','-']).
     :-op(400,yfx,['<<','>>','//','*','/']).
     :-op(300,xfx,mod).
     :-op(200,xfy,['^','**']).
     :-op(50,xfx,same).


File: yap.info,  Node: Predicate Index,  Next: Concept Index,  Prev: Operators,  Up: Top

Predicate Index
***************

* Menu:

* !/0:                                   Control.
* ,/2:                                   Control.
* ->/2:                                  Control.
* ;/2:                                   Control.
* </2:                                   Arithmetic.
* =../2:                                 Testing Terms.
* =/2:                                   Testing Terms.
* =:=/2:                                 Arithmetic.
* =</2:                                  Arithmetic.
* ==/2:                                  Comparing Terms.
* =\=/2:                                 Arithmetic.
* >/2:                                   Arithmetic.
* >=/2:                                  Arithmetic.
* @</2:                                  Comparing Terms.
* @=</2:                                 Comparing Terms.
* @>/2:                                  Comparing Terms.
* @>=/2:                                 Comparing Terms.
* [-]/1:                                 Compiling.
* []/1:                                  Compiling.
* \+/1:                                  Control.
* \=/2:                                  Testing Terms.
* \==/2:                                 Comparing Terms.
* abolish/1:                             Modifying the Database.
* abolish/2:                             Modifying the Database.
* abort/0:                               Control.
* absolute_file_name/2:                  Streams and Files.
* add_edges/3:                           UGraphs.
* add_to_array_element/4:                Arrays.
* add_to_heap/4:                         Heaps.
* add_to_path/1:                         Setting the Compiler.
* add_to_path/2:                         Setting the Compiler.
* add_vertices/3:                        UGraphs.
* alarm/3:                               OS.
* all/3:                                 Sets.
* always_prompt_user/0:                  I/O Control.
* append/3:                              Lists.
* arg/3:                                 Testing Terms.
* argv (yap_flag/2 option):              Misc.
* array/2:                               Arrays.
* array_element/3:                       Arrays.
* assert/1:                              Modifying the Database.
* assert/2:                              Database References.
* assert_static/1:                       Modifying the Database.
* asserta/1:                             Modifying the Database.
* asserta/2:                             Database References.
* asserta_static/1:                      Modifying the Database.
* assertz/1:                             Modifying the Database.
* assertz/2:                             Database References.
* assertz_static/1:                      Modifying the Database.
* assoc_to_list/2:                       Association Lists.
* at_end_of_stream/0:                    Streams and Files.
* at_end_of_stream/1:                    Streams and Files.
* atom/1:                                Testing Terms.
* atom_chars/2:                          Testing Terms.
* atom_codes/2:                          Testing Terms.
* atom_concat/2:                         Testing Terms.
* atom_concat/3:                         Testing Terms.
* atom_length/2:                         Testing Terms.
* atom_to_chars/2:                       String I/O.
* atom_to_chars/3:                       String I/O.
* atomic/1:                              Testing Terms.
* attribute/1 (declaration):             Attribute Declarations.
* attribute_goal/2:                      Displaying Attributes.
* avl_insert/4:                          AVL Trees.
* avl_lookup/3:                          AVL Trees.
* bagof/3:                               Sets.
* bb_delete/2:                           BlackBoard.
* bb_get/2:                              BlackBoard.
* bb_put/2:                              BlackBoard.
* bb_update/3:                           BlackBoard.
* bounded (yap_flag/2 option):           Misc.
* break/0:                               Control.
* C/3:                                   Grammars.
* call/1:                                Control.
* call_cleanup/1:                        Cleanup.
* call_cleanup/2:                        Cleanup.
* call_count_data/0:                     Call Counting.
* call_count_data/3:                     Call Counting.
* call_counting (yap_flag/2 option):     Misc.
* call_residue/2:                        Coroutining.
* call_with_args/n:                      Control.
* callable/1:                            Testing Terms.
* catch/3:                               Control.
* cd/1:                                  OS.
* char_code/2:                           Testing Terms.
* char_conversion (yap_flag/2 option):   Misc.
* char_conversion/2:                     I/O of Terms.
* character_escapes (yap_flag/2 option): Misc.
* checklist/2:                           Apply Macros.
* checknodes/3:                          Apply Macros.
* chr_debug/0:                           CHR Debugging Predicates.
* chr_debugging/0:                       CHR Debugging Predicates.
* chr_leash/1:                           CHR Debugging Predicates.
* chr_nodebug/0:                         CHR Debugging Predicates.
* chr_nospy/1:                           CHR Spy-points.
* chr_notrace/0:                         CHR Debugging Predicates.
* chr_spy/1:                             CHR Spy-points.
* chr_trace/0:                           CHR Debugging Predicates.
* clause/2:                              Modifying the Database.
* clause/3:                              Modifying the Database.
* cleanup_all/0:                         Cleanup.
* close/1:                               Streams and Files.
* close/2:                               Streams and Files.
* close_static_array/1:                  Arrays.
* compare/3:                             Comparing Terms.
* compile/1:                             Compiling.
* compile_expressions/0:                 Setting the Compiler.
* complement/2:                          UGraphs.
* compose/3:                             UGraphs.
* compound/1:                            Testing Terms.
* consult/1:                             Compiling.
* convlist/3:                            Apply Macros.
* copy_term/2:                           Testing Terms.
* cputime (statistics/2 option):         Misc.
* create_mutable/2:                      Term Modification.
* current_atom/1:                        Looking at the Database.
* current_char_conversion/2:             I/O of Terms.
* current_constraint/2:                  CHR Built-In Predicates.
* current_handler/2:                     CHR Built-In Predicates.
* current_input/1:                       Streams and Files.
* current_key/2:                         Internal Database.
* current_module/1:                      Preds.
* current_module/2:                      Preds.
* current_mutex/3:                       Thread Synchronisation.
* current_op/3:                          Misc.
* current_output/1:                      Streams and Files.
* current_predicate/1:                   Looking at the Database.
* current_predicate/2:                   Looking at the Database.
* current_prolog_flag/2:                 Misc.
* current_stream/3:                      Streams and Files.
* current_thread/2:                      Monitoring Threads.
* cyclic_term/1:                         Terms.
* datime/1:                              System.
* db_reference/1C:                       Testing Terms.
* debug (yap_flag/2 option):             Misc.
* debug/0:                               Deb Preds.
* debugging/0:                           Deb Preds.
* del_vertices/3:                        UGraphs.
* delete/3 <1>:                          Red-Black Trees.
* delete/3:                              Lists.
* delete_file/1:                         System.
* delete_file/2:                         System.
* dif/2:                                 Coroutining.
* directory (prolog_load_context/2 option): Misc.
* directory_files/2:                     System.
* discontiguous/1 (directive):           Setting the Compiler.
* discontiguous_warnings (yap_flag/2 option): Misc.
* display/1 <1>:                         I/O for Streams.
* display/1:                             I/O of Terms.
* display/2:                             I/O for Streams.
* do_not_compile_expressions/0:          Setting the Compiler.
* dollar_as_lower_case (yap_flag/2 option): Misc.
* double_quotes (yap_flag/2 option):     Misc.
* dynamic/1:                             Database.
* dynamic_predicate/2:                   Database.
* empty_assoc/1:                         Association Lists.
* empty_heap/1:                          Heaps.
* empty_queue/1:                         Queues.
* ensure_loaded/1:                       Compiling.
* environ/2 <1>:                         System.
* environ/2:                             OS.
* erase/1:                               Internal Database.
* eraseall/1:                            Internal Database.
* erased/1:                              Internal Database.
* exec/3:                                System.
* exists/1:                              I/O Control.
* expand_exprs/2:                        Setting the Compiler.
* expand_term/2:                         Grammars.
* fail/0:                                Control.
* false/0:                               Control.
* fast (yap_flag/2 option):              Misc.
* file (prolog_load_context/2 option):   Misc.
* file_exists/1:                         System.
* file_exists/2:                         System.
* file_property/2:                       System.
* file_search_path/2:                    Setting the Compiler.
* fileerrors (yap_flag/2 option):        Misc.
* fileerrors/0:                          I/O Control.
* find_constraint/2:                     CHR Built-In Predicates.
* find_constraint/3:                     CHR Built-In Predicates.
* findall/3:                             Sets.
* findall/4:                             Sets.
* findall_constraints/2:                 CHR Built-In Predicates.
* findall_constraints/3:                 CHR Built-In Predicates.
* flatten/2:                             Lists.
* float/1:                               Testing Terms.
* flush_output/0:                        Streams and Files.
* flush_output/1:                        Streams and Files.
* format/2:                              I/O of Terms.
* format/3:                              I/O of Terms.
* format_to_chars/3:                     String I/O.
* format_to_chars/4:                     String I/O.
* fragile:                               Cleanup.
* freeze/2:                              Coroutining.
* frozen/2:                              Coroutining.
* functor/3:                             Testing Terms.
* garbage_collect/0:                     Control.
* garbage_collect_atoms/0:               Control.
* garbage_collection (statistics/2 option): Misc.
* gc (yap_flag/2 option):                Misc.
* gc/0:                                  Control.
* gc_margin (yap_flag/2 option):         Misc.
* gc_trace (yap_flag/2 option):          Misc.
* gen_assoc/3:                           Association Lists.
* get/1:                                 I/O of Characters.
* get/2:                                 I/O for Streams.
* get0/1:                                I/O of Characters.
* get0/2:                                I/O for Streams.
* get_assoc/3:                           Association Lists.
* get_assoc/5:                           Association Lists.
* get_atts/2:                            Attribute Manipulation.
* get_byte/1:                            I/O of Characters.
* get_byte/2:                            I/O for Streams.
* get_char/1:                            I/O of Characters.
* get_char/2:                            I/O for Streams.
* get_code/1:                            I/O of Characters.
* get_code/2:                            I/O for Streams.
* get_from_heap/4:                       Heaps.
* get_label/3:                           Trees.
* get_mutable/2:                         Term Modification.
* get_value/2:                           Internal Database.
* getcwd/1:                              OS.
* getrand/1:                             Random.
* global_stack (statistics/2 option):    Misc.
* goal_expansion/3:                      Grammars.
* ground/1:                              Testing Terms.
* grow_stack/1:                          Control.
* halt/0:                                Control.
* halt/1:                                Control.
* head_queue/2:                          Queues.
* heap (statistics/2 option):            Misc.
* heap_size/2:                           Heaps.
* heap_to_list/2:                        Heaps.
* hide/1:                                Setting the Compiler.
* hide_predicate/1:                      Setting the Compiler.
* host_id/1:                             System.
* host_name/1:                           System.
* host_type (yap_flag/2 option):         Misc.
* if/3:                                  Control.
* include/1 (directive):                 Compiling.
* incore/1:                              Control.
* index (yap_flag/2 option):             Misc.
* informational_messages (yap_flag/2 option): Misc.
* initialization/0:                      Misc.
* initialization/1 (directive):          Setting the Compiler.
* insert/4:                              Red-Black Trees.
* insert_constraint/2:                   CHR Built-In Predicates.
* insert_constraint/3:                   CHR Built-In Predicates.
* instance/2:                            Internal Database.
* integer/1:                             Testing Terms.
* integer_rounding_function (yap_flag/2 option): Misc.
* is/2:                                  Arithmetic.
* is_list/1:                             Lists.
* is_mutable/1:                          Term Modification.
* join_queue/3:                          Queues.
* jump_queue/3:                          Queues.
* key_statistics/3:                      Internal Database.
* key_statistics/4:                      Internal Database.
* keysort/2:                             Comparing Terms.
* kill/2:                                System.
* language (yap_flag/2 option):          Misc.
* last/2:                                Lists.
* leash/1:                               Deb Preds.
* length/2:                              Comparing Terms.
* length_queue/2:                        Queues.
* library_directory/1:                   Setting the Compiler.
* list_concat/2:                         Lists.
* list_join_queue/3:                     Queues.
* list_jump_queue/3:                     Queues.
* list_to_assoc/2:                       Association Lists.
* list_to_heap/2:                        Heaps.
* list_to_ord_set/2:                     Ordered Sets.
* list_to_queue/2:                       Queues.
* list_to_tree/2:                        Trees.
* listing/0:                             Looking at the Database.
* listing/1:                             Looking at the Database.
* local_stack (statistics/2 option):     Misc.
* lookup/3:                              Red-Black Trees.
* make_directory/2:                      System.
* make_queue/1:                          Queues.
* map_assoc/3:                           Association Lists.
* map_tree/3:                            Trees.
* mapargs/3:                             Apply Macros.
* maplist/3:                             Apply Macros.
* mapnodes/3:                            Apply Macros.
* max_arity (yap_flag/2 option):         Misc.
* max_integer (yap_flag/2 option):       Misc.
* member/2:                              Lists.
* memberchk/2:                           Lists.
* merge/3:                               Ordered Sets.
* meta_predicate/1 (directive):          Meta-Predicates in Modules.
* min_integer (yap_flag/2 option):       Misc.
* min_of_heap/3:                         Heaps.
* min_of_heap/5:                         Heaps.
* mktemp/2:                              System.
* module (prolog_load_context/2 option): Misc.
* module/1:                              Defining Modules.
* module/2 (directive):                  Defining Modules.
* module/3 (directive):                  Defining Modules.
* multifile/1 (directive):               Setting the Compiler.
* mutex_create/1:                        Thread Synchronisation.
* mutex_destroy/1:                       Thread Synchronisation.
* mutex_lock/1:                          Thread Synchronisation.
* mutex_statistics/0:                    Monitoring Threads.
* mutex_trylock/1:                       Thread Synchronisation.
* mutex_unlock/1:                        Thread Synchronisation.
* mutex_unlock_all/0:                    Thread Synchronisation.
* n_of_integer_keys_in_bb (yap_flag/2 option): Misc.
* n_of_integer_keys_in_db (yap_flag/2 option): Misc.
* name/2:                                Testing Terms.
* neighbors/3:                           UGraphs.
* neighbours/3:                          UGraphs.
* new/1:                                 Red-Black Trees.
* nl/0:                                  I/O of Characters.
* nl/1:                                  I/O for Streams.
* no_source/0:                           Setting the Compiler.
* no_style_check/1:                      Setting the Compiler.
* nodebug/0:                             Deb Preds.
* nofileerrors/0:                        I/O Control.
* nogc/0:                                Control.
* nonvar/1:                              Testing Terms.
* nospy/1:                               Deb Preds.
* nospyall/0:                            Deb Preds.
* not/1:                                 Control.
* notify_constrained/1:                  CHR Built-In Predicates.
* nth/2:                                 Lists.
* nth/4:                                 Lists.
* nth0/2:                                Lists.
* nth0/4:                                Lists.
* nth_clause/3:                          Modifying the Database.
* nth_recorded/3:                        Internal Database.
* number/1:                              Testing Terms.
* number_atom/2:                         Testing Terms.
* number_chars/2:                        Testing Terms.
* number_codes/2:                        Testing Terms.
* number_to_chars/2:                     String I/O.
* number_to_chars/3:                     String I/O.
* numbervars/3:                          Testing Terms.
* on_cleanup/1:                          Cleanup.
* on_signal/3:                           OS.
* once/1:                                Control.
* op/3:                                  Misc.
* open/3:                                Streams and Files.
* open/4:                                Streams and Files.
* open_chars_stream/2:                   String I/O.
* ord_add_element/3:                     Ordered Sets.
* ord_del_element/3:                     Ordered Sets.
* ord_disjoint/2:                        Ordered Sets.
* ord_insert/3:                          Ordered Sets.
* ord_intersect/2:                       Ordered Sets.
* ord_intersect/3:                       Ordered Sets.
* ord_list_to_assoc/2:                   Association Lists.
* ord_member/2:                          Ordered Sets.
* ord_seteq/2:                           Ordered Sets.
* ord_setproduct/3:                      Ordered Sets.
* ord_subtract/3:                        Ordered Sets.
* ord_symdiff/3:                         Ordered Sets.
* ord_union/2:                           Ordered Sets.
* ord_union/3:                           Ordered Sets.
* ord_union/4:                           Ordered Sets.
* ordsubset/2:                           Ordered Sets.
* path/1:                                Setting the Compiler.
* peek_byte/1:                           I/O of Characters.
* peek_byte/2:                           I/O for Streams.
* peek_char/1:                           I/O of Characters.
* peek_char/2:                           I/O for Streams.
* peek_code/1:                           I/O of Characters.
* peek_code/2:                           I/O for Streams.
* permutation/2:                         Lists.
* phrase/2:                              Grammars.
* phrase/3:                              Grammars.
* pid/1:                                 System.
* popen/3:                               System.
* portray_clause/1:                      Looking at the Database.
* portray_clause/2:                      Looking at the Database.
* predicate_property/2:                  Looking at the Database.
* primitive/1:                           Testing Terms.
* print/1:                               I/O of Terms.
* print/2:                               I/O for Streams.
* profile_data/3:                        Profiling.
* profiled_reset/0:                      Profiling.
* profiling (yap_flag/2 option):         Misc.
* program (statistics/2 option):         Misc.
* project_attributes/2 <1>:              Projecting Attributes.
* project_attributes/2:                  Displaying Attributes.
* prolog_file_name/2:                    Setting the Compiler.
* prolog_flag/3:                         Misc.
* prolog_initialization/1:               Misc.
* prolog_load_context/2:                 Misc.
* prompt/2:                              Misc.
* public/1 (directive):                  Setting the Compiler.
* put/1:                                 I/O of Characters.
* put/2:                                 I/O for Streams.
* put_assoc/4:                           Association Lists.
* put_atts/2:                            Attribute Manipulation.
* put_byte/1:                            I/O of Characters.
* put_byte/2:                            I/O for Streams.
* put_char/1:                            I/O of Characters.
* put_char/2:                            I/O for Streams.
* put_code/1:                            I/O of Characters.
* put_code/2:                            I/O for Streams.
* put_label/4:                           Trees.
* putenv/2:                              OS.
* queue_to_list/2:                       Queues.
* random/1:                              Random.
* random/3:                              Random.
* randseq/3:                             Random.
* randset/3:                             Random.
* rannum/1:                              Pseudo Random.
* ranstart/0:                            Pseudo Random.
* ranstart/1:                            Pseudo Random.
* ranunif/2:                             Pseudo Random.
* reachable/3:                           UGraphs.
* read/1:                                I/O of Terms.
* read/2:                                I/O for Streams.
* read_from_chars/2:                     String I/O.
* read_term/2:                           I/O of Terms.
* read_term/3:                           I/O for Streams.
* reconsult/1:                           Compiling.
* recorda/3:                             Internal Database.
* recorda_at/3:                          Internal Database.
* recordaifnot/3:                        Internal Database.
* recorded/3:                            Internal Database.
* recordz/3:                             Internal Database.
* recordz_at/3:                          Internal Database.
* recordzifnot/3:                        Internal Database.
* regexp/3:                              RegExp.
* regexp/4:                              RegExp.
* remove_constraint/1:                   CHR Built-In Predicates.
* remove_duplicates/2:                   Lists.
* remove_from_path/1:                    Setting the Compiler.
* rename/2:                              OS.
* rename_file/2:                         System.
* repeat/0:                              Control.
* reset_op_counters/0:                   Low Level Profiling.
* resize_static_array/3:                 Arrays.
* restore/1:                             Saving.
* retract/1:                             Modifying the Database.
* retract/2:                             Database References.
* retractall/1:                          Modifying the Database.
* reverse/2:                             Lists.
* runtime (statistics/2 option):         Misc.
* same_length/2:                         Lists.
* save/1:                                Saving.
* save/2:                                Saving.
* save_program/1:                        Saving.
* save_program/2:                        Saving.
* see/1:                                 C-Prolog File Handling.
* seeing/1:                              C-Prolog File Handling.
* seen/0:                                C-Prolog File Handling.
* select/3:                              Lists.
* selectlist/3:                          Apply Macros.
* serve_queue/3:                         Queues.
* set_input/1:                           Streams and Files.
* set_output/1:                          Streams and Files.
* set_prolog_flag/2:                     Misc.
* set_stream_position/2:                 Streams and Files.
* set_value/2:                           Internal Database.
* setarg/3n:                             Term Modification.
* setof/3:                               Sets.
* setrand/1:                             Random.
* sh/0:                                  OS.
* shell/0:                               System.
* shell/1:                               System.
* show_op_counters/1:                    Low Level Profiling.
* show_ops_by_group/1:                   Low Level Profiling.
* simple/1:                              Testing Terms.
* single_var_warnings (yap_flag/2 option): Misc.
* singletons/1 (read_term/2 option):     I/O of Terms.
* skip/1:                                I/O of Characters.
* skip/2:                                I/O for Streams.
* sleep/1:                               System.
* socket/2:                              Sockets.
* socket/4:                              Sockets.
* socket_accept/2:                       Sockets.
* socket_accept/3:                       Sockets.
* socket_bind/2:                         Sockets.
* socket_buffering/4:                    Sockets.
* socket_close/1:                        Sockets.
* socket_connect/3:                      Sockets.
* socket_listen/2:                       Sockets.
* socket_select/5:                       Sockets.
* sort/2:                                Comparing Terms.
* source/0:                              Setting the Compiler.
* source_mode/2:                         Setting the Compiler.
* splay_access/5:                        Splay Trees.
* splay_delete/4:                        Splay Trees.
* splay_init/3:                          Splay Trees.
* splay_insert/4:                        Splay Trees.
* splay_join/3:                          Splay Trees.
* splay_split/5:                         Splay Trees.
* spy/1:                                 Deb Preds.
* spy_write/2:                           Deb Preds.
* srandom/1:                             Arithmetic.
* stack_dump_on_error (yap_flag/2 option): Misc.
* stack_shifts (stack_shifts/3 option):  Misc.
* start_low_level_trace/0:               Low Level Tracing.
* static_array/3:                        Arrays.
* static_array_properties/3:             Arrays.
* static_array_to_term/3:                Arrays.
* statistics/0:                          Misc.
* statistics/2:                          Misc.
* stream_property/2:                     Streams and Files.
* stream_select/3:                       Streams and Files.
* strict_iso (prolog_flag/2 option):     Misc.
* style_check/1:                         Setting the Compiler.
* sub_atom/5:                            Testing Terms.
* sub_edges/3:                           UGraphs.
* sublist/2:                             Lists.
* subsumes/2:                            Terms.
* subsumes_chk/2:                        Terms.
* suffix/2:                              Lists.
* sum_list/2:                            Lists.
* sumargs/4:                             Apply Macros.
* sumlist/2:                             Lists.
* sumlist/4:                             Apply Macros.
* sumnodes/4:                            Apply Macros.
* syntax_errors (yap_flag/2 option):     Misc.
* syntax_errors/1 (read_term/2 option):  I/O of Terms.
* system/0:                              System.
* system/1:                              OS.
* system/2:                              System.
* system_options (yap_flag/2 option):    Misc.
* system_predicate/2:                    Looking at the Database.
* tab/1:                                 I/O of Characters.
* tab/2:                                 I/O for Streams.
* tell/1:                                C-Prolog File Handling.
* telling/1:                             C-Prolog File Handling.
* term_expansion/2:                      Grammars.
* term_hash/2:                           Terms.
* term_hash/4:                           Terms.
* term_variables/2:                      Terms.
* thread_at_exit/1:                      Creating and Destroying Prolog Threads.
* thread_create/3:                       Creating and Destroying Prolog Threads.
* thread_detach/1:                       Creating and Destroying Prolog Threads.
* thread_exit/1:                         Creating and Destroying Prolog Threads.
* thread_get_message/1:                  Message Queues.
* thread_get_message/2:                  Message Queues.
* thread_join/2:                         Creating and Destroying Prolog Threads.
* thread_local/1 (directive):            Threads and Dynamic Predicates.
* thread_message_queue_create/1:         Message Queues.
* thread_message_queue_destroy/1:        Message Queues.
* thread_peek_message/1:                 Message Queues.
* thread_self/1:                         Creating and Destroying Prolog Threads.
* thread_send_message/2:                 Message Queues.
* thread_setconcurrency/2:               Creating and Destroying Prolog Threads.
* thread_signal/2:                       Signalling Threads.
* thread_statistics/3:                   Monitoring Threads.
* throw/1:                               Control.
* time_out/3:                            Timeout.
* tmpnam/1:                              System.
* to_chars_modes (yap_flag/2 option):    Misc.
* told/0:                                C-Prolog File Handling.
* top_sort/2:                            UGraphs.
* toplevel_hook (yap_flag/2 option):     Misc.
* trail (statistics/2 option):           Misc.
* transitive_closure/2:                  UGraphs.
* transpose/3:                           UGraphs.
* tree_size/2:                           Trees.
* tree_to_list/2:                        Trees.
* true/0:                                Control.
* ttyget/1:                              C-Prolog to Terminal.
* ttyget0/1:                             C-Prolog to Terminal.
* ttynl/0:                               C-Prolog to Terminal.
* ttyput/1:                              C-Prolog to Terminal.
* ttyskip/1:                             C-Prolog to Terminal.
* ttytab/1:                              C-Prolog to Terminal.
* typein_module (yap_flag/2 option):     Misc.
* unconstrained/1:                       CHR Built-In Predicates.
* unhide/1:                              Setting the Compiler.
* unify_with_occurs_check/2:             Testing Terms.
* unix/1:                                OS.
* unknown (yap_flag/2 option):           Misc.
* unknown/2:                             Undefined Procedures.
* unknown_predicate_handler/3:           Undefined Procedures.
* update_array/3:                        Arrays.
* update_mutable/2:                      Term Modification.
* update_semantics (yap_flag/2 option):  Misc.
* use_module/1:                          Using Modules.
* use_module/2:                          Using Modules.
* use_module/3:                          Using Modules.
* user_error (yap_flag/2 option):        Misc.
* user_input (yap_flag/2 option):        Misc.
* user_output (yap_flag/2 option):       Misc.
* var/1:                                 Testing Terms.
* variable_in_term/2:                    Terms.
* variable_names/1 (read_term/2 option): I/O of Terms.
* variables/1 (read_term/2 option):      I/O of Terms.
* variant/2:                             Terms.
* verify_attributes/3:                   Attributed Unification.
* version (yap_flag/2 option):           Misc.
* version/0:                             Misc.
* version/1:                             Misc.
* vertices/2:                            UGraphs.
* vertices_edges_to_ugraph/3:            UGraphs.
* wait/2:                                System.
* walltime (statistics/2 option):        Misc.
* when/2:                                Coroutining.
* with_mutex/2:                          Thread Synchronisation.
* with_output_to_chars/2:                String I/O.
* with_output_to_chars/3:                String I/O.
* with_output_to_chars/4:                String I/O.
* working_directory/2:                   System.
* write/1:                               I/O of Terms.
* write/2:                               I/O for Streams.
* write_depth/2:                         I/O Control.
* write_strings (yap_flag/2 option):     Misc.
* write_term/2:                          I/O of Terms.
* write_term/3:                          I/O for Streams.
* write_to_chars/2:                      String I/O.
* write_to_chars/3:                      String I/O.
* writeq/1:                              I/O of Terms.
* writeq/2:                              I/O for Streams.
* YAP_AllocSpaceFromYap (C-Interface function): Memory Allocation.
* YAP_ArgOfTerm (C-Interface function):  Manipulating Terms.
* YAP_ArityOfFunctor (C-Interface function): Manipulating Terms.
* YAP_AtomName (C-Interface function):   Manipulating Terms.
* YAP_AtomOfTerm (C-Interface function): Manipulating Terms.
* YAP_BufferToAtomList (C-Interface function): Manipulating Strings.
* YAP_BufferToString (C-Interface function): Manipulating Strings.
* YAP_CallProlog (C-Interface function): Calling Yap From C.
* YAP_CloseAllOpenStreams (C-Interface function): Controlling Streams.
* YAP_cutfail (C-Interface function):    Writing C.
* YAP_cutsucceed (C-Interface function): Writing C.
* yap_flag/2:                            Misc.
* YAP_FloatOfTerm (C-Interface function): Manipulating Terms.
* YAP_FreeSpaceFromYap (C-Interface function): Memory Allocation.
* YAP_FullLookupAtom (C-Interface function): Manipulating Terms.
* YAP_FunctorOfTerm (C-Interface function): Manipulating Terms.
* YAP_HeadOfTerm (C-Interface function): Manipulating Terms.
* YAP_IntOfTerm (C-Interface function):  Manipulating Terms.
* YAP_IsApplTerm (C-Interface function): Manipulating Terms.
* YAP_IsAtomTerm (C-Interface function): Manipulating Terms.
* YAP_IsDBRefTerm (C-Interface function): Manipulating Terms.
* YAP_IsFloatTerm (C-Interface function): Manipulating Terms.
* YAP_IsIntTerm (C-Interface function):  Manipulating Terms.
* YAP_IsNonVarTerm (C-Interface function): Manipulating Terms.
* YAP_IsPairTerm (C-Interface function): Manipulating Terms.
* YAP_IsVarTerm (C-Interface function):  Manipulating Terms.
* YAP_LookupAtom (C-Interface function): Manipulating Terms.
* YAP_MkApplTerm (C-Interface function): Manipulating Terms.
* YAP_MkAtomTerm (C-Interface function): Manipulating Terms.
* YAP_MkFloatTerm (C-Interface function): Manipulating Terms.
* YAP_MkFunctor (C-Interface function):  Manipulating Terms.
* YAP_MkIntTerm (C-Interface function):  Manipulating Terms.
* YAP_MkNewApplTerm (C-Interface function): Manipulating Terms.
* YAP_MkNewPairTerm (C-Interface function): Manipulating Terms.
* YAP_MkPairTerm (C-Interface function): Manipulating Terms.
* YAP_NameOfFunctor (C-Interface function): Manipulating Terms.
* YAP_OpenStream (C-Interface function): Controlling Streams.
* YAP_PRESERVE_DATA (C-Interface function): Writing C.
* YAP_PRESERVED_DATA (C-Interface function): Writing C.
* YAP_StreamToFileNo (C-Interface function): Controlling Streams.
* YAP_StringToBuffer (C-Interface function): Manipulating Strings.
* YAP_TailOfTerm (C-Interface function): Manipulating Terms.
* YAP_Unify (C-Interface function):      Unifying Terms.
* YAP_UserBackCPredicate (C-Interface function): Writing C.
* YAP_UserCPredicate (C-Interface function): Writing C.
* YAPBINDIR:                             Running Yap Interactively.
* YapCompileClause/1:                    YapLibrary.
* YapContinueGoal/0:                     YapLibrary.
* YapEndConsult/0:                       YapLibrary.
* YapError/1:                            YapLibrary.
* YapExit/1:                             YapLibrary.
* YapFastInit/1:                         YapLibrary.
* YapGetValue/1:                         YapLibrary.
* YapInit/9:                             YapLibrary.
* YapInitConsult/2:                      YapLibrary.
* YAPLIBDIR:                             Running Yap Interactively.
* YapPutValue/2:                         YapLibrary.
* YapRead/1:                             YapLibrary.
* YapReset/0:                            YapLibrary.
* YapRestartGoal/0:                      YapLibrary.
* YapRunGoal/1:                          YapLibrary.
* YAPSHAREDIR:                           Running Yap Interactively.


File: yap.info,  Node: Concept Index,  Prev: Predicate Index,  Up: Top

Concept Index
*************

* Menu:

* anonymous variable:                    Variables.
* association list:                      Association Lists.
* atom:                                  Atoms.
* attribute declaration:                 Attribute Declarations.
* attributed variables:                  Attributed Variables.
* AVL trees:                             AVL Trees.
* booting:                               Run.
* CHR control flow model:                CHR Control Flow Model.
* CHR debugging messages:                CHR Debugging Messages.
* CHR debugging options:                 CHR Debugging Options.
* CHR debugging predicates:              CHR Debugging Predicates.
* CHR spy-points:                        CHR Spy-points.
* cleanup:                               Cleanup.
* CLPQ:                                  CLPQR.
* CLPR:                                  CLPQR.
* comment:                               Layout.
* Counting Calls:                        Call Counting.
* declaration, attribute:                Attribute Declarations.
* end of term:                           Formal Syntax.
* environment variables:                 Running Yap Interactively.
* floating-point number:                 Floats.
* heap:                                  Heaps.
* installation:                          Install.
* integer:                               Integers.
* list manipulation:                     Lists.
* logtalk:                               Logtalk.
* machine optimizations:                 Machine Options.
* macros:                                Apply Macros.
* mutable variables:                     Term Modification.
* number:                                Numbers.
* Operating System Utilities:            System.
* or-parallelism:                        Parallelism.
* ordered set:                           Ordered Sets.
* parallelism:                           Parallelism.
* profiling:                             Profiling.
* pseudo random:                         Pseudo Random.
* punctuation token:                     Punctuation Tokens.
* queue <1>:                             Random.
* queue:                                 Queues.
* Red-Black Trees:                       Red-Black Trees.
* regular expressions:                   RegExp.
* splay trees:                           Splay Trees.
* string:                                Strings.
* string I/O:                            String I/O.
* syntax <1>:                            Formal Syntax.
* syntax:                                Configuration Options.
* tabling:                               Tabling.
* timeout:                               Timeout.
* token:                                 Tokens.
* unweighted graphs:                     UGraphs.
* updatable tree:                        Trees.
* update semantics:                      Major Differences with SICStus.
* updating terms:                        Term Modification.
* utilities on terms:                    Terms.
* variable:                              Variables.


