YAP User's Manual: V Itor Santos Costa, Lu Is Damas, Rog Erio Reis, and R Uben Azevedo
YAP User's Manual: V Itor Santos Costa, Lu Is Damas, Rog Erio Reis, and R Uben Azevedo
Table of Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1 Installing YAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1 Tuning the Functionality of YAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Tuning YAP for a Particular Machine and Compiler . . . . . . . . . . . 4
1.3 Tuning YAP for GCC. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.1 Compiling Under Visual C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.3.2 Compiling Under SGI’s cc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Running YAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1 Running Yap Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Running Prolog Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.1 Syntax of Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.2 Prolog Tokens. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.1 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.1.1 Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2.1.2 Floating-point Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2.2 Character Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2.3 Atoms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2.4 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.2.5 Punctuation Tokens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2.6 Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4 Loading Programs . . . . . . . . . . . . . . . . . . . . . . . . 19
4.1 Program loading and updating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2 Changing the Compiler’s Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.3 Saving and Loading Prolog States . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
6 Built-In Predicates . . . . . . . . . . . . . . . . . . . . . . . 27
6.1 Control Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
6.2 Handling Undefined Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
6.3 Predicates on terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
6.4 Comparing Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6.5 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.6 I/O Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.6.1 Handling Streams and Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
6.6.2 Handling Streams and Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.6.3 Handling Input/Output of Terms . . . . . . . . . . . . . . . . . . . . . . . 44
6.6.4 Handling Input/Output of Characters . . . . . . . . . . . . . . . . . . . 48
6.6.5 Input/Output Predicates applied to Streams . . . . . . . . . . . . . 50
6.6.6 Compatible C-Prolog predicates for Terminal I/O . . . . . . . . 51
6.6.7 Controlling Input/Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
6.6.8 Using Sockets From Yap. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
6.7 Using the Clausal Data Base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
6.7.1 Modification of the Data Base . . . . . . . . . . . . . . . . . . . . . . . . . . 55
6.7.2 Looking at the Data Base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
6.7.3 Using Data Base References . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
6.8 Internal Data Base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
6.9 The Blackboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6.10 Collecting Solutions to a Goal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6.11 Grammar Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
6.12 Access to Operating System Functionality . . . . . . . . . . . . . . . . . . . 64
6.13 Term Modification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
6.14 Profiling Prolog Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.15 Counting Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
6.16 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6.17 Predicate Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.18 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
7 Library Predicates . . . . . . . . . . . . . . . . . . . . . . . . 83
7.1 Apply Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
7.2 Association Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
7.3 AVL Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.4 Heaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.5 List Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.6 Ordered Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.7 Pseudo Random Number Integer Generator . . . . . . . . . . . . . . . . . . 90
7.8 Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7.9 Random Number Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
7.10 Red-Black Trees. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.11 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
7.12 Splay Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
7.13 Reading From and Writing To Strings . . . . . . . . . . . . . . . . . . . . . . 96
7.14 Calling The Operating System from YAP . . . . . . . . . . . . . . . . . . . 98
7.15 Utilities On Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
7.16 Call Cleanup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
iii
13 Logtalk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
14 Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
14.1 Creating and Destroying Prolog Threads . . . . . . . . . . . . . . . . . . . 139
14.2 Monitoring Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
14.3 Thread communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
14.3.1 Message Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
14.3.2 Signalling Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
14.3.3 Threads and Dynamic Predicates . . . . . . . . . . . . . . . . . . . . . 144
14.4 Thread Synchronisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
15 Parallelism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
16 Tabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
19 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
19.1 Debugging Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
19.2 Interacting with the debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
20 Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Introduction
This document provides User information on version [No value for “VERSION”] of YAP (yet
another prolog). The YAP Prolog System is a high-performance Prolog compiler developed
at LIACC, Universidade do Porto. YAP provides several important features:
• Speed: YAP is widely considered one of the fastest available Prolog systems.
• Functionality: it supports stream I/O, sockets, modules, exceptions, Prolog debugger,
C-interface, dynamic code, internal database, DCGs, saved states, co-routining, arrays.
• We explicitly allow both commercial and non-commercial use of YAP.
YAP is based on the David H. D. Warren’s WAM (Warren Abstract Machine), with
several optimizations for better performance. YAP follows the Edinburgh tradition, and
was originally designed to be largely compatible with DEC-10 Prolog, Quintus Prolog, and
especially with C-Prolog.
YAP implements most of the ISO-Prolog standard. We are striving at full compatibil-
ity, and the manual describes what is still missing. The manual also includes a (largely
incomplete) comparison with SICStus Prolog.
The document is intended neither as an introduction to Prolog nor to the implementation
aspects of the compiler. A good introduction to programming in Prolog is the book The Art
of Prolog, by L. Sterling and E. Shapiro, published by "The MIT Press, Cambridge MA".
Other references should include the classical Programming in Prolog, by W.F. Clocksin and
C.S. Mellish, published by Springer-Verlag.
YAP 4.3 is known to build with many versions of gcc (<= gcc-2.7.2, >= gcc-2.8.1, >=
egcs-1.0.1, gcc-2.95.*) and on a variety of Unixen: SunOS 4.1, Solaris 2.*, Irix 5.2, HP-UX
10, Dec Alpha Unix, Linux 1.2 and Linux 2.* (RedHat 4.0 thru 5.2, Debian 2.*) in both the
x86 and alpha platforms. It has been built on Windows NT 4.0 using Cygwin from Cygnus
Solutions (see README.nt) and using Visual C++ 6.0.
The overall copyright and permission notice for YAP4.3 can be found in the Artistic
file in this directory. YAP follows the Perl Artistic license, and it is thus non-copylefted
freeware.
If you have a question about this software, desire to add code, found a bug,
want to request a feature, or wonder how to get further assistance, please send
e-mail to [email protected]. To subscribe to the mailing list, send a request to
[email protected] with body "subscribe yappers".
Online documentation is available for YAP at:
http://www.ncc.up.pt/~vsc/Yap/
Recent versions of Yap, including both source and selected binaries, can be found from
this same URL.
This manual was written by Vı́tor Santos Costa, Luı́s Damas, Rogério Reis, and Rúben
Azevedo. The manual is largely based on the DECsystem-10 Prolog User’s Manual by D.L.
Bowen, L. Byrd, F. C. N. Pereira, L. M. Pereira, and D. H. D. Warren. We have also used
comments from the Edinburgh Prolog library written by R. O’Keefe. We would also like to
gratefully acknowledge the contributions from Ashwin Srinivasian.
We are happy to include in YAP several excellent packages developed under separate
licenses. Our thanks to the authors for their kind authorization to include these packages.
2 YAP Prolog User’s Manual
1 Installing YAP
To compile YAP it should be sufficient to:
1. mkdir ARCH.
2. cd ARCH.
3. ../configure ...options....
Notice that by default configure gives you a vanilla configuration. For instance, in
order to use coroutining and/or CLP you need to do
../configure --enable-coroutining ...options...
Please see Section 1.1 [Configuration Options], page 3 for extra options.
4. check the Makefile for any extensions or changes you want to make.
YAP uses autoconf. Recent versions of Yap try to follow GNU conventions on where
to place software.
• The main executable is placed at BINDIR. This executable is actually a script that
calls the Prolog engine, stored at LIBDIR.
• LIBDIR is the directory where libraries are stored. YAPLIBDIR is a subdirectory
that contains the Prolog engine and a Prolog library.
• INCLUDEDIR is used if you want to use Yap as a library.
• INFODIR is where to store info files. Usually /usr/local/info, /usr/info, or
/usr/share/info.
5. make.
6. If the compilation succeeds, try ./yap.
7. If you feel satisfied with the result, do make install.
8. make install-info will create the info files in the standard info directory.
9. make html will create documentation in html format in the predefined directory.
In most systems you will need to be superuser in order to do make install and make
info on the standard directories.
• --enable-condor=yes allows using the Condor system that support High Throughput
Computing (HTC) on large collections of distributively owned computing resources.
• --enable-tabling=yes allows tabling support. This option is still experimental.
• --enable-parallelism={env-copy,sba,a-cow} allows or-parallelism supported by
one of these three forms. This option is still highly experimental.
• --with-gmp[=DIR] give a path to where one can find the GMP library if not installed
in the default path.
Next follow machine dependent details:
Pentium:
YAP_EXTRAS= ... -m486 -malign-loops=2 -malign-jumps=2 \
-malign-functions=2
PentiumPro and other recent Intel and AMD machines:
PentiumPros are known not to require alignment. Check your version of GCC
for the best -march option.
Super and UltraSparcs:
YAP_EXTRAS= ... -msupersparc
MIPS: if have a recent machine and you need a 64 bit wide address
space you can use the abi 64 bits or eabi option, as in:
CC="gcc -mabi=64" ./configure --...
Be careful. At least for some versions of GCC, compiling with -g seems to result
in broken code.
WIN32: GCC is distributed in the MINGW32 and CYGWIN packages.
The Mingw32 environment is available from the URL:
http://www.mingw.org
You will need to install the msys and mingw packages. You should be able to
do configure, make and make install.
If you use mingw32 you may want to search the contributed packages for the
gmp multi-precision arithmetic library. If you do setup Yap with gmp note that
libgmp.dll must be in the path, otherwise Yap will not be able to execute.
CygWin environment is available from the URL:
http://www.cygwin.com
and mirrors. We suggest using recent versions of the cygwin shell. The compi-
lation steps under the cygwin shell are as follows:
mkdir cyg
$YAPSRC/configure --enable-coroutining \\
--enable-depth-limit \\
--enable-max-performance
make
make install
By default, Yap will use the --enable-cygwin=no option to disable the use of
the cygwin dll and to enable the mingw32 subsystem instead. Yap thus will
not need the cygwin dll. It instead accesses the system’s CRTDLL.DLL C run
time library supplied with Win32 platforms through the mingw32 interface.
Note that some older WIN95 systems may not have CRTDLL.DLL, in this case it
should be sufficient to import the file from a newer WIN95 or WIN98 machine.
You should check the default installation path which is set to /Yap in the stan-
dard Makefile. This string will usually be expanded into c:\Yap by Windows.
The cygwin environment does not provide gmp. You can fetch a dll for the gmp
library from http://www.sf.net/projects/mingwrep.
It is also possible to configure Yap to be a part of the cygwin environment. In
this case you should use:
6 YAP Prolog User’s Manual
mkdir cyg
$YAPSRC/configure --enable-coroutining \\
--enable-max-performance \\
--enable-cygwin=yes
make
make install
Yap will then compile using the cygwin library and will be installed in cyg-
win’s /usr/local. You can use Yap from a cygwin console, or as a standalone
application as long as it can find cygwin1.dll in its path.
4. You may want to go to Build.Set Active Configuration and set Project Type to
Release.
5. you will eventually need to bootstrap the system by booting from boot.yap, so write:
-b $YAPSRC\pl\boot.yap
in Project.Project Settings.Debug.Program Arguments.
6. You need the sockets and yap libraries. Add
ws2_32.lib yapdll.lib to
to
to Project.Project Settings.Link.Object/Library Modules
You may also need to set the Link Path so that VC++ will find yapdll.lib.
7. set Project.Project Settings.C/C++.Preprocessor.Additional Include
Directories to include the $YAPSRC/VC/include and $YAPSRC/include.
The syntax is:
$YAPSRC\VC\include, $YAPSRC\include
8. Build the system.
9. Use Build.Start Debug to boot the system, and then create the saved state with
[’$YAPSRC\\pl\\init’].
save_program(startup).
^Z
That’s it, you’ve got Yap and the saved state!
The $YAPSRC\VC directory has the make files to build Yap4.3.17 under VC++ 6.0.
2 Running YAP
We next describe how to invoke Yap in Unix systems.
• YAP usually boots from a saved state. The saved state will use the default installation
directory to search for the YAP binary unless you define the environment variable
YAPBINDIR.
• YAP always tries to find saved states from the current directory first. If it cannot it
will use the environment variable YAPLIBDIR, if defined, or search the default library
directory.
• YAP will try to find library files from the YAPSHAREDIR/library directory.
The #! characters specify that the script should call the binary file Yap. Notice that
many systems will require the complete path to the Yap binary. The -L flag indicates that
YAP should consult the current file when booting and then halt. The remaining arguments
are then passed to YAP. Note that YAP will skip the first lines if they start with # (the
comment sign for Unix’s shell). YAP will consult the file and execute any commands.
A slightly more sophisticated example is:
#!/usr/bin/yap -L --
#
# Hello World script file using Yap
# .
:- initialization(main).
The initialization directive tells Yap to execute the goal main after consulting the
file. Source code is thus compiled and main executed at the end. The . is useful while
debugging the script as a Prolog program: it guarantees that the syntax error will not
propagate to the Prolog code.
Notice that the -- is required so that the shell passes the extra arguments to YAP. As
an example, consider the following script dump_args:
Chapter 2: Running YAP 11
#!/usr/bin/yap -L --
#.
main( [] ).
main( [H|T] ) :-
write( H ), nl,
main( T ).
main( [] ).
main( [H|T] ) :-
write( H ), nl,
main( T ).
The -- indicates the next arguments are not for YAP. Instead, they must be sent directly
to the argv built-in. Hence, running
./dump_args test
will write test on the standard output.
12 YAP Prolog User’s Manual
Chapter 3: Syntax 13
3 Syntax
We will describe the syntax of YAP at two levels. We first will describe the syntax for
Prolog terms. In a second level we describe the tokens from which Prolog terms are built.
Notes:
• op(N,T) denotes an atom which has been previously declared with type T and base
precedence N.
• Since ’,’ is itself a pre-declared operator with type xfy and precedence 1000, is subterm
starts with a ’(’, op must be followed by a space to avoid ambiguity with the case of a
functor followed by arguments, e.g.:
+ (a,b) [the same as ’+’(’,’(a,b)) of arity one]
versus
+(a,b) [the same as ’+’(a,b) of arity two]
• In the first rule for term(0) no blank space should exist between atom and ’(’.
• Each term to be read by the YAP parser must end with a single dot, followed by a
blank (in the sense mentioned in the previous paragraph). When a name consisting
of a single dot could be taken for the end of term marker, the ambiguity should be
avoided by surrounding the dot with single quotes.
3.2.1 Numbers
Numbers can be further subdivided into integer and floating-point numbers.
3.2.1.1 Integers
Integer numbers are described by the following regular expression:
<integer> := {<digit>+<single-quote>|0{xXo}}<alpha_numeric_char>+
where {...} stands for optionality, + optional repetition (one or more times), <digit> denotes
one of the characters 0 ... 9, | denotes or, and <single-quote> denotes the character "’".
The digits before the <single-quote> character, when present, form the number basis, that
can go from 0, 1 and up to 36. Letters from A to Z are used when the basis is larger than
10.
Note that if no basis is specified then base 10 is assumed. Note also that the last digit
of an integer token can not be immediately followed by one of the characters ’e’, ’E’, or ’.’.
Following the ISO standard, YAP also accepts directives of the form 0x to represent
numbers in hexadecimal base and of the form 0o to represent numbers in octal base. For
usefulness, YAP also accepts directives of the form 0X to represent numbers in hexadecimal
base.
Example: the following tokens all denote the same integer
10 2’1010 3’101 8’12 16’a 36’a 0xa 0o12
Numbers of the form 0’a are used to represent character constants. So, the following
tokens denote the same integer:
Chapter 3: Syntax 15
0’d 100
YAP (version [No value for “VERSION”]) supports integers that can fit the word size
of the machine. This is 32 bits in most current machines, but 64 in some others, such as
the Alpha running Linux or Digital Unix. The scanner will read larger or smaller integers
erroneously.
<float> := <digit>+{<dot><digit>+}
<exponent-marker>{<sign>}<digit>+
|<digit>+<dot><digit>+
{<exponent-marker>{<sign>}<digit>+}
where <dot> denotes the decimal-point character ’.’, <exponent-marker> denotes one of ’e’
or ’E’, and <sign> denotes one of ’+’ or ’-’.
Examples:
10.0 10e3 10e-3 3.1415e+3
Floating-point numbers are represented as a double in the target machine. This is usually
a 64-bit number.
3.2.3 Atoms
Atoms are defined by one of the following rules:
atom --> solo-character
atom --> lower-case-letter name-character*
atom --> symbol-character+
atom --> single-quote single-quote
atom --> ’’’ atom_quoted_characters ’’’
where:
<solo-character> denotes one of: ! ;
<symbol-character> denotes one of: # & * + - . / : <
= > ? @ \ ^ ‘ ~
<lower-case-letter> denotes one of: a...z
<name-character> denotes one of: _ a...z A...Z 0....9
<single-quote> denotes: ’
and string_character denotes any character except the double quote and escape char-
acters. Note that escape sequences in strings and atoms follow the same rules.
Examples:
a a12x ’$a’ ! => ’1 2’
Version 4.2.0 of YAP removed the previous limit of 256 characters on an atom. Size of
an atom is now only limited by the space available in the system.
3.2.4 Variables
Variables are described by:
<variable-starter><variable-character>+
where
Chapter 3: Syntax 17
3.2.6 Layout
Any characters with ASCII code less than or equal to 32 appearing before a token are
ignored.
All the text appearing in a line after the character % is taken to be a comment and
ignored (including % ). Comments can also be inserted by using the sequence /* to start
the comment and */ to finish it. In the presence of any sequence of comments or layout
characters, the YAP parser behaves as if it had found a single blank character. The end of
a file also counts as a blank character for this purpose.
18 YAP Prolog User’s Manual
Chapter 4: Loading Programs 19
4 Loading Programs
no_source
The opposite to source.
The same as source_mode(_,off).
compile_expressions
After a call to this predicate, arithmetical expressions will be compiled. (see
example below). This is the default behavior.
do_not_compile_expressions
After a call to this predicate, arithmetical expressions will not be compiled.
?- source, do_not_compile_expressions.
yes
?- [user].
| p(X) :- X is 2 * (3 + 8).
| :- end_of_file.
?- compile_expressions.
yes
?- [user].
| q(X) :- X is 2 * (3 + 8).
| :- end_of_file.
:- listing.
p(A):-
A is 2 * (3 + 8).
q(A):-
A is 22.
hide(+Atom )
Make atom Atom invisible.
unhide(+Atom )
Make hidden atom Atom visible.
hide_predicate(+Pred )
Make predicate Pred invisible to current_predicate/2, listing, and friends.
expand_exprs(-O,+N )
Puts YAP in state N (on or off) and unify O with the previous state, where
On is equivalent to compile_expressions and off is equivalent to do_not_
compile_expressions. This predicate was kept to maintain compatibility with
C-Prolog.
path(-D ) Unifies D with the current directory search-path of YAP. Note that this search-
path is only used by YAP to find the files for consult/1, reconsult/1 and
restore/1 and should not be taken for the system search path.
add_to_path(+D )
Adds D to the end of YAP’s directory search path.
Chapter 4: Loading Programs 21
add_to_path(+D,+N )
Inserts D in the position, of the directory search path of YAP, specified by N.
N must be either of first or last.
remove_from_path(+D )
Remove D from YAP’s directory search path.
style_check(+X )
Turns on style checking according to the attribute specified by X, which must
be one of the following:
single_var
Checks single occurrences of named variables in a clause.
discontiguous
Checks non-contiguous clauses for the same predicate in a file.
multiple Checks the presence of clauses for the same predicate in more than
one file when the predicate has not been declared as multifile
all Performs style checking for all the cases mentioned above.
By default, style checking is disabled in YAP unless we are in sicstus or iso
language mode.
The style_check/1 built-in is now deprecated. Please use the set_prolog_
flag/1 instead.
no_style_check(+X )
Turns off style checking according to the attribute specified by X, which has
the same meaning as in style_check/1.
The no_style_check/1 built-in is now deprecated. Please use the set_prolog_
flag/1 instead.
multifile P [ISO]
Instructs the compiler about the declaration of a predicate P in more than
one file. It must appear in the first of the loaded files where the predicate is
declared, and before declaration of any of its clauses.
Multifile declarations affect reconsult/1 and compile/1: when a multifile
predicate is reconsulted, only the clauses from the same file are removed.
Since Yap4.3.0 multifile procedures can be static or dynamic.
discontiguous(+G ) [ISO]
Declare that the arguments are discontiguous procedures, that is, clauses for
discontigous procedures may be separated by clauses from other procedures.
initialization(+G ) [ISO]
The compiler will execute goals G after consulting the current file.
library_directory(+D )
Succeeds when D is a current library directory name. Library directories are
the places where files specified in the form library(File ) are searched by the
predicates consult/1, reconsult/1, use_module/1 or ensure_loaded/1.
22 YAP Prolog User’s Manual
file_search_path(+NAME,-DIRECTORY )
Allows writing file names as compound terms. The NAME and DIRECTORY
must be atoms. The predicate may generate multiple solutions. The predicate
is originally defined as follows:
file_search_path(library,A) :-
library_directory(A).
file_search_path(system,A) :-
prolog_flag(host_type,A).
Thus, [library(A)] will search for a file using library directory/1 to obtain the
prefix.
library_directory(+D )
Succeeds when D is a current library directory name. Library directories are
the places where files specified in the form library(File ) are searched by the
predicates consult/1, reconsult/1, use_module/1 or ensure_loaded/1.
prolog_file_name(+Name,-FullPath )
Unify FullPath with the absolute path YAP would use to consult file Name.
public P [ISO]
Instructs the compiler that the source of a predicate of a list of predicates P
must be kept. This source is then accessible through the clause/2 procedure
and through the listing family of built-ins.
Note that all dynamic procedures are public. The source directive defines all
new or redefined predicates to be public.
Since Yap4.3.0 multifile procedures can be static or dynamic.
The rules for goals are similar. If a goal appears in a text file with a module declaration,
the goal’s source module is the declared module. Otherwise, it is the module the file is
being loaded into or the type-in module.
One can override this rule by prefixing a goal with the module it is supposed to be
executed into, say:
nasa:launch(apollo,13).
will execute the goal launch(apollo,13) as if the current source module was nasa.
Note that this rule breaks encapsulation and should be used with care.
24 YAP Prolog User’s Manual
module(+M,+L )
This predicate defines the file where it appears as a module file; it must be the
first declaration in the file. M must be an atom specifying the module name;
L must be a list containing the module’s public predicates specification, in the
form [predicate_name/arity,...].
The public predicates of a module file can be made accessible by other files
through the predicates consult/1, reconsult/1, ensure_loaded/1 or use_
module/2. The non-public predicates of a module file are not visible by other
files; they can, however, be accessed if the module name is prefixed to the file
name through the :/2 operator.
module(+M,+L, +Options )
Similar to module/2, this predicate defines the file where it appears as a module
file; it must be the first declaration in the file. M must be an atom specifying
the module name; L must be a list containing the module’s public predicates
specification, in the form [predicate_name/arity,...].
The last argument Options must be a list of options, which can be:
filename the filename for a module to import into the current module.
library(file)
a library file to import into the current module.
hide(Opt )
if Opt is false, keep source code for current module, if true, dis-
able.
module(+M )
Defines M to be the current working or type-in module. All files which are not
binded to a module are assumed to belong to the working module (also referred
to as type-in module). To compile a non-module file into a module which is
not the working one, prefix the file name with the module name, in the form
Module :File , when loading the file.
use_module(+F )
Loads the files specified by F, importing all their public predicates. Predi-
cate name clashes are resolved by asking the user about importing or not the
predicate. A warning is displayed when F is not a module file.
Chapter 5: The Module System 25
use_module(+F,+L )
Loads the files specified by F, importing the predicates specified in the list L.
Predicate name clashes are resolved by asking the user about importing or not
the predicate. A warning is displayed when F is not a module file.
use_module(?M,?F,+L )
If module M has been defined, import the procedures in L to the current module.
Otherwise, load the files specified by F, importing the predicates specified in
the list L.
...
a(G) :- call(G)
...
The expected behavior for this procedure is to execute goal G within the current module,
that is, within example. On the other hand, when executing call/1 the system only knows
where call/1 was defined, that is, it only knows of primitives. A similar problem arises
for assert/1 and friends.
The meta_predicate/1 declaration informs the system that some arguments of a pro-
cedure are goals, clauses or clauses heads, and that these arguments must be expanded to
receive the current source module:
meta_predicate G1,....,Gn
Each Gi is a mode specification. For example, a declaration for call/1 and
setof/3 would be of the form:
:- meta_predicate call(:), setof(?,:,?).
If the argument is : or an integer, the argument is a call and must be expanded.
Otherwise, the argument should not be expanded. Note that the system already
includes declarations for all built-ins.
In the previous example, the only argument to call/1 must be expanded, resulting in
the following code:
:- module(example,[a/1]).
...
a(G) :- call(example:G)
...
26 YAP Prolog User’s Manual
Chapter 6: Built-In Predicates 27
6 Built-In Predicates
\+ +P [ISO]
Goal P is not provable. The execution of this predicate fails if and only if the
goal P finitely succeeds. It is not a true logical negation, which is impossible
in standard Prolog, but "negation-by-failure".
This predicate might be defined as:
\+(P) :- P, !, fail.
\+(_).
if P did not include "cuts".
not +P Goal P is not provable. The same as ’\+ P ’.
This predicate is kept for compatibility with C-Prolog and previous versions of
YAP. Uses of not/1 should be replace by (\+)/1, as YAP does not implement
true negation.
+P -> +Q [ISO]
Read as "if-then-else" or "commit". This operator is similar to the conditional
operator of imperative languages and can be used alone or with an else part as
follows:
+P -> +Q "if P then Q".
+P -> +Q; +R
"if P then Q else R".
These two predicates could be defined respectively in Prolog as:
(P -> Q) :- P, !, Q.
and
(P -> Q; R) :- P, !, Q.
(P -> Q; R) :- R.
if there were no "cuts" in P, Q and R.
Note that the commit operator works by "cutting" any alternative solutions of
P.
Note also that you can use chains of commit operators like:
P -> Q ; R -> S ; T.
Note that (->)/2 does not affect the scope of cuts in its arguments.
repeat [ISO]
Succeeds repeatedly.
In the next example, repeat is used as an efficient way to implement a loop.
The next example reads all terms in a file:
a :- repeat, read(X), write(X), nl, X=end_of_file, !.
the loop is effectively terminated by the cut-goal, when the test-goal X=end
succeeds. While the test fails, the goals read(X), write(X), and nl are executed
repeatedly, because backtracking is caught by the repeat goal.
The built-in repeat/1 could be defined in Prolog by:
repeat.
repeat :- repeat.
Chapter 6: Built-In Predicates 29
call(+P ) [IS0]
If P is instantiated to an atom or a compound term, the goal call(P ) is
executed as if the value of P was found instead of the call to call/1, except
that any "cut" occurring in P only cuts alternatives in the execution of P.
incore(+P )
The same as call/1.
call_with_args(+Name,...,?Ai,...)
Meta-call where Name is the name of the procedure to be called and the Ai are
the arguments. The number of arguments varies between 0 and 10.
If Name is a complex term, then call_with_args/n behaves as call/n:
call(p(X1,...,Xm), Y1,...,Yn) :- p(X1,...,Xm,Y1,...,Yn).
+P The same as call(P ). This feature has been kept to provide compatibility
with C-Prolog. When compiling a goal, YAP generates a call(X ) whenever a
variable X is found as a goal.
a(X) :- X.
is converted to:
a(X) :- call(X).
if(?G,?H,?I ) [IS0]
Call goal H once per each solution of goal H. If goal H has no solutions, call
goal I.
The built-in if/3 is similar to ->/3, with the difference that it will backtrack
over the test goal. Consider the following small data-base:
a(1). b(a). c(x).
a(2). b(b). c(y).
Execution of an if/3 query will proceed as follows:
?- if(a(X),b(Y),c(Z)).
X = 1,
Y = a ? ;
X = 1,
Y = b ? ;
X = 2,
Y = a ? ;
X = 2,
Y = b ? ;
no
The system will backtrack over the two solutions for a/1 and the two solutions
for b/1, generating four solutions.
Cuts are allowed inside the first goal G, but they will only prune over G.
30 YAP Prolog User’s Manual
grow_heap(+Size )
Increase heap size Size kilobytes.
grow_stack(+Size )
Increase stack size Size kilobytes.
goal, and the second M set to the current module. The predicate G will be
called from within the user module.
If user:unknown_predicate_handler/3 succeeds, the system will execute NG.
If user:unknown_predicate_handler/3 fails, the system will execute default
action as specified by unknown/2.
name(3,L).
will return:
L = [51].
atom_chars(?A,?L ) [ISO]
The predicate holds when at least one of the arguments is ground (otherwise,
an error message will be displayed). The argument A must be unifiable with an
atom, and the argument L with the list of the ASCII codes for the characters
of the external representation of A.
The ISO-Prolog standard dictates that atom_chars/2 should unify the sec-
ond argument with a list of one-char atoms, and not the character codes. For
compatibility with previous versions of YAP, and with other Prolog imple-
mentations, YAP unifies the second argument with the character codes, as in
atom_codes/2. Use the set_prolog_flag(to_chars_mode,iso) to obtain ISO
standard compatibility.
atom_codes(?A,?L ) [ISO]
The predicate holds when at least one of the arguments is ground (otherwise,
an error message will be displayed). The argument A will be unified with an
atom and L with the list of the ASCII codes for the characters of the external
representation of A.
atom_concat(+As,?A )
The predicate holds when the first argument is a list of atoms, and the second
unifies with the atom obtained by concatenating all the atoms in the first list.
atomic_concat(+As,?A )
The predicate holds when the first argument is a list of atoms, and the second
unifies with the atom obtained by concatenating all the atomic terms in the
first list. The first argument thus may contain atoms or numbers.
atom_concat(+A1,+A2,?A )
The predicate holds when the first argument and second argument are atoms,
and the third unifies with the atom obtained by concatenating the first two
arguments.
atom_length(+A,?I ) [ISO]
The predicate holds when the first argument is an atom, and the second unifies
with the number of characters forming that atom.
atom_concat(?A1,?A2,?A12 ) [ISO]
The predicate holds when the third argument unifies with an atom, and the
first and second unify with atoms such that their representations concatenated
are the representation for A12.
If A1 and A2 are unbound, the built-in will find all the atoms that concatenated
give A12.
number_chars(?I,?L )
The predicate holds when at least one of the arguments is ground (otherwise,
an error message will be displayed). The argument I must be unifiable with a
34 YAP Prolog User’s Manual
number, and the argument L with the list of the ASCII codes for the characters
of the external representation of I.
The ISO-Prolog standard dictates that number_chars/2 should unify the sec-
ond argument with a list of one-char atoms, and not the character codes. For
compatibility with previous versions of YAP, and with other Prolog imple-
mentations, YAP unifies the second argument with the character codes, as in
number_codes/2. Use the set_prolog_flag(to_chars_mode,iso) to obtain
ISO standard compatibility.
number_codes(?A,?L ) [ISO]
The predicate holds when at least one of the arguments is ground (otherwise,
an error message will be displayed). The argument A will be unified with a
number and L with the list of the ASCII codes for the characters of the external
representation of A.
number_atom(?I,?L )
The predicate holds when at least one of the arguments is ground (otherwise,
an error message will be displayed). The argument I must be unifiable with a
number, and the argument L must be unifiable with an atom representing the
number.
char_code(?A,?I ) [ISO]
The built-in succeeds with A bound to character represented as an atom, and
I bound to the character code represented as an integer. At least, one of either
A or I must be bound before the call.
sub_atom(+A,?Bef, ?Size, ?After, ?At_out ) [ISO]
True when A and At out are atoms such that the name of At out has size Size
and is a substring of the name of A, such that Bef is the number of characters
before and After the number of characters afterwards.
Note that A must always be known, but At out can be unbound when calling
this built-in. If all the arguments for sub_atom/5 but A are unbound, the
built-in will backtrack through all possible substrings of A.
numbervars(T,+N1,-Nn )
Instantiates each variable in term T to a term of the form: ’$VAR’(I ), with I
increasing from N1 to Nn.
ground(T )
Succeeds if there are no free variables in the term T.
arg(+N,+T,A ) [ISO]
Succeeds if the argument N of the term T unifies with A. The arguments are
numbered from 1 to the arity of the term.
The current version will generate an error if T or N are unbound, if T is not a
compound term, of if N is not a positive integer. Note that previous versions
of YAP would fail silently under these errors.
functor(T,F,N )
The top functor of term T is named F and has arity N.
Chapter 6: Built-In Predicates 35
X == Y [ISO]
Succeeds if terms X and Y are strictly identical. The difference between this
predicate and =/2 is that, if one of the arguments is a free variable, it only
succeeds when they have already been unified.
?- X == Y.
fails, but,
?- X = Y, X == Y.
succeeds.
?- X == 2.
fails, but,
?- X = 2, X == 2.
succeeds.
X \== Y [ISO]
Terms X and Y are not strictly identical.
X @< Y [ISO]
Term X precedes term Y in the standard order.
X @=< Y [ISO]
Term X does not follow term Y in the standard order.
X @> Y [ISO]
Term X follows term Y in the standard order.
X @>= Y [ISO]
Term X does not precede term Y in the standard order.
sort(+L,-S )
Unifies S with the list obtained by sorting L and merging identical (in the sense
of ==) elements.
keysort(+L,S )
Assuming L is a list of the form Key -Value , keysort(+L,S ) unifies S with the
list obtained from L, by sorting its elements according to the value of Key.
?- keysort([3-a,1-b,2-c,1-a,1-b],S).
would return:
S = [1-b,1-a,1-b,2-c,3-a]
length(?L,?S )
Unify the well-defined list L with its length. The procedure can be used to find
the length of a pre-defined list, or to build a list of length S.
Chapter 6: Built-In Predicates 37
6.5 Arithmetic
Arithmetic expressions in YAP may use the following operators or evaluable predicates:
+X The value of X itself.
-X [ISO] Symmetric value.
X +Y [ISO]
Sum.
X-Y [ISO]
Difference.
X *Y [ISO]
Product.
X /Y [ISO]
Quotient.
X //Y [ISO]
Integer quotient.
X mod Y [ISO]
Integer remainder.
X rem Y Integer remainder, the same as mod.
exp(X ) [ISO]
Natural exponential.
log(X ) [ISO]
Natural logarithm.
log10(X ) Decimal logarithm.
sqrt(X ) [ISO]
Square root.
sin(X ) [ISO]
Sine.
cos(X ) [ISO]
Cosine.
tan(X ) Tangent.
asin(X ) Arc sine.
acos(X ) Arc cosine.
atan(X ) [ISO]
Arc tangent.
atan2(X ) Four-quadrant arc tangent.
sinh(X ) Hyperbolic sine.
cosh(X ) Hyperbolic cosine.
38 YAP Prolog User’s Manual
At most, there are 17 streams opened at the same time. Each stream is either
an input or an output stream but not both. There are always 3 open streams:
user_input for reading, user_output for writing and user_error for writ-
ing. If there is no ambiguity, the atoms user_input and user_output may be
referred to as user.
The file_errors flag controls whether errors are reported when in mode ’read’
or ’append’ the file F does not exist or is not readable, and whether in mode
’write’ or ’append’ the file is not writable.
open(+F,+M,-S,+Opts ) [ISO]
Opens the file with name F in mode M (’read’, ’write’ or ’append’), returning
S unified with the stream name, and following these options:
reposition(+Bool )
Specify whether it is possible to reposition the stream (true), or
not (false). By default, YAP enables repositioning for all files,
except terminal files and sockets.
eof_action(+Action )
Specify the action to take if attempting to input characters from
a stream where we have previously found an end-of-file. The
possible actions are error, that raises an error, reset, that tries
to reset the stream and is used for tty type files, and eof_code,
which generates a new end-of-file (default for non-tty files).
alias(+Name )
Specify an alias to the stream. The alias Name must be an atom.
The alias can be used instead of the stream descriptor for every
operation concerning the stream.
The operation will fail and give an error if the alias name is already
in use. YAP allows several aliases for the same file, but only one is
returned by stream_property/2
close(+S ) [ISO]
Closes the stream S. If S does not stand for a stream currently opened an error is
reported. The streams user_input, user_output, and user_error can never
be closed.
By default, give a file name, close/1 will also try to close a corresponding open
stream. This feature is not available in ISO or SICStus languages mode and is
deprecated.
close(+S,+O ) [ISO]
Closes the stream S, following options O.
The only valid options are force(true) and force(false). YAP currently
ignores these options.
42 YAP Prolog User’s Manual
absolute_file_name(+Name,-FullPath )
Give the path a full path FullPath Yap would use to consult a file named Name.
Unify FullPath with user if the file name is user.
current_stream(F,M,S )
Defines the relation: The stream S is opened on the file F in mode M. It might
be used to obtain all open streams (by backtracking) or to access the stream
for a file F in mode M, or to find properties for a stream S.
flush_output [ISO]
Send all data in the output buffer to current output stream.
flush_output(+S ) [ISO]
Send all data in the output buffer to stream S.
set_input(+S )
Set stream S as the current input stream. Predicates like read/1 and get/1
will start using stream S.
set_output(+S )
Set stream S as the current output stream. Predicates like write/1 and put/1
will start using stream S.
stream_select(+STREAMS,+TIMEOUT,-READSTREAMS )
Given a list of open STREAMS openeded in read mode and a TIMEOUT return
a list of streams who are now available for reading.
If the TIMEOUT is instantiated to off, stream_select/3 will wait indefinitely
for a stream to become open. Otherwise the timeout must be of the form
SECS:USECS where SECS is an integer gives the number of seconds to wait for a
timeout and USECS adds the number of micro-seconds.
This built-in is only defined if the system call select is available in the system.
current_input(-S ) [ISO]
Unify S with the current input stream.
current_output(-S ) [ISO]
Unify S with the current output stream.
at_end_of_stream [ISO]
Succeed if the current stream has stream position end-of-stream or past-end-
of-stream.
at_end_of_stream(+S ) [ISO]
Succeed if the stream S has stream position end-of-stream or past-end-of-
stream. Note that S must be a readable stream.
set_stream_position(+S, +POS ) [ISO]
Given a stream position POS for a stream S, set the current stream position
for S to be POS.
stream_property(?Stream,?Prop ) [ISO]
Obtain the properties for the open streams. If the first argument is unbound,
the procedure will backtrack through all open streams. Otherwise, the first
Chapter 6: Built-In Predicates 43
told Closes the current output stream, and the user’s terminal becomes again the
current output stream. It is important to remember to close streams after
having finished using them, as the maximum number of simultaneously opened
streams is 17.
see(+S ) If S is a currently opened input stream then it is assumed to be the current input
stream. If S is an atom it is taken as a filename. If there is no input stream
currently associated with it, then it is opened for input, and the new input
stream thus created becomes the current input stream. If it is not possible to
open the file, an error occurs. If there is a single opened input stream currently
associated with the file, it becomes the current input stream; if there are more
than one in that condition, then one of them is chosen.
When S is a stream not currently opened for input, an error may be reported,
depending on the state of the file_errors flag. If S is neither a stream nor
an atom the predicates just fails.
seeing(-S )
The current input stream is unified with S.
seen Closes the current input stream (see 6.7.).
char_conversion(+IN,+OUT ) [ISO]
While reading terms convert unquoted occurrences of the character IN to the
character OUT. Both IN and OUT must be bound to single characters atoms.
Character conversion only works if the flag char_conversion is on. This is
default in the iso and sicstus language modes. As an example, character
conversion can be used for instance to convert characters from the ISO-LATIN-
1 character set to ASCII.
If IN is the same character as OUT, char_conversion/2 will remove this con-
version from the table.
current_char_conversion(?IN,?OUT ) [ISO]
If IN is unbound give all current character translations. Otherwise, give the
translation for IN, if one exists.
write(T ) [ISO]
The term T is written to the current output stream according to the operator
declarations in force.
display(+T )
Displays term T on the current output stream. All Prolog terms are written in
standard parenthesized prefix notation.
write_canonical(+T ) [ISO]
Displays term T on the current output stream. Atoms are quoted when neces-
sary, and operators are ignored, that is, the term is written in standard paren-
thesized prefix notation.
write_term(+T, +Opts ) [ISO]
Displays term T on the current output stream, according to the following op-
tions:
quoted(+Bool )
If true, quote atoms if this would be necessary for the atom to
be recognized as an atom by YAP’s parser. The default value is
false.
ignore_ops(+Bool )
If true, ignore operator declarations when writing the term. The
default value is false.
numbervars(+Bool )
If true, output terms of the form ’$VAR’(N), where N is an integer,
as a sequence of capital letters. The default value is false.
portrayed(+Bool )
If true, use portray/1 to portray bound terms. The default value
is false.
max_depth(+Depth )
If Depth is a positive integer, use Depth as the maximum depth to
portray a term. The default is 0, that is, unlimited depth.
46 YAP Prolog User’s Manual
writeq(T ) [ISO]
Writes the term T, quoting names to make the result acceptable to the predicate
’read’ whenever necessary.
print(T ) Prints the term T to the current output stream using write/1 unless T is
bound and a call to the user-defined predicate portray/1 succeeds. To do
pretty printing of terms the user should define suitable clauses for portray/1
and use print/1.
format(+T,+L )
Print formatted output to the current output stream. The arguments in list L
are output according to the string or atom T.
A control sequence is introduced by a w. The following control sequences are
available in YAP:
’~~’ Print a single tilde.
’~a’ The next argument must be an atom, that will be printed as if by
write.
’~Nc’ The next argument must be an integer, that will be printed as a
character code. The number N is the number of times to print the
character (default 1).
’~Ne’
’~NE’
’~Nf’
’~Ng’
’~NG’ The next argument must be a floating point number. The float F,
the number N and the control code c will be passed to printf as:
printf("%s.Nc", F)
As an example:
?- format("~8e, ~8E, ~8f, ~8g, ~8G~w",
[3.14,3.14,3.14,3.14,3.14,3.14]).
3.140000e+00, 3.140000E+00, 3.140000, 3.14, 3.143.14
’~Nd’ The next argument must be an integer, and N is the number of
digits after the decimal point. If N is 0 no decimal points will be
printed. The default is N = 0.
?- format("~2d, ~d",[15000, 15000]).
150.00, 15000
’~ND’ Identical to ’~Nd’, except that commas are used to separate groups
of three digits.
?- format("~2D, ~D",[150000, 150000]).
1,500.00, 150,000
’~i’ Ignore the next argument in the list of arguments:
?- format(’The ~i met the boregrove’,[mimsy]).
The met the boregrove
Chapter 6: Built-In Predicates 47
?- format("~n*Hello~16+*~n",[]).
*Hello *
?- format("*~tHello~16+*~n",[]).
* Hello*
?- format("*~tHello~t~16+*~n",[]).
* Hello *
The two ~t escape sequence force filling both before and after Hello. Space is
then evenly divided between the right and the left sides.
format(+S,+T,+L )
Print formatted output to stream S.
put_code(+N ) [ISO]
Outputs to the current output stream the character whose ASCII code is N.
The current output stream must be a text stream. The character N must be
a legal ASCII character code, an expression yielding such a code, or a list in
which case only the first element is used.
get(-C ) The next non-blank character from the current input stream is unified with C.
Blank characters are the ones whose ASCII codes are not greater than 32. If
there are no more non-blank characters in the stream, C is unified with -1. If
end_of_stream has already been reached in the previous reading, this call will
give an error message.
get0(-C ) The next character from the current input stream is consumed, and then unified
with C. There are no restrictions on the possible values of the ASCII code for
the character, but the character will be internally converted by YAP.
get_byte(-C ) [ISO]
If C is unbound, or is a character code, and the current stream is a binary
stream, read the next byte from the current stream and unify its code with C.
get_char(-C ) [ISO]
If C is unbound, or is an atom representation of a character, and the current
stream is a text stream, read the next character from the current stream and
unify its atom representation with C.
get_code(-C ) [ISO]
If C is unbound, or is the code for a character, and the current stream is a text
stream, read the next character from the current stream and unify its code with
C.
peek_byte(-C ) [ISO]
If C is unbound, or is a character code, and the current stream is a binary
stream, read the next byte from the current stream and unify its code with C,
while leaving the current stream position unaltered.
peek_char(-C ) [ISO]
If C is unbound, or is an atom representation of a character, and the current
stream is a text stream, read the next character from the current stream and
unify its atom representation with C, while leaving the current stream position
unaltered.
peek_code(-C ) [ISO]
If C is unbound, or is the code for a character, and the current stream is a text
stream, read the next character from the current stream and unify its code with
C, while leaving the current stream position unaltered.
skip(+N ) Skips input characters until the next occurrence of the character with ASCII
code N. The argument to this predicate can take the same forms as those for
put (see 6.11).
tab(+N ) Outputs N spaces to the current output stream.
nl [ISO] Outputs a new line to the current output stream.
50 YAP Prolog User’s Manual
get_code(+S,-C ) [ISO]
If C is unbound, or is a character code, and the stream S is a text stream, read
the next character from that stream and unify its code with C.
peek_byte(+S,-C ) [ISO]
If C is unbound, or is a character code, and S is a binary stream, read the
next byte from the current stream and unify its code with C, while leaving the
current stream position unaltered.
peek_char(+S,-C ) [ISO]
If C is unbound, or is an atom representation of a character, and the stream
S is a text stream, read the next character from that stream and unify its
representation as an atom with C, while leaving the current stream position
unaltered.
peek_code(+S,-C ) [ISO]
If C is unbound, or is an atom representation of a character, and the stream
S is a text stream, read the next character from that stream and unify its
representation as an atom with C, while leaving the current stream position
unaltered.
skip(+S,-C )
Like skip/1, but using stream S instead of the current input stream.
tab(+S,+N )
The same as tab/1, but using stream S.
nl(+S ) Outputs a new line to stream S.
fileerrors
Switches on the file errors flag so that in certain error conditions I/O predicates
will produce an appropriated message and abort.
write_depth(T,L,A )
Unifies T with the value of the maximum depth of a term to be written, L with
the maximum length of a list to write, and A with the maximum number of
arguments of a compound term to write. The setting will be used by write/1
or write/2. The default value for all arguments is 0, meaning unlimited depth
and length.
?- write_depth(3,5,5).
yes
?- write(a(b(c(d(e(f(g))))))).
a(b(c(....)))
yes
?- write([1,2,3,4,5,6,7,8]).
[1,2,3,4,5,...]
yes
?- write(a(1,2,3,4,5,6,7,8)).
a(1,2,3,4,5,...)
yes
write_depth(T,L )
Same as write_depth(T,L,_). Unifies T with the value of the maximum depth
of a term to be written, and L with the maximum length of a list to write. The
setting will be used by write/1 or write/2. The default value for all arguments
is 0, meaning unlimited depth and length.
?- write_depth(3,5,5).
yes
?- write(a(b(c(d(e(f(g))))))).
a(b(c(....)))
yes
?- write([1,2,3,4,5,6,7,8]).
[1,2,3,4,5,...]
yes
always_prompt_user
Force the system to prompt the user even if the user_input stream is not a
terminal. This command is useful if you want to obtain interactive control from
a pipe or a socket.
socket(+DOMAIN,+TYPE,+PROTOCOL,-SOCKET )
Corresponds to the BSD system call socket. Create a socket for domain DO-
MAIN of type TYPE and protocol PROTOCOL. Both DOMAIN and TYPE
should be atoms, whereas PROTOCOL must be an integer. The new socket
object is accessible through a descriptor bound to the variable SOCKET.
The current implementation of YAP only accepts two socket domains: ’AF_
INET’ and ’AF_UNIX’. Socket types depend on the underlying operating sys-
tem, but at least the following types are supported: ’SOCK_STREAM’ and ’SOCK_
DGRAM’.
socket(+DOMAIN,-SOCKET )
Call socket/4 with TYPE bound to ’SOCK_STREAM’ and PROTOCOL bound
to 0.
socket_close(+SOCKET )
Close socket SOCKET. Note that sockets used in socket_connect (that is,
client sockets) should not be closed with socket_close, as they will be au-
tomatically closed when the corresponding stream is closed with close/1 or
close/2.
socket_bind(+SOCKET, ?PORT )
Interface to system call bind, as used for servers: bind socket to a port. Port
information depends on the domain:
’AF_UNIX’(+FILENAME )
’AF_FILE’(+FILENAME )
use file name FILENAME for UNIX or local sockets.
’AF_INET’(?HOST,?PORT)
If HOST is bound to an atom, bind to host HOST, otherwise if
unbound bind to local host (HOST remains unbound). If port
PORT is bound to an integer, try to bind to the corresponding
port. If variable PORT is unbound allow operating systems to
choose a port number, which is unified with PORT.
socket_connect(+SOCKET, +PORT, -STREAM )
Interface to system call connect, used for clients: connect socket SOCKET to
PORT. The connection results in the read/write stream STREAM.
Port information depends on the domain:
’AF_UNIX’(+FILENAME )
’AF_FILE’(+FILENAME )
connect to socket at file FILENAME.
’AF_INET’(+HOST,+PORT )
Connect to socket at host HOST and port PORT.
socket_listen(+SOCKET, +LENGTH )
Interface to system call listen, used for servers to indicate willingness to wait
for connections at socket SOCKET. The integer LENGTH gives the queue limit
for incoming connections, and should be limited to 5 for portable applications.
The socket must be of type SOCK_STREAM or SOCK_SEQPACKET.
54 YAP Prolog User’s Manual
socket_accept(+SOCKET, -STREAM )
socket_accept(+SOCKET, -CLIENT, -STREAM )
Interface to system call accept, used for servers to wait for connections at socket
SOCKET. The stream descriptor STREAM represents the resulting connection.
If the socket belongs to the domain ’AF_INET’, CLIENT unifies with an atom
containing the IP address for the client in numbers and dots notation.
socket_accept(+SOCKET, -STREAM )
Accept a connection but do not return client information.
socket_buffering(+SOCKET, -MODE, -OLD, +NEW )
Set buffering for SOCKET in read or write MODE. OLD is unified with the
previous status, and NEW receives the new status which may be one of unbuf
or fullbuf.
socket_select(+SOCKETS, -NEWSTREAMS, +TIMEOUT, +STREAMS, -READSTREAMS )
Interface to system call select, used for servers to wait for connection requests
or for data at sockets. The variable SOCKETS is a list of form KEY-SOCKET,
where KEY is an user-defined identifier and SOCKET is a socket descrip-
tor. The variable TIMEOUT is either off, indicating execution will wait until
something is available, or of the form SEC-USEC, where SEC and USEC give
the seconds and microseconds before socket_select/5 returns. The variable
SOCKETS is a list of form KEY-STREAM, where KEY is an user-defined
identifier and STREAM is a stream descriptor
Execution of socket_select/5 unifies READSTREAMS from STREAMS with
readable data, and NEWSTREAMS with a list of the form KEY-STREAM,
where KEY was the key for a socket with pending data, and STREAM the
stream descriptor resulting from accepting the connection.
current_host(?HOSTNAME )
Unify HOSTNAME with an atom representing the fully qualified hostname for
the current host. Also succeeds if HOSTNAME is bound to the unqualified
hostname.
hostname_address(?HOSTNAME,?IP_ADDRESS )
HOSTNAME is an host name and IP ADDRESS its IP address in number and
dots notation.
dynamic +P
Declares predicate P or list of predicates [P1,...,Pn] as a dynamic predicate. P
must be written in form: name/arity.
:- dynamic god/1.
a more convenient form can be used:
:- dynamic son/3, father/2, mother/2.
or, equivalently,
:- dynamic [son/3, father/2, mother/2].
Note:
a predicate is assumed to be dynamic when asserted before being defined.
dynamic_predicate(+P,+Semantics )
Declares predicate P or list of predicates [P1,...,Pn] as a dynamic predicate
following either logical or immediate semantics.
assert_static(:C )
Adds clause C to a static procedure. Asserting a static clause for a predicate
while choice-points for the predicate are available has undefined results.
asserta_static(:C )
Adds clause C to the beginning of a static procedure.
assertz_static(:C )
Adds clause C to the end of a static procedure. Asserting a static clause for
a predicate while choice-points for the predicate are available has undefined
results.
The following predicates can be used for dynamic predicates and for static predicates, if
source mode was on when they were compiled:
clause(+H,B ) [ISO]
A clause whose head matches H is searched for in the program. Its head and
body are respectively unified with H and B. If the clause is a unit clause, B is
unified with true.
This predicate is applicable to static procedures compiled with source active,
and to all dynamic procedures.
clause(+H,B,-R )
The same as clause/2, plus R is unified with the reference to the clause in the
database. You can use instance/2 to access the reference’s value. Note that
you may not use erase/1 on the reference on static procedures.
nth_clause(+H,I,-R )
Find the I th clause in the predicate defining H, and give a reference to the
clause. Alternatively, if the reference R is given the head H is unified with a
description of the predicate and I is bound to its position.
The following predicates can only be used for dynamic predicates:
retract(+C ) [ISO]
Erases the first clause in the program that matches C. This predicate may
also be used for the static predicates that have been compiled when the source
mode was on. For more information on source/0 (see Section 4.2 [Setting the
Compiler], page 19).
retractall(+G )
Retract all the clauses whose head matches the goal G. Goal G must be a call
to a dynamic predicate.
portray_clause(+C )
Write clause C as if written by listing/0.
portray_clause(+S,+C )
Write clause C on stream S as if written by listing/0.
current_atom(A )
Checks whether A is a currently defined atom. It is used to find all currently
defined atoms by backtracking.
current_predicate(F ) [ISO]
F is the predicate indicator for a currently defined user or library predicate. F
is of the form Na/Ar, where the atom Na is the name of the predicate, and Ar
its arity.
current_predicate(A,P )
Defines the relation: P is a currently defined predicate whose name is the atom
A.
system_predicate(A,P )
Defines the relation: P is a built-in predicate whose name is the atom A.
predicate_property(P,Prop )
For the predicates obeying the specification P unify Prop with a property of P.
These properties may be:
built_in true for built-in predicates,
dynamic true if the predicate is dynamic
static true if the predicate is static
meta_predicate(M )
true if the predicate has a meta predicate declaration M.
multifile
true if the predicate was declared to be multifile
imported_from(Mod )
true if the predicate was imported from module Mod.
exported true if the predicate is exported in the current module.
public true if the predicate is public; note that all dynamic predicates are
public.
tabled true if the predicate is tabled; note that only static predicates can
be tabled in YAP.
source true if source for the predicate is available.
number_of_clauses(ClauseCount )
Number of clauses in the predicate definition. Always one if exter-
nal or built-in.
58 YAP Prolog User’s Manual
recordaifnot(+K,T,-R )
If a term equal to T up to variable renaming is stored under key K fail. Other-
wise, make term T the first record under key K and unify R with its reference.
recordzifnot(+K,T,-R )
If a term equal to T up to variable renaming is stored under key K fail. Other-
wise, make term T the first record under key K and unify R with its reference.
recorded(+K,T,R )
Searches in the internal database under the key K, a term that unifies with T
and whose reference matches R. This built-in may be used in one of two ways:
• K may be given, in this case the built-in will return all elements of the
internal data-base that match the key.
• R may be given, if so returning the key and element that match the refer-
ence.
nth_instance(?K,?Index,T,?R )
Fetches the Indexnth entry in the internal database under the key K. Entries
are numbered from one. If the key K are the Index are bound, a reference is
unified with R. Otherwise, the reference R must be given, and the term the
system will find the matching key and index.
erase(+R )
The term referred to by R is erased from the internal database. If reference R
does not exist in the database, erase just fails.
erased(+R )
Succeeds if the object whose database reference is R has been erased.
instance(+R,-T )
If R refers to a clause or a recorded term, T is unified with its most general
instance. If R refers to an unit clause C, then T is unified with C :- true.
When R is not a reference to an existing clause or to a recorded term, this goal
fails.
eraseall(+K )
All terms belonging to the key K are erased from the internal database. The
predicate always succeeds.
current_key(?A,?K )
Defines the relation: K is a currently defined database key whose name is the
atom A. It can be used to generate all the keys for the internal data-base.
key_statistics(+K,-Entries,-Size,-IndexSize )
Returns several statistics for a key K. Currently, it says how many entries we
have for that key, Entries, what is the total size spent on entries, Size, and what
is the amount of space spent in indices.
key_statistics(+K,-Entries,-TotalSize )
Returns several statistics for a key K. Currently, it says how many entries we
have for that key, Entries, what is the total size spent on this key.
60 YAP Prolog User’s Manual
get_value(+A,-V )
In YAP, atoms can be associated with constants. If one such association exists
for atom A, unify the second argument with the constant. Otherwise, unify V
with [].
This predicate is YAP specific.
set_value(+A,+C )
Associate atom A with constant C.
The set_value and get_value built-ins give a fast alternative to the internal
data-base. This is a simple form of implementing a global counter.
read_and_increment_counter(Value) :-
get_value(counter, Value),
Value1 is Value+1,
set_value(counter, Value1).
This predicate is YAP specific.
recordzifnot(+K,T,-R )
If a variant of T is stored under key K fail. Otherwise, make term T the last
record under key K and unify R with its reference.
This predicate is YAP specific.
recordaifnot(+K,T,-R )
If a variant of T is stored under key K fail. Otherwise, make term T the first
record under key K and unify R with its reference.
This predicate is YAP specific.
There is a strong analogy between the i.d.b. and the way dynamic predicates are stored.
In fact, the main i.d.b. predicates might be implemented using dynamic predicates:
recorda(X,T,R) :- asserta(idb(X,T),R).
recordz(X,T,R) :- assertz(idb(X,T),R).
recorded(X,T,R) :- clause(idb(X,T),R).
We can take advantage of this, the other way around, as it is quite easy to write a simple
Prolog interpreter, using the i.d.b.:
asserta(G) :- recorda(interpreter,G,_).
assertz(G) :- recordz(interpreter,G,_).
retract(G) :- recorded(interpreter,G,R), !, erase(R).
call(V) :- var(V), !, fail.
call((H :- B)) :- !, recorded(interpreter,(H :- B),_), call(B).
call(G) :- recorded(interpreter,G,_).
In YAP, much attention has been given to the implementation of the i.d.b., especially to the
problem of accelerating the access to terms kept in a large list under the same key. Besides
using the key, YAP uses an internal lookup function, transparent to the user, to find only
the terms that might unify. For instance, in a data base containing the terms
b
b(a)
c(d)
e(g)
Chapter 6: Built-In Predicates 61
b(X)
e(h)
stored under the key k/1, when executing the query
:- recorded(k(_),c(_),R).
recorded would proceed directly to the third term, spending almost the time as if a(X) or
b(X) was being searched. The lookup function uses the functor of the term, and its first
three arguments (when they exist). So, recorded(k(_),e(h),_) would go directly to the
last term, while recorded(k(_),e(_),_) would find first the fourth term, and then, after
backtracking, the last one.
This mechanism may be useful to implement a sort of hierarchy, where the functors of
the terms (and eventually the first arguments) work as secondary keys.
In the YAP’s i.d.b. an optimized representation is used for terms without free variables.
This results in a faster retrieval of terms and better space usage. Whenever possible, avoid
variables in terms in terms stored in the i.d.b.
findall(T,+G,-L ) [ISO]
Unifies L with a list that contains all the instantiations of the term T satisfying
the goal G.
With the following program:
a(2,1).
a(1,1).
a(2,2).
the answer to the query
findall(X,a(X,Y),L).
would be:
X = _32
Y = _33
L = [2,1,2];
no
findall(T,+G,+L,-L0 )
Similar to findall/3, but appends all answers to list L0.
all(T,+G,-L )
Similar to findall(T,G,L ) but eliminating repeated elements. Thus, assuming
the same clauses as in the above example, the reply to the query
all(X,a(X,Y),L).
would be:
X = _32
Y = _33
L = [2,1];
no
bagof(T,+G,-L ) [ISO]
For each set of possible instances of the free variables occurring in G but not
in T, generates the list L of the instances of T satisfying G. Again, assuming
the same clauses as in the examples above, the reply to the query
bagof(X,a(X,Y),L).
would be:
X = _32
Y = 1
L = [2,1];
X = _32
Y = 2
L = [2];
no
setof(X,+P,-B ) [ISO]
Similar to bagof(T,G,L ) but sorting list L and keeping only one copy of each
element. Again, assuming the same clauses as in the examples above, the reply
to the query
Chapter 6: Built-In Predicates 63
setof(X,a(X,Y),L).
would be:
X = _32
Y = 1
L = [1,2];
X = _32
Y = 2
L = [2];
no
phrase(+P,L,R )
This predicate succeeds when the difference list L -R is a phrase of type P.
phrase(+P,L )
This predicate succeeds when L is a phrase of type P. The same as
phrase(P,L,[]).
Both this predicate and the previous are used as a convenient way to start
execution of grammar rules.
’C’(S1,T,S2 )
This predicate is used by the grammar rules compiler and is defined as
’C’([H|T],H,T).
once_with_alarm(Time,Goal,DoOnAlarm) :-
catch(execute_once_with_alarm(Time, Goal), alarm, DoOnAlarm).
execute_once_with_alarm(Time, Goal) :-
alarm(Time, alarm, _),
( call(Goal) -> alarm(0, alarm, _) ; alarm(0, alarm, _), fail).
The procedure has three arguments: the Time before the alarm is sent; the
Goal to execute; and the goal DoOnAlarm to execute if the alarm is sent. It
uses catch/3 to handle the case the alarm is sent. Then it starts the alarm,
calls the goal Goal, and disables the alarm on success or failure.
on_signal(+Signal,?OldAction,+Callable )
Set the interrupt handler for soft interrupt Signal to be Callable. OldAction is
unified with the previous handler.
Only a subset of the software interrupts (signals) can have their handlers ma-
nipulated through on_signal/3. Their POSIX names, YAP names and default
behavior is given below. The "YAP name" of the signal is the atom that is
associated with each signal, and should be used as the first argument to on_
signal/3. It is chosen so that it matches the signal’s POSIX name.
on_signal/3 succeeds, unless when called with an invalid signal name or one
that is not supported on this platform. No checks are made on the handler
provided by the user.
sig_up (Hangup)
SIGHUP in Unix/Linux; Reconsult the initialization files ~/.yaprc,
~/.prologrc and ~/prolog.ini.
sig_usr1 and sig_usr2 (User signals)
SIGUSR1 and SIGUSR2 in Unix/Linux; Print a message and halt.
A special case is made, where if Callable is bound to default, then the default
handler is restored for that signal.
A call in the form on_signal(S,H,H ) can be used to retrieve a signal’s current
handler without changing it.
It must be noted that although a signal can be received at all times, the handler
is not executed while Yap is waiting for a query at the prompt. The signal will
be, however, registered and dealt with as soon as the user makes a query.
Please also note, that neither POSIX Operating Systems nor Yap guarantee
that the order of delivery and handling is going to correspond with the order
of dispatch.
list_profile(Module) :-
% get number of calls for each profiled procedure
setof(D-[Module:P|D1],(profile_data(Module:P,calls,D),profile_data(Module:P
% output so that the most often called
% predicates will come last:
write_profile_data(LP).
68 YAP Prolog User’s Manual
write_profile_data([]).
write_profile_data([D-[M:P|R]|SLP]) :-
% swap the two calls if you want the most often
% called predicates first.
format(’~a:~w: ~32+~t~d~12+~t~d~12+~n’, [M,P,D,R]),
write_profile_data(SLP).
These are the current predicates to access and clear profiling data:
profile_data(?Na/Ar, ?Parameter, -Data )
Give current profile data on Parameter for a predicate described by the pred-
icate indicator Na/Ar. If any of Na/Ar or Parameter are unbound, backtrack
through all profiled predicates or stored parameters. Current parameters are:
calls Number of times a procedure was called.
retries Number of times a call to the procedure was backtracked to and
retried.
profile_reset
Reset all profiling information.
yes
yes
?- catch((call_count(10000,_,_),l),call_counter,format("limit_exceeded.~n",[])).
limit_exceeded.
yes
Notice that we first compile the looping predicate l/0 with call_counting on. Next,
we catch/3 to handle an exception when l/0 performs more than 10000 reductions.
6.16 Arrays
The YAP system includes experimental support for arrays. The support is enabled with
the option YAP_ARRAYS.
There are two very distinct forms of arrays in YAP. The dynamic arrays are a differ-
ent way to access compound terms created during the execution. Like any other terms,
any bindings to these terms and eventually the terms themselves will be destroyed during
backtracking. Our goal in supporting dynamic arrays is twofold. First, they provide an al-
ternative to the standard arg/3 built-in. Second, because dynamic arrays may have name
that are globally visible, a dynamic array can be visible from any point in the program. In
more detail, the clause
g(X) :- array_element(a,2,X).
will succeed as long as the programmer has used the built-in array/2 to create an array
term with at least 3 elements in the current environment, and the array was associated with
the name a. The element X is a Prolog term, so one can bind it and any such bindings will
be undone when backtracking. Note that dynamic arrays do not have a type: each element
may be any Prolog term.
The static arrays are an extension of the database. They provide a compact way for
manipulating data-structures formed by characters, integers, or floats imperatively. They
can also be used to provide two-way communication between YAP and external programs
through shared memory.
In order to efficiently manage space elements in a static array must have a type. Cur-
rently, elements of static arrays in YAP should have one of the following predefined types:
• byte: an 8-bit signed character.
• unsigned_byte: an 8-bit unsigned character.
• int: Prolog integers. Size would be the natural size for the machine’s architecture.
70 YAP Prolog User’s Manual
current_module(M )
Succeeds if M are defined modules. A module is defined as soon as some
predicate defined in the module is loaded, as soon as a goal in the module is
called, or as soon as it becomes the current type-in module.
current_module(M,F )
Succeeds if M are current modules associated to the file F.
6.18 Miscellaneous
statistics/0
Send to the current user error stream general information on space used and
time spent by the system.
?- statistics.
memory (total) 4784124 bytes
program space 3055616 bytes: 1392224 in use, 1663392 free
2228132 max
stack space 1531904 bytes: 464 in use, 1531440 free
global stack: 96 in use, 616684 max
local stack: 368 in use, 546208 max
trail stack 196604 bytes: 8 in use, 196596 free
The example shows how much memory the system spends. Memory is divided
into Program Space, Stack Space and Trail. In the example we have 3MB
allocated for program spaces, with less than half being actually used. Yap also
shows the maximum amount of heap space having been used which was over
2MB.
The stack space is divided into two stacks which grow against each other. We
are in the top level so very little stack is being used. On the other hand, the
system did use a lot of global and local stack during the previous execution (we
refer the reader to a WAM tutorial in order to understand what are the global
and local stacks).
Yap also shows information on how many memory overflows and garbage col-
lections the system executed, and statistics on total execution time. Cputime
includes all running time, runtime excludes garbage collection and stack over-
flow time.
statistics(?Param,-Info )
Gives statistical information on the system parameter given by first argument:
Chapter 6: Built-In Predicates 73
bounded [ISO]
fileerrors
Set or show the minimum free stack before starting garbage collec-
tion. The default depends on total stack size.
gc_trace
If off (default) do not show information on garbage collection and
stack shifts, if on inform when a garbage collection or stack shift
happened, if verbose give detailed information on garbage collec-
tion and stack shifts. Last, if very_verbose give detailed informa-
tion on data-structures found during the garbage collection process,
namely, on choice-points.
host_type
Read-only flag telling the rounding function used for integers. Takes
the value down for the current version of YAP.
language
Choose whether YAP is closer to C-Prolog, cprolog, iso-prolog,
iso or SICStus Prolog, sicstus. The current default is cprolog.
This flag affects update semantics, leashing mode, style checking,
76 YAP Prolog User’s Manual
Read or set the size of the hash table that is used for looking up
the blackboard when the key is an integer.
n_of_integer_keys_in_db
Read or set the size of the hash table that is used for looking up
the internal data-base when the key is an integer.
profiling
redefine_warnings
error
Report the syntax error and generate an error.
quiet
Just fail
system_options
This read only flag tells which options were used to compile Yap.
Currently it informs whether the system supports coroutining,
depth_limit, the low_level_tracer, or-parallelism,
rational_trees, tabling, threads, or the wam_profiler.
to_chars_mode
Error = ’$stream’(3) ? ;
no
?- set_prolog_flag(user_error, mauri_tripa).
close(mauri_tripa).
yes
?-
We execute three commands. First, we open a stream in write
mode and give it an alias, in this case mauri_tripa. Next, we set
user_error to the stream via the alias. Note that after we did
so prompts from the system were redirected to the stream mauri_
tripa. Last, we close the stream. At this point, YAP automatically
redirects the user_error alias to the original stderr.
user_input
Writable flag telling whether the system should write lists of inte-
gers that are writable character codes using the list notation. It is
on if enables or off if disabled. The default value for this flag is
off.
80 YAP Prolog User’s Manual
current_prolog_flag(?Flag,-Value ) [ISO]
Obtain the value for a YAP Prolog flag. Equivalent to calling yap_flag/2 with
the second argument unbound, and unifying the returned second argument with
Value.
prolog_flag(?Flag,-OldValue,+NewValue )
Obtain the value for a YAP Prolog flag and then set it to a new value. Equiv-
alent to first calling current_prolog_flag/2 with the second argument Old-
Value unbound and then calling set_prolog_flag/2 with the third argument
NewValue.
set_prolog_flag(+Flag,+Value ) [ISO]
Set the value for YAP Prolog flag Flag. Equivalent to calling yap_flag/2 with
both arguments bound.
op(+P,+T,+A ) [ISO]
Defines the operator A or the list of operators A with type T (which must be
one of xfx, xfy,yfx, xf, yf, fx or fy) and precedence P (see appendix iv for a
list of predefined operators).
Note that if there is a preexisting operator with the same name and type, this
operator will be discarded. Also, ’,’ may not be defined as an operator, and
it is not allowed to have the same for an infix and a postfix operator.
current_op(P,T,F ) [ISO]
Defines the relation: P is a currently defined operator of type T and precedence
P.
prompt(-A,+B )
Changes YAP input prompt from A to B.
initialization
Execute the goals defined by initialization/1. Only the first answer is consid-
ered.
prolog_initialization(G )
Add a goal to be executed on system initialization. This is compatible with
SICStus Prolog’s initialization/1.
version Write YAP’s boot message.
version(-Message )
Add a message to be written when yap boots or after aborting. It is not possible
to remove messages.
prolog_load_context(?Key, ?Value )
Obtain information on what is going on in the compilation process. The fol-
lowing keys are available:
directory
Full name for the directory where YAP is currently consulting the
file.
Chapter 6: Built-In Predicates 81
file
Full name for the file currently being consulted. Notice that in-
cluded filed are ignored.
module
Current source module.
source
Full name for the file currently being read in, which may be con-
sulted, reconsulted, or included.
stream
Stream currently being read in.
term_position
7 Library Predicates
Library files reside in the library directory path (set by the LIBDIR variable in the Makefile
for YAP). Currently, most files in the library are from the Edinburgh Prolog library.
%given
plus(X,Y,Z) :- Z is X + Y.
plus_if_pos(X,Y,Z) :- Y > 0, Z is X + Y.
vars(X, Y, [X|Y]) :- var(X), !.
vars(_, Y, Y).
trans(TermIn, TermOut) :-
(compound(TermIn) ; atom(TermIn)),
TermIn =.. [p|Args],
TermOut =..[q|Args],
!.
trans(X,X).
%success
empty_assoc(+Assoc )
Succeeds if association list Assoc is empty.
gen_assoc(+Assoc,?Key,?Value )
Given the association list Assoc, unify Key and Value with two associated
elements. It can be used to enumerate all elements in the association list.
get_assoc(+Key,+Assoc,?Value )
If Key is one of the elements in the association list Assoc, return the associated
value.
get_assoc(+Key,+Assoc,?Value,+NAssoc,?NValue )
If Key is one of the elements in the association list Assoc, return the associated
value Value and a new association list NAssoc where Key is associated with
NValue.
get_prev_assoc(+Key,+Assoc,?Next,?Value )
If Key is one of the elements in the association list Assoc, return the previous
key, Next, and its value, Value.
get_next_assoc(+Key,+Assoc,?Next,?Value )
If Key is one of the elements in the association list Assoc, return the next key,
Next, and its value, Value.
is_assoc(+Assoc )
Succeeds if Assoc is an association list, that is, if it is a red-black tree.
list_to_assoc(+List,?Assoc )
Given a list List such that each element of List is of the form Key-Val, and all
the Keys are unique, Assoc is the corresponding association list.
map_assoc(+Pred,+Assoc )
Succeeds if the unary predicate name Pred(Val) holds for every element in the
association list.
map_assoc(+Pred,+Assoc,?New )
Given the binary predicate name Pred and the association list Assoc, New in
an association list with keys in Assoc, and such that if Key-Val is in Assoc, and
Key-Ans is in New, then Pred(Val,Ans) holds.
max_assoc(+Assoc,-Key,?Value )
Given the association list Assoc, Key in the largest key in the list, and Value
the associated value.
min_assoc(+Assoc,-Key,?Value )
Given the association list Assoc, Key in the smallest key in the list, and Value
the associated value.
ord_list_to_assoc(+List,?Assoc )
Given an ordered list List such that each element of List is of the form Key-Val,
and all the Keys are unique, Assoc is the corresponding association list.
put_assoc(+Key,+Assoc,+Val,+New )
The association list New includes and element of association key with Val, and
all elements of Assoc that did not have key Key.
86 YAP Prolog User’s Manual
7.4 Heaps
A heap is a labelled binary tree where the key of each node is less than or equal to the keys
of its sons. The point of a heap is that we can keep on adding new elements to the heap
and we can keep on taking out the minimum element. If there are N elements total, the
total time is O(NlgN). If you know all the elements in advance, you are better off doing a
merge-sort, but this file is for when you want to do say a best-first search, and have no idea
when you start how many elements there will be, let alone what they are.
The following heap manipulation routines are available once included with the use_
module(library(heaps)) command.
add_to_heap(+Heap,+key,+Datum,-NewHeap )
Inserts the new Key-Datum pair into the heap. The insertion is not stable,
that is, if you insert several pairs with the same Key it is not defined which of
them will come out first, and it is possible for any of them to come out first
depending on the history of the heap.
empty_heap(?Heap )
Succeeds if Heap is an empty heap.
get_from_heap(+Heap,-key,-Datum,-Heap )
Returns the Key-Datum pair in OldHeap with the smallest Key, and also a
Heap which is the OldHeap with that pair deleted.
heap_size(+Heap, -Size )
Reports the number of elements currently in the heap.
heap_to_list(+Heap, -List )
Returns the current set of Key-Datum pairs in the Heap as a List, sorted into
ascending order of Keys.
list_to_heap(+List, -Heap )
Takes a list of Key-Datum pairs (such as keysort could be used to sort) and
forms them into a heap.
Chapter 7: Library Predicates 87
L = [1,2,3,4,5,6,7,8] ? ;
no
is_list(+List )
True when List is a proper list. That is, List is bound to the empty list (nil)
or a term with functor ’.’ and arity 2.
last(+List,?Last )
True when List is a list and Last is identical to its last element.
list_concat(+Lists,?List )
True when Lists is a list of lists and List is the concatenation of Lists.
member(?Element, ?Set )
True when Set is a list, and Element occurs in it. It may be used to test for an
element or to enumerate all the elements by backtracking.
memberchk(+Element, +Set )
As member/2, but may only be used to test whether a known Element occurs
in a known Set. In return for this limited use, it is more efficient when it is
applicable.
nth0(?N, ?List, ?Elem )
True when Elem is the Nth member of List, counting the first as element 0.
(That is, throw away the first N elements and unify Elem with the next.) It
can only be used to select a particular element given the list and index. For
that task it is more efficient than member/2
88 YAP Prolog User’s Manual
max_list(?Numbers, ?Max )
True when Numbers is a list of numbers, and Max is the maximum.
min_list(?Numbers, ?Min )
True when Numbers is a list of numbers, and Min is the minimum.
7.8 Queues
The following queue manipulation routines are available once included with the
use_module(library(queues)) command. Queues are implemented with difference lists.
Chapter 7: Library Predicates 91
make_queue(+Queue )
Creates a new empty queue. It should only be used to create a new queue.
join_queue(+Element, +OldQueue, -NewQueue )
Adds the new element at the end of the queue.
list_join_queue(+List, +OldQueue, -NewQueue )
Ads the new elements at the end of the queue.
jump_queue(+Element, +OldQueue, -NewQueue )
Adds the new element at the front of the list.
list_jump_queue(+List, +OldQueue, +NewQueue )
Adds all the elements of List at the front of the queue.
head_queue(+Queue, ?Head )
Unifies Head with the first element of the queue.
serve_queue(+OldQueue, +Head, -NewQueue )
Removes the first element of the queue for service.
empty_queue(+Queue )
Tests whether the queue is empty.
length_queue(+Queue, -Length )
Counts the number of elements currently in the queue.
list_to_queue(+List, -Queue )
Creates a new queue with the same elements as List.
queue_to_list(+Queue, -List )
Creates a new list with the same elements as Queue.
rb_update(+T,+Key,+NewVal,-TN )
Tree TN is tree T, but with value for Key associated with NewVal. Fails if it
cannot find Key in T.
rb_apply(+T,+Key,+G,-TN )
If the value associated with key Key is Val0 in T, and if call(G,Val0,ValF) holds,
then TN differs from T only in that Key is associated with value ValF in tree
TN. Fails if it cannot find Key in T, or if call(G,Val0,ValF) is not satisfiable.
rb_visit(+T,-Pairs )
Pairs is an infix visit of tree T, where each element of Pairs is of the form K-Val.
rb_size(+T,-Size )
Size is the number of elements in T.
rb_keys(+T,+Keys )
Keys is an infix visit with all keys in tree T. Keys will be sorted, but may be
duplicate.
rb_map(+T,+G,-TN )
For all nodes Key in the tree T, if the value associated with key Key is Val0 in
tree T, and if call(G,Val0,ValF) holds, then the value associated with Key in
TN is ValF. Fails if or if call(G,Val0,ValF) is not satisfiable for all Var0.
rb_partial_map(+T,+Keys,+G,-TN )
For all nodes Key in Keys, if the value associated with key Key is Val0 in tree
T, and if call(G,Val0,ValF) holds, then the value associated with Key in TN
is ValF. Fails if or if call(G,Val0,ValF) is not satisfiable for all Var0. Assumes
keys are not repeated.
rb_clone(+T,+NT,+Nodes )
“Clone” the red-back tree into a new tree with the same keys as the original
but with all values set to unbound values. Nodes is a list containing all new
nodes as pairs K-V.
rb_min(+T,-Key,-Value )
Key is the minimum key in T, and is associated with Val.
rb_max(+T,-Key,-Value )
Key is the maximal key in T, and is associated with Val.
rb_next(+T, +Key,-Next,-Value )
Next is the next element after Key in T, and is associated with Val.
rb_previous(+T, +Key,-Previous,-Value )
Previous is the previous element after Key in T, and is associated with Val.
list_to_rbtree(+L, -T )
T is the red-black tree corresponding to the mapping in list L.
ord_list_to_rbtree(+L, -T )
T is the red-black tree corresponding to the mapping in ordered list L.
94 YAP Prolog User’s Manual
splay_access(-Return,+Key,?Val,+Tree,-NewTree )
If item Key is in tree Tree, return its Val and unify Return with true. Otherwise
unify Return with null. The variable NewTree unifies with the new tree.
splay_delete(+Key,?Val,+Tree,-NewTree )
Delete item Key from tree Tree, assuming that it is present already. The
variable Val unifies with a value for key Key, and the variable NewTree unifies
with the new tree. The predicate will fail if Key is not present.
splay_init(-NewTree )
Initialize a new splay tree.
splay_insert(+Key,?Val,+Tree,-NewTree )
Insert item Key in tree Tree, assuming that it is not there already. The variable
Val unifies with a value for key Key, and the variable NewTree unifies with the
new tree. In our implementation, Key is not inserted if it is already there:
rather it is unified with the item already in the tree.
splay_join(+LeftTree,+RighTree,-NewTree )
Combine trees LeftTree and RighTree into a single treeNewTree containing all
items from both trees. This operation assumes that all items in LeftTree are
less than all those in RighTree and destroys both LeftTree and RighTree.
splay_split(+Key,?Val,+Tree,-LeftTree,-RightTree )
Construct and return two trees LeftTree and RightTree, where LeftTree con-
tains all items in Tree less than Key, and RightTree contains all items in Tree
greater than Key. This operations destroys Tree.
atom_to_chars(+Atom, -Result )
Convert the atom Atom to the string of character codes Result.
atom_to_chars(+Atom, -Result0, -Result )
Convert the atom Atom to the difference list of character codes Result-Result0.
number_to_chars(+Number, -Result )
Convert the number Number to the string of character codes Result.
number_to_chars(+Number, -Result0, -Result )
Convert the atom Number to the difference list of character codes Result-
Result0.
read_from_chars(+Chars, -Term )
Parse the list of character codes Chars and return the result in the term Term.
The character codes to be read must terminate with a dot character such that
either (i) the dot character is followed by blank characters; or (ii) the dot
character is the last character in the string.
open_chars_stream(+Chars, -Stream )
Open the list of character codes Chars as a stream Stream.
with_output_to_chars(?Goal, -Chars )
Execute goal Goal such that its standard output will be sent to a memory
buffer. After successful execution the contents of the memory buffer will be
converted to the list of character codes Chars.
with_output_to_chars(?Goal, ?Chars0, -Chars )
Execute goal Goal such that its standard output will be sent to a memory
buffer. After successful execution the contents of the memory buffer will be
converted to the difference list of character codes Chars-Chars0.
with_output_to_chars(?Goal, -Stream, ?Chars0, -Chars )
Execute goal Goal such that its standard output will be sent to a memory
buffer. After successful execution the contents of the memory buffer will be
converted to the difference list of character codes Chars-Chars0 and Stream
receives the stream corresponding to the memory buffer.
The implementation of the character IO operations relies on three YAP built-ins:
charsio:open_mem_read_stream(+String, -Stream )
Store a string in a memory buffer and output a stream that reads from this
memory buffer.
charsio:open_mem_write_stream(-Stream )
Create a new memory buffer and output a stream that writes to it.
charsio:peek_mem_write_stream(-Stream, L0, L)
Convert the memory buffer associated with stream Stream to the difference list
of character codes L-L0.
These built-ins are initialized to belong to the module charsio in init.yap. Novel proce-
dures for manipulating strings by explicitly importing these built-ins.
YAP does not currently support opening a charsio stream in append mode, or seeking
in such a stream.
98 YAP Prolog User’s Manual
X = datime(2001,5,28,15,29,46) ?
mktime(datime(+Year, +Month, +DayOfTheMonth,
+Hour, +Minute, +Second), -Seconds) The mktime/1 procedure returns the
number of Seconds elapsed since 00:00:00 on January 1, 1970, Coordinated
Universal Time (UTC). The user provides information on Year, Month, Day-
OfTheMonth, Hour, Minute, and Second. The Hour is given on local time. This
function uses the WIN32 GetLocalTime function or the Unix mktime function.
?- mktime(datime(2001,5,28,15,29,46),X).
X = 991081786 ? ;
delete_file(+File )
The delete_file/1 procedure removes file File. If File is a directory, remove
the directory and all its subdirectories.
?- delete_file(x).
delete_file(+File,+Opts )
The delete_file/2 procedure removes file File according to options Opts.
These options are directory if one should remove directories, recursive if
one should remove directories recursively, and ignore if errors are not to be
reported.
This example is equivalent to using the delete_file/1 predicate:
?- delete_file(x, [recursive]).
directory_files(+Dir,+List )
Given a directory Dir, directory_files/2 procedures a listing of all files and
directories in the directory:
?- directory_files(’.’,L), writeq(L).
[’Makefile.~1~’,’sys.so’,’Makefile’,’sys.o’,x,..,’.’]
The predicates uses the dirent family of routines in Unix environments, and
findfirst in WIN32.
file_exists(+File )
The atom File corresponds to an existing file.
Chapter 7: Library Predicates 99
file_exists(+File,+Permissions )
The atom File corresponds to an existing file with permissions compatible with
Permissions. YAP currently only accepts for permissions to be described as a
number. The actual meaning of this number is Operating System dependent.
file_property(+File,?Property )
The atom File corresponds to an existing file, and Property will be unified
with a property of this file. The properties are of the form type(Type ), which
gives whether the file is a regular file, a directory, a fifo file, or of unknown
type; size(Size ), with gives the size for a file, and mod_time(Time ), which
gives the last time a file was modified according to some Operating System
dependent timestamp; mode(mode ), gives the permission flags for the file, and
linkto(FileName ), gives the file pointed to by a symbolic link. Properties can
be obtained through backtracking:
?- file_property(’Makefile’,P).
P = type(regular) ? ;
P = size(2375) ? ;
P = mod_time(990826911) ? ;
no
make_directory(+Dir )
Create a directory Dir. The name of the directory must be an atom.
rename_file(+OldFile,+NewFile )
Create file OldFile to NewFile. This predicate uses the C built-in function
rename.
environ(?EnvVar,+EnvValue )
Unify environment variable EnvVar with its value EnvValue, if there is one.
This predicate is backtrackable in Unix systems, but not currently in Win32
configurations.
?- environ(’HOME’,X).
X = ’C:\\cygwin\\home\\administrator’ ?
host_id(-Id )
Unify Id with an identifier of the current host. Yap uses the hostid function
when available,
host_name(-Name )
Unify Name with a name for the current host. Yap uses the hostname function
in Unix systems when available, and the GetComputerName function in WIN32
systems.
100 YAP Prolog User’s Manual
kill(Id,+SIGNAL )
Send signal SIGNAL to process Id. In Unix this predicate is a direct interface
to kill so one can send signals to groups of processes. In WIN32 the predicate
is an interface to TerminateProcess, so it kills Id indepent of SIGNAL.
mktemp(Spec,-File )
Direct interface to mktemp: given a Spec, that is a file name with six X to it,
create a file name File. Use tmpnam/1 instead.
pid(-Id )
Unify Id with the process identifier for the current process. An interface to the
getpid function.
tmpnam(-File )
Interface with tmpnam: create an unique file and unify its name with File.
exec(+Command,[+InputStream,+OutputStream,+ErrorStream], -Status) Exe-
cute command Command with its streams connected to InputStream, Output-
Stream, and ErrorStream. The result for the command is returned in Status.
The command is executed by the default shell bin/sh -c in Unix.
The following example demonstrates the use of exec/3 to send a command and
process its output:
exec(ls,[std,pipe(S),null],P),repeat, get0(S,C), (C = -1, close(S) ! ; put(C)
The streams may be one of standard stream, std, null stream, null, or pipe(S),
where S is a pipe stream. Note that it is up to the user to close the pipe.
working_directory(-CurDir,?NextDir )
Fetch the current directory at CurDir. If NextDir is bound to an atom, make
its value the current working directory.
popen(+Command, +TYPE, -Stream )
Interface to the popen function. It opens a process by creating a pipe, forking
and invoking Command on the current shell. Since a pipe is by definition
unidirectional the Type argument may be read or write, not both. The stream
should be closed using close/1, there is no need for a special pclose command.
The following example demonstrates the use of popen/3 to process the output
of a command, as exec/3 would do:
?- popen(ls,read,X),repeat, get0(X,C), (C = -1, ! ; put(C)).
X = ’C:\\cygwin\\home\\administrator’ ?
The WIN32 implementation of popen/3 relies on exec/3.
shell Start a new shell and leave Yap in background until the shell completes. Yap
uses the shell given by the environment variable SHELL. In WIN32 environment
YAP will use COMSPEC if SHELL is undefined.
shell(+Command )
Execute command Command under a new shell. Yap will be in background until
the command completes. In Unix environments Yap uses the shell given by the
environment variable SHELL with the option " -c ". In WIN32 environment
Chapter 7: Library Predicates 101
YAP will use COMSPEC if SHELL is undefined, in this case with the option " /c
".
shell(+Command,-Status )
Execute command Command under a new shell and unify Status with the exit
for the command. Yap will be in background until the command completes. In
Unix environments Yap uses the shell given by the environment variable SHELL
with the option " -c ". In WIN32 environment YAP will use COMSPEC if SHELL
is undefined, in this case with the option " /c ".
sleep(+Time )
Block the current process for Time seconds. The number of seconds must be
a positive number, and it may an integer or a float. The Unix implementation
uses usleep if the number of seconds is below one, and sleep if it is over a
second. The WIN32 implementation uses Sleep for both cases.
system Start a new default shell and leave Yap in background until the shell completes.
Yap uses /bin/sh in Unix systems and COMSPEC in WIN32.
system(+Command,-Res )
Interface to system: execute command Command and unify Res with the result.
wait(+PID,-Status )
Wait until process PID terminates, and return its exits Status.
subsumes(?Term1, ?Term2 )
Succeed if Term1 subsumes Term2. Variables in term Term1 are bound so that
the two terms become equal.
subsumes_chk(?Term1, ?Term2 )
Succeed if Term1 subsumes Term2 but does not bind any variable in Term1.
variable_in_term(?Term,?Var )
Succeed if the second argument Var is a variable and occurs in term Term.
L = [1-[3,5],2-[4],3-[],4-[5],5-[]] ?
In this case all edges are defined implicitly. The next example shows three
unconnected edges:
?- vertices_edges_to_ugraph([6,7,8],[1-3,2-4,4-5,1-5],L).
L = [1-[3,5],2-[4],3-[],4-[5],5-[],6-[],7-[],8-[]] ?
vertices(+Graph, -Vertices )
Unify Vertices with all vertices appearing in graph Graph. In the next example:
?- vertices([1-[3,5],2-[4],3-[],4-[5],5-[]], V).
L = [1,2,3,4,5]
edges(+Graph, -Edges )
Unify Edges with all edges appearing in graph Graph. In the next example:
?- vertices([1-[3,5],2-[4],3-[],4-[5],5-[]], V).
L = [1,2,3,4,5]
add_vertices(+Graph, +Vertices, -NewGraph )
Unify NewGraph with a new graph obtained by adding the list of vertices
Vertices to the graph Graph. In the next example:
?- add_vertices([1-[3,5],2-[4],3-[],4-[5],
5-[],6-[],7-[],8-[]],
[0,2,9,10,11],
NG).
NG = [0-[],1-[3,5],2-[4],3-[],4-[5],5-[],
6-[],7-[],8-[],9-[],10-[],11-[]]
del_vertices(+Vertices, +Graph, -NewGraph )
Unify NewGraph with a new graph obtained by deleting the list of vertices
Vertices and all the edges that start from or go to a vertex in Vertices to the
graph Graph. In the next example:
?- del_vertices([2,1],[1-[3,5],2-[4],3-[],
4-[5],5-[],6-[],7-[2,6],8-[]],NL).
Chapter 7: Library Predicates 105
NL = [3-[],4-[5],5-[],6-[],7-[6],8-[]]
add_edges(+Graph, +Edges, -NewGraph )
Unify NewGraph with a new graph obtained by adding the list of edges Edges
to the graph Graph. In the next example:
?- add_edges([1-[3,5],2-[4],3-[],4-[5],5-[],6-[],
7-[],8-[]],[1-6,2-3,3-2,5-7,3-2,4-5],NL).
NL = [1-[3,5,6],2-[3,4],3-[2],4-[5],5-[7],6-[],7-[],8-[]]
del_edges(+Graph, +Edges, -NewGraph )
Unify NewGraph with a new graph obtained by removing the list of edges Edges
from the graph Graph. Notice that no vertices are deleted. In the next example:
?- del_edges([1-[3,5],2-[4],3-[],4-[5],5-[],
6-[],7-[],8-[]],
[1-6,2-3,3-2,5-7,3-2,4-5,1-3],NL).
NL = [1-[5],2-[4],3-[],4-[],5-[],6-[],7-[],8-[]]
transpose(+Graph, -NewGraph )
Unify NewGraph with a new graph obtained from Graph by replacing all edges
of the form V1-V2 by edges of the form V2-V1. The cost is O(|V|^2). In the
next example:
?- transpose([1-[3,5],2-[4],3-[],
4-[5],5-[],6-[],7-[],8-[]], NL).
NL = [1-[],2-[],3-[1],4-[2],5-[1,4],6-[],7-[],8-[]]
Notice that an undirected graph is its own transpose.
neighbors(+Vertex, +Graph, -Vertices )
Unify Vertices with the list of neighbors of vertex Vertex in Graph. If the
vertice is not in the graph fail. In the next example:
?- neighbors(4,[1-[3,5],2-[4],3-[],
4-[1,2,7,5],5-[],6-[],7-[],8-[]],
NL).
NL = [1,2,7,5]
neighbours(+Vertex, +Graph, -Vertices )
Unify Vertices with the list of neighbours of vertex Vertex in Graph. In the
next example:
?- neighbours(4,[1-[3,5],2-[4],3-[],
4-[1,2,7,5],5-[],6-[],7-[],8-[]], NL).
NL = [1,2,7,5]
complement(+Graph, -NewGraph )
Unify NewGraph with the graph complementary to Graph. In the next example:
106 YAP Prolog User’s Manual
?- complement([1-[3,5],2-[4],3-[],
4-[1,2,7,5],5-[],6-[],7-[],8-[]], NL).
NL = [1-[2,4,6,7,8],2-[1,3,5,6,7,8],3-[1,2,4,5,6,7,8],
4-[3,5,6,8],5-[1,2,3,4,6,7,8],6-[1,2,3,4,5,7,8],
7-[1,2,3,4,5,6,8],8-[1,2,3,4,5,6,7]]
compose(+LeftGraph, +RightGraph, -NewGraph )
Compose the graphs LeftGraph and RightGraph to form NewGraph. In the
next example:
?- compose([1-[2],2-[3]],[2-[4],3-[1,2,4]],L).
L = [1-[4],2-[1,2,4],3-[]]
top_sort(+Graph, -Sort )
Generate the set of nodes Sort as a topological sorting of graph Graph, if one
is possible. In the next example we show how topological sorting works for a
linear graph:
?- top_sort([_138-[_219],_219-[_139], _139-[]],L).
L = [_138,_219,_139]
top_sort(+Graph, -Sort0, -Sort )
Generate the difference list Sort-Sort0 as a topological sorting of graph Graph,
if one is possible.
transitive_closure(+Graph, +Closure )
Generate the graph Closure as the transitive closure of graph Graph. In the
next example:
?- transitive_closure([1-[2,3],2-[4,5],4-[6]],L).
L = [1-[2,3,4,5,6],2-[4,5,6],4-[6]]
reachable(+Node, +Graph, -Vertices )
Unify Vertices with the set of all vertices in graph Graph that are reachable
from Node. In the next example:
?- reachable(1,[1-[3,5],2-[4],3-[],4-[5],5-[]],V).
V = [1,3,5]
dgraph_vertices(+Graph, -Vertices )
Unify Vertices with all vertices appearing in graph Graph.
dgraph_edges(+Graph, -Edges )
Unify Edges with all edges appearing in graph Graph.
dgraph_complement(+Graph, -NewGraph )
Unify NewGraph with the graph complementary to Graph.
dgraph_transpose(+Graph, -Transpose )
Unify NewGraph with a new graph obtained from Graph by replacing all edges
of the form V1-V2 by edges of the form V2-V1.
dgraph_transitive_closure(+Graph, -Closure )
Unify Closure with the transitive closure of graph Graph.
dgraph_symmetric_closure(+Graph, -Closure )
Unify Closure with the symmetric closure of graph Graph, that is, if Closure
contains an edge U-V it must also contain the edge V-U.
dgraph_top_sort(+Graph, -Vertices )
Unify Vertices with the topological sort of graph Graph.
108 YAP Prolog User’s Manual
8 SWI-Prolog Emulation
This library provides a number of SWI-Prolog builtins that are not by default in YAP. This
library is loaded with the use_module(library(swi)) command.
append(?List1,?List2,?List3 )
Succeeds when List3 unifies with the concatenation of List1 and List2. The
predicate can be used with any instantiation pattern (even three variables).
between(+Low,+High,?Value )
Low and High are integers, High less or equal than Low. If Value is an integer,
Low less or equal than Value less or equal than High. When Value is a variable
it is successively bound to all integers between Low and High. If High is inf,
between/3 is true iff Value less or equal than Low, a feature that is particularly
interesting for generating integers from a certain value.
chdir(+Dir )
Compatibility predicate. New code should use working_directory/2.
concat_atom(+List,-Atom )
List is a list of atoms, integers or floating point numbers. Succeeds if Atom
can be unified with the concatenated elements of List. If List has exactly 2
elements it is equivalent to atom_concat/3, allowing for variables in the list.
concat_atom(?List,+Separator,?Atom )
Creates an atom just like concat atom/2, but inserts Separator between each
pair of atoms. For example: \
?- concat_atom([gnu, gnat], ’, ’, A).
A = ’gnu, gnat’
(Unimplemented) This predicate can also be used to split atoms by instantiating
Separator and Atom:
?- concat_atom(L, -, ’gnu-gnat’).
L = [gnu, gnat]
nth1(+Index,?List,?Elem )
Succeeds when the Index-th element of List unifies with Elem. Counting starts
at 1.
Set environment variable. Name and Value should be instantiated to atoms or
integers. The environment variable will be passed to shell/[0-2] and can be
requested using getenv/2. They also influence expand_file_name/2.
setenv(+Name,+Value )
Set environment variable. Name and Value should be instantiated to atoms or
integers. The environment variable will be passed to shell/[0-2] and can be
requested using getenv/2. They also influence expand_file_name/2.
term_to_atom(?Term,?Atom )
Succeeds if Atom describes a term that unifies with Term. When Atom is
instantiated Atom is converted and then unified with Term. If Atom has no
110 YAP Prolog User’s Manual
X = [1, 2, 3]
we will phrase this as “Predicate is applied on ...”
maplist(+Pred,+List )
Pred is applied successively on each element of List until the end of the list or
Pred fails. In the latter case maplist/2 fails.
maplist(+Pred,+List1,+List2 )
Apply Pred on all successive triples of elements from List1 and List2. Fails if
Pred can not be applied to a pair. See the example above.
maplist(+Pred,+List1,+List2,+List4 )
Apply Pred on all successive triples of elements from List1, List2 and List3.
Fails if Pred can not be applied to a triple. See the example above.
8.2 Forall
forall(+Cond,+Action )
For all alternative bindings of Cond Action can be proven. The next example
verifies that all arithmetic statements in the list L are correct. It does not say
which is wrong if one proves wrong.
?- forall(member(Result = Formula, [2 = 1 + 1, 4 = 2 * 2]),
Result =:= Formula).
predicate. Each attribute is associated to a module and the hook (attr unify hook/2) is
executed in this module. The example below realises a very simple and incomplete finite
domain reasoner.
:- module(domain,
[ domain/2 % Var, ?Domain
]).
:- use_module(library(oset)).
domain(X, Dom) :-
var(Dom), !,
get_attr(X, domain, Dom).
domain(X, List) :-
sort(List, Domain),
put_attr(Y, domain, Domain),
X = Y.
attr_unify_hook(Domain, Y) :-
( get_attr(Y, domain, Dom2)
-> oset_int(Domain, Dom2, NewDomain),
( NewDomain == []
-> fail
; NewDomain = [Value]
-> Y = Value
; put_attr(Y, domain, NewDomain)
)
; var(Y)
-> put_attr( Y, domain, Domain )
; memberchk(Y, Domain)
).
Before explaining the code we give some example queries:
?- domain(X, [a,b]), X = c
no
?- domain(X, [a,b]), domain(X, [a,c]).
X=a
?- domain(X, [a,b,c]), domain(X, [a,c]).
X = D0
The predicate domain/2 fetches (first clause) or assigns (second clause) the variable a
domain, a set of values it can be unified with. In the second clause first associates the
domain with a fresh variable and then unifies X to this variable to deal with the possibility
that X already has a domain. The predicate attr_unify_hook/2 is a hook called after a
variable with a domain is assigned a value. In the simple case where the variable is bound
to a concrete value we simply check whether this value is in the domain. Otherwise we take
112 YAP Prolog User’s Manual
the intersection of the domains and either fail if the intersection is empty (first example),
simply assign the value if there is only one value in the intersection (second example) or
assign the intersection as the new domain of the variable (third example).
put_attr(+Var,+Module,+Value )
If Var is a variable or attributed variable, set the value for the attribute named
Module to Value. If an attribute with this name is already associated with
Var, the old value is replaced. Backtracking will restore the old value (i.e. an
attribute is a mutable term. See also setarg/3). This predicate raises a type
error if Var is not a variable or Module is not an atom.
get_attr(+Var,+Module,+Value )
Request the current value for the attribute named Module. If Var is not an
attributed variable or the named attribute is not associated to Var this predicate
fails silently. If Module is not an atom, a type error is raised.
del_attr(+Var,+Module )
Delete the named attribute. If Var loses its last attribute it is transformed back
into a traditional Prolog variable. If Module is not an atom, a type error is
raised. In all other cases this predicate succeeds regarless whether or not the
named attribute is present.
attr_unify_hook(+AttValue,+VarValue )
Hook that must be defined in the module an attributed variable refers to. Is is
called after the attributed variable has been unified with a non-var term, possi-
bly another attributed variable. AttValue is the attribute that was associated
to the variable in this module and VarValue is the new value of the variable.
Normally this predicate fails to veto binding the variable to VarValue, forcing
backtracking to undo the binding. If VarValue is another attributed variable the
hook often combines the two attribute and associates the combined attribute
with VarValue using put_attr/3.
• The value lives on the Prolog (global) stack. This implies that lookup time is indepen-
dent from the size of the term. This is particulary interesting for large data structures
such as parsed XML documents or the CHR global constraint store.
• They support both global assignment using nb_setval/2 and backtrackable assignment
using b_setval/2.
• Only one value (which can be an arbitrary complex Prolog term) can be associated to
a variable at a time.
• Their value cannot be shared among threads. Each thread has its own namespace and
values for global variables.
• Currently global variables are scoped globally. We may consider module scoping in
future versions.
Both b_setval/2 and nb_setval/2 implicitely create a variable if the referenced name
does not already refer to a variable.
Global variables may be initialised from directives to make them available during the
program lifetime, but some considerations are necessary for saved-states and threads.
Saved-states to not store global variables, which implies they have to be declared with
initialization/1 to recreate them after loading the saved state. Each thread has its own
set of global variables, starting with an empty set. Using thread_inititialization/1
to define a global variable it will be defined, restored after reloading a saved state and
created in all threads that are created after the registration.
b_setval(+Name,+Value )
Associate the term Value with the atom Name or replaces the currently asso-
ciated value with Value. If Name does not refer to an existing global variable a
variable with initial value [] is created (the empty list). On backtracking the
assignment is reversed.
b_getval(+Name,-Value )
Get the value associated with the global variable Name and unify it with Value.
Note that this unification may further instantiate the value of the global vari-
able. If this is undesirable the normal precautions (double negation or copy_
term/2) must be taken. The b_getval/2 predicate generates errors if Name is
not an atom or the requested variable does not exist.
nb_setval(+Name,+Value )
Associates a copy of Value created with duplicate_term/2 with the atom
Name. Note that this can be used to set an initial value other than [] prior to
backtrackable assignment.
nb_getval(+Name,-Value )
The nb_getval/2 predicate is a synonym for b getval/2, introduced for com-
patibility and symetry. As most scenarios will use a particular global variable
either using non-backtracable or backtrackable assignment, using nb_getval/2
can be used to document that the variable is used non-backtracable.
nb_current(?Name,?Value )
Enumerate all defined variables with their value. The order of enumeration is
undefined.
114 YAP Prolog User’s Manual
nb_delete(?Name )
Delete the named global variable.
9 Extensions to Prolog
YAP includes several extensions that are not enabled by default, but that can be used to
extend the functionality of the system. These options can be set at compilation time by
enabling the related compilation flag, as explained in the Makefile
9.2 Coroutining
Prolog uses a simple left-to-right flow of control. It is sometimes convenient to change this
control so that goals will only be executed when conditions are fulfilled. This may result
in a more "data-driven" execution, or may be necessary to correctly implement extensions
such as negation by default.
The COROUTINING flag enables this option. Note that the support for coroutining will in
general slow down execution.
The following declaration is supported:
block/1 The argument to block/1 is a condition on a goal or a conjunction of condi-
tions, with each element separated by commas. Each condition is of the form
predname(C1,...,CN ), where N is the arity of the goal, and each CI is of
the form -, if the argument must suspend until the variable is bound, or ?,
otherwise.
wait/1 The argument to wait/1 is a predicate descriptor or a conjunction of these
predicates. These predicates will suspend until their first argument is bound.
The following primitives are supported:
dif(X,Y ) Succeed if the two arguments do not unify. A call to dif/2 will suspend if
unification may still succeed or fail, and will fail if they always unify.
freeze(?X,:G )
Delay execution of goal G until the variable X is bound.
116 YAP Prolog User’s Manual
frozen(X,G )
Unify G with a conjunction of goals suspended on variable X, or true if no goal
has suspended.
when(+C,:G )
Delay execution of goal G until the conditions C are satisfied. The conditions
are of the following form:
C1,C2 Delay until both conditions C1 and C2 are satisfied.
C1 ;C2 Delay until either condition C1 or condition C2 is satisfied.
?=(V1,C2 )
Delay until terms V1 and V1 have been unified.
nonvar(V )
Delay until variable V is bound.
ground(V )
Delay until variable V is ground.
Note that when/2 will fail if the conditions fail.
call_residue(:G,L )
Call goal G. If subgoals of G are still blocked, return a list containing these
goals and the variables they are blocked in. The goals are then considered as
unblocked. The next example shows a case where dif/2 suspends twice, once
outside call_residue/2, and the other inside:
?- dif(X,Y),
call_residue((dif(X,Y),(X = f(Z) ; Y = f(Z))), L).
X = f(Z),
L = [[Y]-dif(f(Z),Y)],
dif(f(Z),Y) ? ;
Y = f(Z),
L = [[X]-dif(X,f(Z))],
dif(X,f(Z)) ? ;
no
The system only reports one invocation of dif/2 as having suspended.
Chapter 10: Attributed Variables 117
10 Attributed Variables
YAP now supports the attributed variables packaged developed at OFAI by Christian
Holzbaur. Attributes are a means of declaring that an arbitrary term is a property for
a variable. These properties can be updated during forward execution. Moreover, the uni-
fication algorithm is aware of attributed variables and will call user defined handlers when
trying to unify these variables.
Attributed variables provide an elegant abstraction over which one can extend Prolog
systems. Their main application so far has been in implementing constraint handlers, such
as Holzbaur’s CLPQR and Fruewirth and Holzbaur’s CHR, but other applications have
been proposed in the literature.
The command
| ?- use_module(library(atts)).
enables the use of attributed variables. The package provides the following functionality:
• Each attribute must be declared first. Attributes are described by a functor and are
declared per module. Each Prolog module declares its own sets of attributes. Different
modules may have different functors with the same module.
• The built-in put_atts/2 adds or deletes attributes to a variable. The variable may be
unbound or may be an attributed variable. In the latter case, YAP discards previous
values for the attributes.
• The built-in get_atts/2 can be used to check the values of an attribute associated
with a variable.
• The unification algorithm calls the user-defined predicate verify_attributes/3 before
trying to bind an attributed variable. Unification will resume after this call.
• The user-defined predicate attribute_goal/2 converts from an attribute to a goal.
• The user-defined predicate project_attributes/2 is used from a set of variables into
a set of constraints or goals. One application of project_attributes/2 is in the
top-level, where it is used to output the set of floundered constraints at the end of a
query.
Notice that the verify_attributes/3 may be called even if Var has no at-
tributes in module Module. In this case the routine should simply succeed with
Goals unified with the empty list.
attvar(-Var )
Succeed if Var is an attributed variable.
:- module(domain, [domain/2]).
:- use_module(library(atts)).
:- use_module(library(ordsets), [
ord_intersection/3,
ord_intersect/2,
list_to_ord_set/2
]).
:- attribute dom/1.
domain(X, Dom) :-
var(Dom), !,
get_atts(X, dom(Dom)).
domain(X, List) :-
list_to_ord_set(List, Set),
Set = [El|Els], % at least one element
( Els = [] -> % exactly one element
X = El % implied binding
; put_atts(Fresh, dom(Set)),
X = Fresh % may call
% verify_attributes/3
).
Chapter 10: Attributed Variables 121
Note that the “implied binding” Other=El was deferred until after the completion of
verify_attribute/3. Otherwise, there might be a danger of recursively invoking verify_
attribute/3, which might bind Var, which is not allowed inside the scope of verify_
attribute/3. Deferring unifications into the third argument of verify_attribute/3 ef-
fectively serializes the calls to verify_attribute/3.
Assuming that the code resides in the file ‘domain.yap’, we can use it via:
| ?- use_module(domain).
Let’s test it:
| ?- domain(X,[5,6,7,1]), domain(Y,[3,4,5,6]), domain(Z,[1,6,7,8]).
domain(X,[1,5,6,7]),
domain(Y,[3,4,5,6]),
domain(Z,[1,6,7,8]) ?
yes
| ?- domain(X,[5,6,7,1]), domain(Y,[3,4,5,6]), domain(Z,[1,6,7,8]),
X=Y.
Y = X,
domain(X,[5,6]),
domain(Z,[1,6,7,8]) ?
yes
| ?- domain(X,[5,6,7,1]), domain(Y,[3,4,5,6]), domain(Z,[1,6,7,8]),
X=Y, Y=Z.
X = 6,
Y = 6,
Z = 6
To demonstrate the use of the Goals argument of verify_attributes/3, we give an
implementation of freeze/2. We have to name it myfreeze/2 in order to avoid a name
clash with the built-in predicate of the same name.
:- module(myfreeze, [myfreeze/2]).
:- use_module(library(atts)).
:- attribute frozen/1.
Goals = []
; Goals = [Fa]
).
verify_attributes(_, _, []).
myfreeze(X, Goal) :-
put_atts(Fresh, frozen(Goal)),
Fresh = X.
Assuming that this code lives in file ‘myfreeze.yap’, we would use it via:
| ?- use_module(myfreeze).
| ?- myfreeze(X,print(bound(x,X))), X=2.
A = B / C when C is ground or // A = B / 3
A and B are ground // 4 = 12 / C
12.1 Introduction
Constraint Handling Rules (CHR) is a committed-choice bottom-up language embedded in
Prolog. It is designed for writing constraint solvers and is particularily useful for provid-
ing application-specific constraints. It has been used in many kinds of applications, like
scheduling, model checking, abduction, type checking among many others.
CHR has previously been implemented in other Prolog systems (SICStus, Eclipse, Yap),
Haskell and Java. This CHR system is based on the compilation scheme and runtime
environment of CHR in SICStus.
In this documentation we restrict ourselves to giving a short overview of CHR in general
and mainly focus on elements specific to this implementation. For a more thorough review
of CHR we refer the reader to [Freuhwirth:98]. More background on CHR can be found at
the CHR web site.
12.2.2 Semantics
In this subsection the operational semantics of CHR in Prolog are presented informally.
They do not differ essentially from other CHR systems.
When a constraint is called, it is considered an active constraint and the system will try
to apply the rules to it. Rules are tried and executed sequentially in the order they are
written.
A rule is conceptually tried for an active constraint in the following way. The active
constraint is matched with a constraint in the head of the rule. If more constraints appear
in the head they are looked for among the suspended constraints, which are called passive
constraints in this context. If the necessary passive constraints can be found and all match
with the head of the rule and the guard of the rule succeeds, then the rule is committed and
the body of the rule executed. If not all the necessary passive constraint can be found, the
matching fails or the guard fails, then the body is not executed and the process of trying
and executing simply continues with the following rules. If for a rule, there are multiple
constraints in the head, the active constraint will try the rule sequentially multiple times,
each time trying to match with another constraint.
Chapter 12: CHR: Constraint Handling Rules 129
This process ends either when the active constraint disappears, i.e. it is removed by
some rule, or after the last rule has been processed. In the latter case the active constraint
becomes suspended.
A suspended constraint is eligible as a passive constraint for an active constraint. The
other way it may interact again with the rules, is when a variable appearing in the con-
straint becomes bound to either a nonvariable or another variable involved in one or more
constraints. In that case the constraint is triggered, i.e. it becomes an active constraint
and all the rules are tried.
Rule Types
There are three different kinds of rules, each with their specific semantics:
simplification
The simplification rule removes the constraints in its head and calls its body.
propagation
The propagation rule calls its body exactly once for the constraints in its head.
simpagation
The simpagation rule removes the constraints in its head after the \ and then
calls its body. It is an optimization of simplification rules of the form: \[con-
straints 1, constraints 2 <=> constraints 1, body \] Namely, in the simpagation
form:
constraints1 \ constraints2 <=> body
constraints1 constraints are not called in the body.
Rule Names
Naming a rule is optional and has no semantical meaning. It only functions as documenta-
tion for the programmer.
Pragmas
The semantics of the pragmas are:
‘passive(Identifier)’
The constraint in the head of a rule Identifier can only act as a passive constraint
in that rule.
Additional pragmas may be released in the future.
Options
It is possible to specify options that apply to all the CHR rules in the module. Options are
specified with the option/2 declaration:
option(Option,Value).
Available options are:
check_guard_bindings
This option controls whether guards should be checked for illegal variable bind-
ings or not. Possible values for this option are on, to enable the checks, and
off, to disable the checks.
130 YAP Prolog User’s Manual
type(bool,[true,false]).
type(complex_number,[float + float * i]).
type(binary_tree(T),[ leaf(T) | node(binary_tree(T),binary_tree(T)) ]).
type(list(T),[ [] | [T | list(T)]).
The mode, type declaration and type definition options are provided for backward com-
patibility. The new syntax is described below.
12.3.3 Compilation
The SWI-Prolog CHR compiler exploits term expansion/2 rules to translate the constraint
handling rules to plain Prolog. These rules are loaded from the library ‘chr’. They are
activated if the compiled file has the ‘chr’ extension or after finding a declaration of the
format below.
:- constraints ...
It is adviced to define CHR rules in a module file, where the module declaration is
immediately followed by including the ‘chr’ library as examplified below:
:- module(zebra, [ zebra/0 ]).
:- use_module(library(chr)).
:- constraints ...
Using this style CHR rules can be defined in ordinary Prolog ‘pl’ files and the operator
definitions required by CHR do not leak into modules where they might cause conflicts.
12.4 Debugging
The CHR debugging facilities are currently rather limited. Only tracing is currently avail-
able. To use the CHR debugging facilities for a CHR file it must be compiled for debugging.
132 YAP Prolog User’s Manual
Generating debug info is controlled by the CHR option debug, whose default is derived from
the SWI-Prolog flag generate_debug_info. Therefore debug info is provided unless the
‘-nodebug’ is used.
12.4.1 Ports
For CHR constraints the four standard ports are defined:
call A new constraint is called and becomes active.
exit An active constraint exits: it has either been inserted in the store after trying
all rules or has been removed from the constraint store.
fail An active constraint fails.
redo An active constraint starts looking for an alternative solution.
In addition to the above ports, CHR constraints have five additional ports:
wake A suspended constraint is woken and becomes active.
insert An active constraint has tried all rules and is suspended in the constraint store.
remove An active or passive constraint is removed from the constraint store, if it had
been inserted.
try An active constraints tries a rule with possibly some passive constraints. The
try port is entered just before committing to the rule.
apply An active constraints commits to a rule with possibly some passive constraints.
The apply port is entered just after committing to the rule.
12.4.2 Tracing
Tracing is enabled with the chr trace/0 predicate and disabled with the chr notrace/0
predicate.
When enabled the tracer will step through the call, exit, fail, wake and apply ports,
accepting debug commands, and simply write out the other ports.
The following debug commans are currently supported:
CHR debug options:
ancestors
Print list of ancestor call and wake ports.
nodebug Disable the tracer.
break Enter a recursive Prolog toplevel. See break/0.
abort Exit to the toplevel. See abort/0.
fail Insert failure in execution.
help Print the above available debug options.
12.5 Examples
Here are two example constraint solvers written in CHR.
• The program below defines a solver with one constraint, leq/2, which is a less-than-
or-equal constraint.
:- module(leq,[cycle/3, leq/2]).
:- use_module(library(chr)).
:- constraints leq/2.
reflexivity leq(X,X) <=> true.
antisymmetry leq(X,Y), leq(Y,X) <=> X = Y.
idempotence leq(X,Y) \ leq(X,Y) <=> true.
transitivity leq(X,Y), leq(Y,Z) ==> leq(X,Z).
134 YAP Prolog User’s Manual
cycle(X,Y,Z):-
leq(X,Y),
leq(Y,Z),
leq(Z,X).
• The program below implements a simple finite domain constraint solver.
:- module(dom,[dom/2]).
:- use_module(library(chr)).
:- constraints dom/2.
intersection([],_,[]).
intersection([H|T],L2,[H|L3]) :-
member(H,L2), !,
intersection(T,L2,L3).
intersection([_|T],L2,L3) :-
intersection(T,L2,L3).
12.7 Guidelines
In this section we cover several guidelines on how to use CHR to write constraint solvers
and how to do so efficiently.
[Set semantics]
The CHR system allows the presence of identical constraints, i.e. multiple
constraints with the same functor, arity and arguments. For most constraint
Chapter 12: CHR: Constraint Handling Rules 135
13 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. Be sure to read the
Logtalk/INSTALL file for additional instructions on how to customize your Logtalk
installation to match your working environment.
For the latest Llogtalk news, please see the URL http://www.logtalk.org/.
138 YAP Prolog User’s Manual
Chapter 14: Threads 139
14 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.
current_thread(+Id, -Status )
Enumerates identifiers and status of all currently known threads. Calling cur-
rent 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.
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 follow-
ing 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.
Chapter 14: Threads 143
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).
thread_signal(+ThreadId, :Goal )
Make thread ThreadId execute Goal at the first opportunity. In the current im-
plementation, 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-
144 YAP Prolog User’s Manual
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.
foo(gnat).
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 refer-
ences 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.
146 YAP Prolog User’s Manual
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.
Chapter 15: Parallelism 147
15 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 fol-
lowing 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.
148 YAP Prolog User’s Manual
Chapter 16: Tabling 149
16 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.
The following predicates may be useful to control tabled execution:
is_tabled(+PredIndicator )
Succeeds if the predicate PredIndicator, of the form Name/Arity, is a tabled
predicate.
tabling_mode(+PredIndicator,+Options )
Sets tabling mode options for the list or predicate given by PredIndicator. The
list of Options includes:
batched: use batched scheduling for this predicate (default).
local: use local scheduling for this predicate.
exec_answers: use complete tries as code (default).
load_answers: use complete tries as a consumer, somewhat less
efficient but creates less choice-points.
abolish_table(+PredIndicator )
Remove tables for PredIndicator
show_table(+PredIndicator )
Print out the contents of the table generated for PredIndicator.
table_statistics(+PredIndicator )
Print out some information on the current tables for PredIndicator.
150 YAP Prolog User’s Manual
Chapter 17: Tracing at Low Level 151
19 Debugging
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:
Chapter 19: Debugging 157
• The first three characters are used to point out special states of the debugger. If the
port is exit and the first character is ’ ?’, the current call still has alternatives to be
tried. If the second character is a *, execution is at a spy-point. If the third 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.
158 YAP Prolog User’s Manual
20 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 com-
pilers, 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 pro-
grammers 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
160 YAP Prolog User’s Manual
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).
Chapter 21: C Language interface to YAP 161
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.
162 YAP Prolog User’s Manual
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.
21.1 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
Chapter 21: C Language interface to YAP 163
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
YAP_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_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_Term t )
where flt is a typedef for the appropriate C floating point type, nowadays a double
The following primitives are provided for verifying whether a term is a big int, creating
a term from a big integer and to access the value of a big int from a term.
YAP_Bool YAP_IsBigNumTerm(YAP_Term t )
YAP_Term YAP_MkBigNumTerm(void *b )
void *YAP_BigNumOfTerm(YAP_Term t, void *b )
YAP must support bignum for the configuration you are using (check the YAP configuration
and setup). For now, Yap only supports the GNU GMP library, and void * will be a cast
for mpz_t. Notice that YAP_BigNumOfTerm requires the number to be already initialised.
As an example, we show how to print a bignum:
static int
p_print_bignum(void)
{
mpz_t mz;
if (!YAP_IsBigNumTerm(YAP_ARG1))
164 YAP Prolog User’s Manual
return FALSE;
mpz_init(mz);
YAP_BigNumOfTerm(YAP_ARG1, mz);
gmp_printf("Shows up as %Zd\n", mz);
mpz_clear(mz);
return TRUE;
}
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_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_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.
Chapter 21: C Language interface to YAP 165
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.
21.2 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.
21.3 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 buf-
size )
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.
The C-interface function calls the parser on a sequence of characters stored at buf and
returns the resulting term.
YAP_Term YAP_ReadBuffer(char *buf,YAP_Term *error )
The user-provided string must include a terminating null character. Syntax errors will cause
returning FALSE and binding error to a Prolog term.
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(void)
{
YAP_Term t = YAP_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) {
168 YAP Prolog User’s Manual
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(void)
{
int n;
YAP_Term t;
YAP_Term sol = YAP_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 back-
tracking. 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
Chapter 21: C Language interface to YAP 169
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. In this example, we would have
something like
void
init_n100(void)
{
YAP_UserBackCPredicate("n100", start_n100, continue_n100, 1, 1);
}
• 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.
Chapter 22: Using YAP as a Library 171
int
main(int argc, char *argv[]) {
if (YAP_FastInit("saved_state") == YAP_BOOT_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:
172 YAP Prolog User’s Manual
• YAP_Term YAP Read(int (*)(void) GetC) Parse a Term using the function GetC to
input characters.
• YAP_Term YAP RunGoal(YAP_Term Goal) Execute query Goal and return 1 if the query
succeeds, and 0 otherwise. The predicate returns 0 if failure, otherwise it will return
YAP Term. Note that YAP Term may change due to garbage collection, so you should
use something like:
t = YAP_RunGoal(t);
if (t == 0) return FALSE;
If the execution fails, garbage collection might still have changed the term, so you
should not use the input argument again.
An alternative is to use slots, as shown next:
long sl = YAP_InitSlot(scoreTerm);
out = YAP_RunGoal(t);
t = YAP_GetFromSlot(sl);
YAP_RecoverSlots(1);
if (out == 0) return FALSE;
Slots are safe houses in the stack, preserved by the garbage collector and the stack
shifter. In this case, we use a slot to preserve t during the execution of YAP_RunGoal.
When the execution of t is over we read the (possibly changed) value of t back from
the slot sl and tell YAP that the slot sl is not needed and can be given back to the
system.
• int YAP RestartGoal(void) Look for the next solution to the current query by forcing
YAP to backtrack.
• int YAP Reset(void) Reset execution environment (similar to the abort/0 built-in).
This is useful when you want to start a new query before asking all solutions to the
previous query.
• YAP_Bool YAP GoalHasException(YAP_Term *tp) Check if the last goal generated an
exception, and if so copy it to the space pointed to by tp
• void YAP ClearExceptions(void) Reset any exceptions left over by the system.
• void YAP Write(YAP_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 YAP WriteBuffer(YAP_Term t, char * buff, unsigned int size, int flags) Write
a YAP Term t to buffer buff with size size. 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 YAP InitConsult(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.
174 YAP Prolog User’s Manual
Note that it is up to the user to open the file filename. The YAP_InitConsult function
only uses the file name for internal bookkeeping.
• void YAP EndConsult(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.
Chapter 23: Compatibility with Other Prolog systems 175
! <
!/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 </2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
, =
,/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 =../2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
=:=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
=</2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
; ==/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
;/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 =\=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
176 YAP Prolog User’s Manual
> F
>/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 fail/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
>=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 fileerrors/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
findall/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
functor/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
@
@</2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
@>/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
G
@>=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 get/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
get0/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
[ H
[-]/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
halt/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
[]/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
\ I
instance/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
\+/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
integer/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
\==/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
A K
keysort/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
abort/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
atom/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
atomic/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 L
leash/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
length/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
B
bagof/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
break/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 N
name/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
nl/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
C nodebug/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
call/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 nofileerrors/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
close/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 nonvar/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
compare/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 nospy/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
consult/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 not/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
current atom/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 number/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
current predicate/1 . . . . . . . . . . . . . . . . . . . . . . . . . . 57
O
D op/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
db reference/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
debug/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
debugging/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 P
display/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 primitive/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
print/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
prompt/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
E put/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
erase/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
erased/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
exists/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
R
expand exprs/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 read/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
expand term/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 reconsult/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
recorda/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Chapter 23: Compatibility with Other Prolog systems 177
recorded/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 T
recordz/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
tab/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
rename/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
tell/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
repeat/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
telling/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
term expansion/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
S told/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
save/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 true/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
see/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
seeing/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
seen/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 V
setof/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 var/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
sh/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
skip/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
sort/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
spy/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 W
statistics/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 write/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
system/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 writeq/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
A I
abolish/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 is/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
abolish/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
assert/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
assert/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 L
asserta/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 listing/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
asserta/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 listing/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
assertz/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
assertz/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
N
nth clause/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
C
clause/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
clause/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 R
retract/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
- A
->/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 abolish table/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
absolute file name/2 . . . . . . . . . . . . . . . . . . . . . . . . . 42
add edges/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
= add to array element/4 . . . . . . . . . . . . . . . . . . . . . . 71
=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 add to heap/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
add vertices/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
alarm/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
\ all/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
\=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 always prompt user/0. . . . . . . . . . . . . . . . . . . . . . . . 52
append/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87, 109
178 YAP Prolog User’s Manual
arg/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 compound/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
array/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 concat atom/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
array element/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 concat atom/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
assert static/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 convlist/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
asserta static/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 copy term/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
assertz static/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 copy term nat/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
assoc to list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 create mutable/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
at end of stream/0 . . . . . . . . . . . . . . . . . . . . . . . . . . 42 current char conversion/2 . . . . . . . . . . . . . . . . . . . . 45
at end of stream/1 . . . . . . . . . . . . . . . . . . . . . . . . . . 42 current input/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
atom chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 current key/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
atom codes/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 current module/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
atom concat/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 current module/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
atom concat/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 current mutex/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
atom length/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 current op/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
atom to chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 current output/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
atom to chars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 current predicate/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 57
atomic concat/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 current prolog flag/2. . . . . . . . . . . . . . . . . . . . . . . . . 80
attr unify hook/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 112 current stream/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
attribute goal/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 current thread/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
attvar/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 cyclic term/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
avl insert/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
avl lookup/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
D
B datime/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
del assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
b getval/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
b setval/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 del attr/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
bb delete/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 del edges/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
bb get/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 del max assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
bb put/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 del min assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
bb update/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 del vertices/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
between/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 delete/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
delete file/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
delete file/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
C dgraph add edges/3 . . . . . . . . . . . . . . . . . . . . . . . . 107
dgraph add vertices/3 . . . . . . . . . . . . . . . . . . . . . . 107
C/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
dgraph complement/2. . . . . . . . . . . . . . . . . . . . . . . 107
call cleanup/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
dgraph compose/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 107
call cleanup/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
call count data/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 dgraph del edges/3 . . . . . . . . . . . . . . . . . . . . . . . . . 107
call count data/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 dgraph del vertices/3 . . . . . . . . . . . . . . . . . . . . . . . 107
call residue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 dgraph edges/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
call with args/n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 dgraph neighbors/3 . . . . . . . . . . . . . . . . . . . . . . . . . 107
callable/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 dgraph neighbours/3 . . . . . . . . . . . . . . . . . . . . . . . . 107
catch/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 dgraph new/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
cd/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 dgraph symmetric closure/2 . . . . . . . . . . . . . . . . . 107
char code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 dgraph top sort/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 107
char conversion/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 dgraph transitive closure/2 . . . . . . . . . . . . . . . . . . 107
chdir/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 dgraph transpose/2 . . . . . . . . . . . . . . . . . . . . . . . . . 107
checklist/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 dgraph vertices/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
checknodes/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 dif/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
cleanup all/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 directory files/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
close/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 discontiguous/1 (directive) . . . . . . . . . . . . . . . . . . . 21
close static array/1 . . . . . . . . . . . . . . . . . . . . . . . . . . 71 display/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45, 50
compile/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 display/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
compile/1 (directive) . . . . . . . . . . . . . . . . . . . . . . . . . 19 do not compile expressions/0 . . . . . . . . . . . . . . . . . 20
compile expressions/0 . . . . . . . . . . . . . . . . . . . . . . . . 20 dynamic/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
complement/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 dynamic predicate/2 . . . . . . . . . . . . . . . . . . . . . . . . . 55
compose/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Chapter 23: Compatibility with Other Prolog systems 179
E ground/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
edges/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 grow heap/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
empty assoc/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 grow stack/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
empty heap/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
empty queue/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
environ/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64, 99 H
eraseall/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 halt/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
exec/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 head queue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
heap size/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
heap to list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
F hide/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
false/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 hide predicate/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
file exists/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 host id/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
file exists/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 host name/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
file property/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
file search path/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
findall/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 I
flatten/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 if/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
float/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 incore/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
flush output/0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 initialization/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
flush output/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 initialization/1 (directive) . . . . . . . . . . . . . . . . . . . . 21
forall/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 is assoc/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
format/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 is list/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
format/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 is mutable/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
format to chars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 is rbtree/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
format to chars/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 is tabled/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
fragile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
freeze/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
frozen/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 J
join queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
jump queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
G
garbage collect/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
garbage collect atoms/0 . . . . . . . . . . . . . . . . . . . . . . 30 K
gc/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 key statistics/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
gen assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 key statistics/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
get/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 kill/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
get assoc/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
get assoc/5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
get attr/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
get attrs/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
L
get atts/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 last/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
get byte/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 length queue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
get byte/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 library directory/1 . . . . . . . . . . . . . . . . . . . . . . . 21, 22
get char/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 list concat/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
get char/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 list join queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
get code/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 list jump queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
get code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 list to assoc/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
get from heap/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 list to heap/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
get label/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 list to ord set/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
get mutable/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 list to queue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
get next assoc/4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 list to rbtree/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
get prev assoc/4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 list to tree/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
get value/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
get0/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
getcwd/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 M
getrand/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 make directory/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
goal expansion/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 make queue/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
180 YAP Prolog User’s Manual
map assoc/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 O
map assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 on cleanup/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
map tree/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 on signal/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
mapargs/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 once/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
maplist/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 open/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
maplist/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83, 110 open/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
maplist/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 open chars stream/2 . . . . . . . . . . . . . . . . . . . . . . . . . 97
mapnodes/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 ord add element/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
max assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 ord del element/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
max list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 ord disjoint/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
member/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 ord insert/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
memberchk/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 ord intersect/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
merge/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 ord intersect/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
meta predicate/1 (directive) . . . . . . . . . . . . . . . . . . 25 ord intersect/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
min assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 ord list to assoc/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
min list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 ord member/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
min of heap/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 ord seteq/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
min of heap/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 ord setproduct/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
mktemp/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 ord subtract/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
mktime/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 ord symdiff/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
module/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 ord union/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
module/2 (directive) . . . . . . . . . . . . . . . . . . . . . . . . . 24 ord union/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
module/3 (directive) . . . . . . . . . . . . . . . . . . . . . . . . . 24 ord union/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
multifile/1 (directive) . . . . . . . . . . . . . . . . . . . . . . . . 21 ordsubset/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
mutex create/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
mutex destroy/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
mutex lock/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 P
mutex statistics/0 . . . . . . . . . . . . . . . . . . . . . . . . . . 141 path/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20, 21
mutex trylock/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 peek byte/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
mutex unlock/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 peek byte/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
mutex unlock all/0 . . . . . . . . . . . . . . . . . . . . . . . . . 146 peek char/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
peek char/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
peek code/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
N peek code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
permutation/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
nb current/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
phrase/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
nb delete/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
phrase/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
nb getval/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
pid/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
nb setval/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
popen/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
neighbors/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 portray clause/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
neighbours/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 portray clause/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
nl/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 predicate property/2 . . . . . . . . . . . . . . . . . . . . . . . . . 57
no source/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 print/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
nogc/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 profile data/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
nospyall/0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 profiled reset/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
nth/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 project attributes/2 . . . . . . . . . . . . . . . . . . . . . . . . 119
nth/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 prolog file name/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
nth recorded/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 prolog flag/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
nth0/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 prolog initialization/1 . . . . . . . . . . . . . . . . . . . . . . . . 80
nth0/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 prolog load context/2 . . . . . . . . . . . . . . . . . . . . . . . . 80
nth1/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 public/1 (directive) . . . . . . . . . . . . . . . . . . . . . . . . . . 22
number atom/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 put/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
number chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 put assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
number codes/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 put attr/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
number to chars/2. . . . . . . . . . . . . . . . . . . . . . . . . . . 97 put attrs/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
number to chars/3. . . . . . . . . . . . . . . . . . . . . . . . . . . 97 put atts/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
numbervars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 put byte/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
put byte/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Chapter 23: Compatibility with Other Prolog systems 181
S
Q same length/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
queue to list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 save/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
save program/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
save program/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
R select/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
random/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 selectlist/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
random/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 serve queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
randseq/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 set input/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
randset/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 set output/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
rannum/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 set prolog flag/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
ranstart/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 set stream position/2 . . . . . . . . . . . . . . . . . . . . . . . . 42
ranstart/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 set value/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
ranunif/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 setarg/3n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
rb apply/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 setenv/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
rb clone/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 setrand/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
rb del max/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 shell/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
rb del min/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 shell/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100, 101
rb delete/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 show op counters/1 . . . . . . . . . . . . . . . . . . . . . . . . . 153
rb delete/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 show ops by group/1 . . . . . . . . . . . . . . . . . . . . . . . 153
rb empty/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 show table/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
rb insert/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 simple/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
rb keys/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 skip/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
rb lookup/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 sleep/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
rb lookupall/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 socket/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
rb map/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 socket/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
rb max/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 socket accept/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
rb min/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 socket accept/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
rb new/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 socket bind/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
rb next/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 socket buffering/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
rb partial map/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 socket close/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
rb previous/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 socket connect/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
rb size/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 socket listen/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
rb update/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 socket select/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
rb visit/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 source/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
reachable/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 source mode/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
read/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 splay access/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
read from chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 splay delete/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
read term/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 splay init/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
read term/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 splay insert/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
recorda/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 splay join/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
recorda at/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 splay split/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
recordaifnot/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . 59, 60 spy write/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
recordz at/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 srandom/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
recordzifnot/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 start low level trace/0 . . . . . . . . . . . . . . . . . . . . . . 151
regexp/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 static array/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70, 71
regexp/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 static array location/4 . . . . . . . . . . . . . . . . . . . . . . . 70
remove duplicates/2 . . . . . . . . . . . . . . . . . . . . . . . . . 88 static array properties/3 . . . . . . . . . . . . . . . . . . . . . 70
remove from path/1 . . . . . . . . . . . . . . . . . . . . . . . . . 21 static array to term/3 . . . . . . . . . . . . . . . . . . . . . . . 70
rename file/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 statistics/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
reset op counters/0 . . . . . . . . . . . . . . . . . . . . . . . . . 153 stream property/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
182 YAP Prolog User’s Manual
stream select/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 U
style check/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 undgraph add edges/3 . . . . . . . . . . . . . . . . . . . . . . 108
sub atom/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
undgraph add vertices/3 . . . . . . . . . . . . . . . . . . . . 108
sublist/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
undgraph complement/2 . . . . . . . . . . . . . . . . . . . . 108
subsumes/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
undgraph del edges/3 . . . . . . . . . . . . . . . . . . . . . . . 108
subsumes chk/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
undgraph del vertices/3 . . . . . . . . . . . . . . . . . . . . . 108
suffix/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
sum list/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 undgraph edges/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 108
sumargs/4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 undgraph neighbors/3 . . . . . . . . . . . . . . . . . . . . . . 108
sumlist/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 undgraph neighbours/3 . . . . . . . . . . . . . . . . . . . . . 108
sumlist/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 undgraph new/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
sumnodes/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 undgraph vertices/2 . . . . . . . . . . . . . . . . . . . . . . . . 108
system/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 unhide/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
system/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 unify with occurs check/2 . . . . . . . . . . . . . . . . . . . . 35
system predicate/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 57 unix/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
unknown/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
unknown predicate handler/3 . . . . . . . . . . . . . . . . 31
T update array/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
tab/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 update mutable/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
table statistics/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 use module/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
term hash/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 use module/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
term hash/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 use module/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
term to atom/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
term variables/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
thread at exit/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 V
thread create/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
variable in term/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 102
thread detach/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
variant/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
thread exit/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
verify attributes/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 118
thread get message/1 . . . . . . . . . . . . . . . . . . . . . . . 142
version/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
thread get message/2 . . . . . . . . . . . . . . . . . . . . . . . 142
thread join/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 version/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
thread local/1 (directive) . . . . . . . . . . . . . . . . . . . . 144 vertices/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
thread message queue create/1 . . . . . . . . . . . . . . 142 vertices edges to ugraph/3 . . . . . . . . . . . . . . . . . . 104
thread message queue destroy/1 . . . . . . . . . . . . . 142
thread peek message/1 . . . . . . . . . . . . . . . . . . . . . 142
thread self/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 W
thread send message/2 . . . . . . . . . . . . . . . . . . . . . . 141 wait/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
thread setconcurrency/2 . . . . . . . . . . . . . . . . . . . . 140 when/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
thread signal/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 with mutex/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
thread statistics/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 141 with output to chars/2 . . . . . . . . . . . . . . . . . . . . . . 97
throw/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 with output to chars/3 . . . . . . . . . . . . . . . . . . . . . . 97
time out/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 with output to chars/4 . . . . . . . . . . . . . . . . . . . . . . 97
tmpnam/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 working directory/2 . . . . . . . . . . . . . . . . . . . . 100, 110
top sort/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
write/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
top sort/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
write depth/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
transitive closure/2 . . . . . . . . . . . . . . . . . . . . . . . . . 106
write term/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
transpose/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
tree size/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 write term/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
tree to list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 write to chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
ttyget/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 write to chars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
ttyget0/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 writeq/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
ttynl/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
ttyput/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
ttyskip/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Y
ttytab/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 yap flag/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Chapter 23: Compatibility with Other Prolog systems 183
• YAP allows asserting and abolishing static code during execution through the assert_
static/1 and abolish/1 built-ins. 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)).
! ,
!/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 ,/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Chapter 23: Compatibility with Other Prolog systems 185
- B
->/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 bb delete/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
bb get/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
bb put/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
; bb update/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
;/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 break/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
< C
</2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 C/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
call/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
call cleanup/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
= call cleanup/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
=../2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 call residue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 callable/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
=:=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 char code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
=</2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 char conversion/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
==/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 cleanup all/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
=\=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 close/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
compare/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
compile/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
> complement/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
>/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 compose/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
>=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 compound/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
copy term/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
create mutable/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
@ current atom/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
@</2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 current char conversion/2 . . . . . . . . . . . . . . . . . . . . 45
@>/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 current input/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
@>=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 current key/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
current module/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
current module/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
\ current op/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
\+/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 current output/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
\==/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 current predicate/1 . . . . . . . . . . . . . . . . . . . . . . . . . . 57
current predicate/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 57
current stream/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
A cyclic term/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
abort/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
absolute file name/2 . . . . . . . . . . . . . . . . . . . . . . . . . 42 D
add edges/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
add to heap/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 datime/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
add vertices/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 db reference/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
append/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 debugging/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
arg/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 del assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
assoc to list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 del edges/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
at end of stream/0 . . . . . . . . . . . . . . . . . . . . . . . . . . 42 del max assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
at end of stream/1 . . . . . . . . . . . . . . . . . . . . . . . . . . 42 del min assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
atom/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 del vertices/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
atom codes/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 delete/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
atom concat/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 delete file/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
atom concat/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 delete file/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
atom to chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 dgraph del vertices/3 . . . . . . . . . . . . . . . . . . . . . . . 107
atom to chars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 dif/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
atomic/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 directory files/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
attribute goal/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 discontiguous/1 (directive) . . . . . . . . . . . . . . . . . . . 21
display/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45, 50
186 YAP Prolog User’s Manual
display/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 H
halt/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
halt/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
E head queue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
edges/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 heap size/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
empty assoc/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 heap to list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
empty heap/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 host id/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
empty queue/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 host name/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
environ/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64, 99
exec/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
expand term/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
I
if/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
incore/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
F initialization/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
integer/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
fail/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 is/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
false/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 is assoc/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
file exists/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 is list/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
file exists/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 is mutable/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
file property/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
file search path/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
fileerrors/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 J
findall/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 join queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
findall/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 jump queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
flatten/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
float/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
flush output/0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 K
flush output/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 keysort/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
format to chars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 kill/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
format to chars/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
fragile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
freeze/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 L
frozen/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
last/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
functor/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 leash/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
length/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
length queue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
G list join queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
garbage collect/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 list jump queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
garbage collect atoms/0 . . . . . . . . . . . . . . . . . . . . . . 30 list to assoc/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
gc/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 list to heap/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
gen assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 list to ord set/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
get/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 list to queue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
get/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 list to tree/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
get assoc/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 listing/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
get assoc/5. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
get atts/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
get from heap/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
M
get label/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 make directory/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
get mutable/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 make queue/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
get next assoc/4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 map assoc/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
get prev assoc/4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 map assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
get0/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 map tree/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
get0/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 max assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
max list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
getrand/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
member/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
ground/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
memberchk/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
merge/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Chapter 23: Compatibility with Other Prolog systems 187
T
tab/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
W
tab/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 wait/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
tell/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 when/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
telling/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 with output to chars/2 . . . . . . . . . . . . . . . . . . . . . . 97
term expansion/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 with output to chars/3 . . . . . . . . . . . . . . . . . . . . . . 97
term hash/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 with output to chars/4 . . . . . . . . . . . . . . . . . . . . . . 97
term hash/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 working directory/2 . . . . . . . . . . . . . . . . . . . . . . . . 100
term variables/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 write/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
time out/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 write/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
tmpnam/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 write term/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
told/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 write term/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
top sort/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 write to chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
top sort/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 write to chars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
transitive closure/2 . . . . . . . . . . . . . . . . . . . . . . . . . 106 writeq/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
transpose/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 writeq/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Chapter 23: Compatibility with Other Prolog systems 189
[ L
[-]/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 listing/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
[]/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
N
A nth clause/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
abolish/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 nth recorded/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
abolish/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 number chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
assert/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
assert/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
asserta/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 O
asserta/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
assertz/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 open/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
assertz/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
atom chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
P
predicate property/2 . . . . . . . . . . . . . . . . . . . . . . . . . 57
B prolog initialization/1 . . . . . . . . . . . . . . . . . . . . . . . . 80
bagof/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
R
C read term/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
clause/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 read term/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
clause/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 recorda/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
close/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 recordaifnot/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
recorded/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
recordz/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
D retract/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
debug/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 retract/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
dynamic/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 retractall/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
E S
erase/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 setof/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
erased/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 statistics/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
statistics/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
F
format/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 U
format/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 unknown/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
I V
instance/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 version/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
\ A
\=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 abolish table/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
190 YAP Prolog User’s Manual
B
b getval/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 G
b setval/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 get attr/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
between/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 get attrs/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
get byte/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
get byte/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
C get char/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
call count data/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 get char/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
call count data/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 get code/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
call with args/n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 get code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
catch/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 get value/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
cd/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 getcwd/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
chdir/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 goal expansion/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
checklist/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 grow heap/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
checknodes/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 grow stack/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
close static array/1 . . . . . . . . . . . . . . . . . . . . . . . . . . 71
compile/1 (directive) . . . . . . . . . . . . . . . . . . . . . . . . . 19
compile expressions/0 . . . . . . . . . . . . . . . . . . . . . . . . 20 H
concat atom/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 hide/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
concat atom/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 hide predicate/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
consult/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
convlist/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
copy term nat/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 I
current mutex/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
current prolog flag/2. . . . . . . . . . . . . . . . . . . . . . . . . 80 initialization/1 (directive) . . . . . . . . . . . . . . . . . . . . 21
current thread/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 is rbtree/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
is tabled/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
D
del attr/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
K
dgraph add edges/3 . . . . . . . . . . . . . . . . . . . . . . . . 107 key statistics/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
dgraph add vertices/3 . . . . . . . . . . . . . . . . . . . . . . 107 key statistics/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
dgraph complement/2. . . . . . . . . . . . . . . . . . . . . . . 107
dgraph compose/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 107
dgraph del edges/3 . . . . . . . . . . . . . . . . . . . . . . . . . 107 L
dgraph edges/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 library directory/1 . . . . . . . . . . . . . . . . . . . . . . . 21, 22
dgraph neighbors/3 . . . . . . . . . . . . . . . . . . . . . . . . . 107 list concat/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
dgraph neighbours/3 . . . . . . . . . . . . . . . . . . . . . . . . 107 list to rbtree/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
dgraph new/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Chapter 23: Compatibility with Other Prolog systems 191
M ranunif/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
mapargs/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 rb apply/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
maplist/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 rb clone/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
maplist/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83, 110 rb del max/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
maplist/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 rb del min/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
mapnodes/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 rb delete/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
mktime/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 rb delete/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
mutex create/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 rb empty/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
mutex destroy/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 rb insert/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
mutex lock/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 rb keys/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
mutex statistics/0 . . . . . . . . . . . . . . . . . . . . . . . . . . 141 rb lookup/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
mutex trylock/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 rb lookupall/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
mutex unlock/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 rb map/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
mutex unlock all/0 . . . . . . . . . . . . . . . . . . . . . . . . . 146 rb max/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
rb min/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
rb new/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
N rb next/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
rb partial map/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
nb current/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
rb previous/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
nb delete/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
rb size/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
nb getval/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
rb update/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
nb setval/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
rb visit/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
no source/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
reconsult/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
not/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
recorda/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
nth1/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
recorda at/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
number atom/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
recordaifnot/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
recordz at/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
recordzifnot/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
O regexp/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
on signal/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 regexp/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
once/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 remove from path/1 . . . . . . . . . . . . . . . . . . . . . . . . . 21
rename/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
reset op counters/0 . . . . . . . . . . . . . . . . . . . . . . . . . 153
P resize static array/3 . . . . . . . . . . . . . . . . . . . . . . . . . 71
path/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20, 21
peek byte/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
peek byte/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 S
peek char/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 save/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
peek code/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 save/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
peek code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 selectlist/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
profile data/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 set prolog flag/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
profiled reset/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 set value/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
public/1 (directive) . . . . . . . . . . . . . . . . . . . . . . . . . . 22 setarg/3n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
put attr/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 setenv/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
put attrs/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 sh/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
put byte/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 show op counters/1 . . . . . . . . . . . . . . . . . . . . . . . . . 153
put byte/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 show ops by group/1 . . . . . . . . . . . . . . . . . . . . . . . 153
put char/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 show table/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
put char/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 source/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
put code/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 source mode/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
put code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 splay access/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
putenv/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 splay delete/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
splay init/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
splay insert/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
R splay join/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
rannum/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 splay split/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
ranstart/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 spy write/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
ranstart/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 srandom/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
192 YAP Prolog User’s Manual
:-op(500,fx,[’+’,’-’]).
:-op(400,yfx,[’<<’,’>>’,’//’,’*’,’/’]).
:-op(300,xfx,mod).
:-op(200,xfy,[’^’,’**’]).
:-op(50,xfx,same).
Predicate Index 197
Predicate Index
! abolish/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
!/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 abolish_table/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
abort/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
absolute_file_name/2 . . . . . . . . . . . . . . . . . . . . . . . 42
, add_edges/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
,/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 add_to_array_element/4 . . . . . . . . . . . . . . . . . . . . 71
add_to_heap/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
add_to_path/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
- add_to_path/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
->/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 add_vertices/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
alarm/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
all/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
; always_prompt_user/0 . . . . . . . . . . . . . . . . . . . . . . . 52
append/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87, 109
;/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
arg/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
argv (yap_flag/2 option) . . . . . . . . . . . . . . . . . . . 73
< array/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
array_element/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
</2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
assert/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
assert/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
= assert_static/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
asserta/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
=../2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
asserta/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
asserta_static/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
=:=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
assertz/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
=</2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
assertz/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
==/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
assertz_static/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
=\=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
assoc_to_list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
at_end_of_stream/0 . . . . . . . . . . . . . . . . . . . . . . . . . 42
> at_end_of_stream/1 . . . . . . . . . . . . . . . . . . . . . . . . . 42
atom/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
>/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
atom_chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
>=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
atom_codes/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
atom_concat/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
@ atom_concat/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
atom_length/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
@</2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 atom_to_chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
@=</2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 atom_to_chars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
@>/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 atomic/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
@>=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 atomic_concat/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
attr_unify_hook/2 . . . . . . . . . . . . . . . . . . . . . . . . . 112
attribute/1 (declaration) . . . . . . . . . . . . . . . . 117
[ attribute_goal/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 119
[-]/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 attvar/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
[]/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 avl_insert/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
avl_lookup/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
\
\+/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 B
\=/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 b_getval/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
\==/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 b_setval/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
bagof/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
bb_delete/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
A bb_get/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
abolish/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 bb_put/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
198 YAP Prolog User’s Manual
bb_update/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 current_stream/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
between/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 current_thread/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 141
bounded (yap_flag/2 option) . . . . . . . . . . . . . . . . 74 cyclic_term/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
break/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
D
C datime/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
C/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 db_reference/1C . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
call/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 debug (yap_flag/2 option) . . . . . . . . . . . . . . . . . . 74
call_cleanup/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 debug/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
call_cleanup/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 debugging/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
call_count_data/0 . . . . . . . . . . . . . . . . . . . . . . . . . . 68 del_assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
call_count_data/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 68 del_attr/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
call_counting (yap_flag/2 option) . . . . . . . . . 74 del_edges/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
call_residue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 del_max_assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
call_with_args/n . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 del_min_assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
callable/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 del_vertices/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
catch/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 delete/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
cd/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 delete_file/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
char_code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 delete_file/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
char_conversion (yap_flag/2 option) . . . . . . . 74 dgraph_add_edges/3 . . . . . . . . . . . . . . . . . . . . . . . . 107
char_conversion/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 45 dgraph_add_vertices/3 . . . . . . . . . . . . . . . . . . . . 107
character_escapes (yap_flag/2 option) . . . . . 74 dgraph_complement/2 . . . . . . . . . . . . . . . . . . . . . . . 107
chdir/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 dgraph_compose/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 107
checklist/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 dgraph_del_edges/3 . . . . . . . . . . . . . . . . . . . . . . . . 107
checknodes/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 dgraph_del_vertices/3 . . . . . . . . . . . . . . . . . . . . 107
clause/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 dgraph_edges/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
clause/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 dgraph_neighbors/3 . . . . . . . . . . . . . . . . . . . . . . . . 107
cleanup_all/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 dgraph_neighbours/3 . . . . . . . . . . . . . . . . . . . . . . . 107
close/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 dgraph_new/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
close/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 dgraph_symmetric_closure/2 . . . . . . . . . . . . . . . 107
close_static_array/1 . . . . . . . . . . . . . . . . . . . . . . . 71 dgraph_top_sort/2 . . . . . . . . . . . . . . . . . . . . . . . . . 107
compare/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 dgraph_transitive_closure/2 . . . . . . . . . . . . . . 107
compile/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 dgraph_transpose/2 . . . . . . . . . . . . . . . . . . . . . . . . 107
compile_expressions/0 . . . . . . . . . . . . . . . . . . . . . 20 dgraph_vertices/2 . . . . . . . . . . . . . . . . . . . . . . . . . 107
complement/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 dif/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
compose/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 directory (prolog_load_context/2 option) . . 80
compound/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 directory_files/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 98
concat_atom/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 discontiguous/1 (directive) . . . . . . . . . . . . . . . 21
concat_atom/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 discontiguous_warnings (yap_flag/2 option)
consult/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74, 77
convlist/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 display/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45, 50
copy_term/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 display/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
copy_term_nat/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 do_not_compile_expressions/0 . . . . . . . . . . . . . . 20
cputime (statistics/2 option) . . . . . . . . . . . . . . 73 dollar_as_lower_case (yap_flag/2 option) . . 74
create_mutable/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 double_quotes (yap_flag/2 option) . . . . . . . . . 74
current_atom/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 dynamic/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
current_char_conversion/2 . . . . . . . . . . . . . . . . . 45 dynamic_predicate/2 . . . . . . . . . . . . . . . . . . . . . . . . 55
current_input/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
current_key/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
current_module/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 E
current_module/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 edges/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
current_mutex/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 empty_assoc/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
current_op/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 empty_heap/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
current_output/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 empty_queue/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
current_predicate/1 . . . . . . . . . . . . . . . . . . . . . . . . 57 ensure_loaded/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
current_predicate/2 . . . . . . . . . . . . . . . . . . . . . . . . 57 environ/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64, 99
current_prolog_flag/2 . . . . . . . . . . . . . . . . . . . . . 80 erase/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Predicate Index 199
eraseall/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 get_code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
erased/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 get_from_heap/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
exec/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 get_label/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
exists/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 get_mutable/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
expand_exprs/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 get_next_assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
expand_term/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 get_prev_assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
get_value/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
get0/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
F get0/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
fail/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 getcwd/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
false/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 getrand/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
fast (yap_flag/2 option) . . . . . . . . . . . . . . . . . . . 74 global_stack (statistics/2 option) . . . . . . . . 73
file (prolog_load_context/2 option) . . . . . . . 81 goal_expansion/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
file_exists/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 ground/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
file_exists/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 grow_stack/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
file_property/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
file_search_path/2 . . . . . . . . . . . . . . . . . . . . . . . . . 22
fileerrors (yap_flag/2 option). . . . . . . . . . . . . 75 H
fileerrors/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
halt/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
findall/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
halt/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
findall/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
flatten/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 head_queue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
float/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 heap (statistics/2 option) . . . . . . . . . . . . . . . . . 73
float_format (yap_flag/2 option) . . . . . . . . . . 75 heap_size/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
flush_output/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 heap_to_list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
flush_output/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 hide/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
forall/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 hide_predicate/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
format/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 host_id/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
format/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 host_name/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
format_to_chars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 96 host_type (yap_flag/2 option) . . . . . . . . . . . . . . 75
format_to_chars/4 . . . . . . . . . . . . . . . . . . . . . . . . . . 96
fragile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
freeze/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 I
frozen/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 if/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
functor/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 include/1 (directive) . . . . . . . . . . . . . . . . . . . . . . 19
incore/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
index (yap_flag/2 option) . . . . . . . . . . . . . . . . . . 75
G informational_messages (yap_flag/2 option)
garbage_collect/0 . . . . . . . . . . . . . . . . . . . . . . . . . . 30 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
garbage_collect_atoms/0 . . . . . . . . . . . . . . . . . . . 30 initialization/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
garbage_collection (statistics/2 option) . . 73 initialization/1 (directive) . . . . . . . . . . . . . . 21
gc (yap_flag/2 option) . . . . . . . . . . . . . . . . . . . . . 75 instance/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
gc/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 integer/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
gc_margin (yap_flag/2 option) . . . . . . . . . . . . . . 75 integer_rounding_function (yap_flag/2
gc_trace (yap_flag/2 option) . . . . . . . . . . . . . . . 75 option) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
gen_assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 is/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
get/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 is_assoc/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
get/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 is_list/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
get_assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 is_mutable/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
get_assoc/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 is_rbtree/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
get_attr/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
is_tabled/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
get_attrs/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
get_atts/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
get_byte/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 J
get_byte/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
get_char/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 join_queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
get_char/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 jump_queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
get_code/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
200 YAP Prolog User’s Manual
K module/3 (directive) . . . . . . . . . . . . . . . . . . . . . . . 24
key_statistics/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 multifile/1 (directive) . . . . . . . . . . . . . . . . . . . . 21
key_statistics/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 mutex_create/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
keysort/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 mutex_destroy/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
kill/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 mutex_lock/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
mutex_statistics/0 . . . . . . . . . . . . . . . . . . . . . . . . 141
mutex_trylock/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
L mutex_unlock/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
language (yap_flag/2 option) . . . . . . . . . . . . . . . 75 mutex_unlock_all/0 . . . . . . . . . . . . . . . . . . . . . . . . 146
last/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
leash/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
length/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
N
length_queue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 n_of_integer_keys_in_bb (yap_flag/2 option)
library_directory/1 . . . . . . . . . . . . . . . . . . . . 21, 22 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
list_concat/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 n_of_integer_keys_in_db (yap_flag/2 option)
list_join_queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 91 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
list_jump_queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 91 name/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
list_to_assoc/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 nb_current/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
list_to_heap/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 nb_delete/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
list_to_ord_set/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 89 nb_getval/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
list_to_queue/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 nb_setval/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
list_to_rbtree/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 neighbors/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
list_to_tree/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 neighbours/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
listing/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 nl/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
listing/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 nl/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
local_stack (statistics/2 option) . . . . . . . . . 73 no_source/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
no_style_check/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
nodebug/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
M nofileerrors/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
make_directory/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 nogc/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
make_queue/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 nonvar/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
map_assoc/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 nospy/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
map_assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 nospyall/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
map_tree/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 not/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
mapargs/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 nth/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
maplist/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 nth/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
maplist/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83, 110 nth_clause/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
maplist/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 nth_recorded/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
mapnodes/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 nth0/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
max_arity (yap_flag/2 option) . . . . . . . . . . . . . . 76 nth0/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
max_assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 nth1/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
max_integer (yap_flag/2 option) . . . . . . . . . . . 76 number/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
max_list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 number_atom/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
max_tagged_integer (yap_flag/2 option) . . . . 76 number_chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
member/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 number_codes/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
memberchk/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 number_to_chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 97
merge/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 number_to_chars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 97
meta_predicate/1 (directive) . . . . . . . . . . . . . . 25 numbervars/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
min_assoc/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
min_integer (yap_flag/2 option) . . . . . . . . . . . 76
min_list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 O
min_of_heap/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 on_cleanup/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
min_of_heap/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 on_signal/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
mktemp/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 once/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
mktime/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 op/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
module (prolog_load_context/2 option) . . . . . 81 open/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
module/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 open/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
module/2 (directive) . . . . . . . . . . . . . . . . . . . . . . . 24 open_chars_stream/2 . . . . . . . . . . . . . . . . . . . . . . . . 97
Predicate Index 201
ord_add_element/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 89 put_char/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
ord_del_element/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 89 put_code/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
ord_disjoint/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 put_code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
ord_insert/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 put_label/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
ord_intersect/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 putenv/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
ord_intersect/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
ord_intersect/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
ord_list_to_assoc/2 . . . . . . . . . . . . . . . . . . . . . . . . 85 Q
ord_member/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 queue_to_list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
ord_seteq/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
ord_setproduct/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
ord_subtract/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 R
ord_symdiff/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 random/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
ord_union/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 random/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
ord_union/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 randseq/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
ord_union/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 randset/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
ordsubset/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 rannum/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
ranstart/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
ranstart/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
P ranunif/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
path/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 rb_apply/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
peek_byte/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 rb_clone/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
peek_byte/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 rb_del_max/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
peek_char/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 rb_del_min/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
peek_char/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 rb_delete/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
peek_code/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 rb_delete/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
peek_code/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 rb_empty/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
permutation/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 rb_insert/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
phrase/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 rb_keys/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
phrase/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 rb_lookup/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
pid/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 rb_lookupall/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
popen/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 rb_map/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
portray_clause/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 rb_max/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
portray_clause/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 rb_min/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
predicate_property/2 . . . . . . . . . . . . . . . . . . . . . . . 57 rb_new/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
primitive/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 rb_next/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
print/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 rb_partial_map/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
print/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 rb_previous/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
profile_data/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 rb_size/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
profiled_reset/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 rb_update/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
profiling (yap_flag/2 option) . . . . . . . . . . . . . . 76 rb_visit/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
program (statistics/2 option) . . . . . . . . . . . . . . 73 reachable/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
project_attributes/2. . . . . . . . . . . . . . . . . . . . . . 119 read/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
prolog_file_name/2 . . . . . . . . . . . . . . . . . . . . . . . . . 22 read/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
prolog_flag/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 read_from_chars/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 97
prolog_initialization/1 . . . . . . . . . . . . . . . . . . . 80 read_term/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
prolog_load_context/2 . . . . . . . . . . . . . . . . . . . . . 80 read_term/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
prompt/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 reconsult/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
public/1 (directive) . . . . . . . . . . . . . . . . . . . . . . . 22 recorda/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58, 59
put/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 recorda_at/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
put/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 recordaifnot/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 59, 60
put_assoc/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 recorded/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
put_attr/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 recordz/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
put_attrs/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 recordz_at/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
put_atts/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 recordzifnot/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
put_byte/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 regexp/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
put_byte/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 regexp/4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
put_char/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 remove_duplicates/2 . . . . . . . . . . . . . . . . . . . . . . . . 88
202 YAP Prolog User’s Manual
remove_from_path/1 . . . . . . . . . . . . . . . . . . . . . . . . . 21 source/0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
rename/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 source_mode/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
rename_file/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 splay_access/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
repeat/0. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 splay_delete/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
reset_op_counters/0 . . . . . . . . . . . . . . . . . . . . . . . 153 splay_init/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
resize_static_array/3 . . . . . . . . . . . . . . . . . . . . . 71 splay_insert/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
restore/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 splay_join/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
retract/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 splay_split/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
retract/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 spy/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
retractall/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 spy_write/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
reverse/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 srandom/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
runtime (statistics/2 option) . . . . . . . . . . . . . . 73 stack_dump_on_error (yap_flag/2 option) . . . 77
stack_shifts (stack_shifts/3 option) . . . . . . 73
start_low_level_trace/0 . . . . . . . . . . . . . . . . . . 151
S static_array/3 . . . . . . . . . . . . . . . . . . . . . . . . . . 70, 71
same_length/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 static_array_location/4 . . . . . . . . . . . . . . . . . . . 70
save/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 static_array_properties/3 . . . . . . . . . . . . . . . . . 70
save/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 static_array_to_term/3 . . . . . . . . . . . . . . . . . . . . 70
save_program/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 statistics/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
save_program/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 statistics/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
see/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 stream_property/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 42
seeing/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 stream_select/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
seen/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 strict_iso (prolog_flag/2 option) . . . . . . . . . 77
select/3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 style_check/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
selectlist/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 sub_atom/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
serve_queue/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 sublist/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
set_input/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 subsumes/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
set_output/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 subsumes_chk/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
set_prolog_flag/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 80 suffix/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
set_stream_position/2 . . . . . . . . . . . . . . . . . . . . . 42 sum_list/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
set_value/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60 sumargs/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
setarg/3n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 sumlist/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
setenv/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 sumlist/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
setof/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 sumnodes/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
setrand/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 syntax_errors (yap_flag/2 option) . . . . . . . . . 77
sh/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 syntax_errors/1 (read_term/2 option) . . . . . . 44
shell/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 system/0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
shell/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100, 101 system/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
show_op_counters/1 . . . . . . . . . . . . . . . . . . . . . . . . 153 system/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
show_ops_by_group/1 . . . . . . . . . . . . . . . . . . . . . . . 153 system_options (yap_flag/2 option) . . . . . . . . 78
show_table/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 system_predicate/2 . . . . . . . . . . . . . . . . . . . . . . . . . 57
simple/1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
single_var_warnings (yap_flag/2 option) . . . 77
singletons/1 (read_term/2 option) . . . . . . . . . 44 T
skip/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 tab/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
skip/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 tab/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
sleep/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 table_statistics/1 . . . . . . . . . . . . . . . . . . . . . . . . 149
socket/2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 tell/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
socket/4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 telling/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
socket_accept/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 term_expansion/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
socket_accept/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 term_hash/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
socket_bind/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 term_hash/4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
socket_buffering/4 . . . . . . . . . . . . . . . . . . . . . . . . . 54 term_to_atom/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
socket_close/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 term_variables/2 . . . . . . . . . . . . . . . . . . . . . . . . . . 101
socket_connect/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 thread_at_exit/1 . . . . . . . . . . . . . . . . . . . . . . . . . . 140
socket_listen/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 thread_create/3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
socket_select/5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 thread_detach/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
sort/2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 thread_exit/1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Predicate Index 203
Concept Index
A mutable variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
anonymous variable . . . . . . . . . . . . . . . . . . . . . . . . . . 17
association list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
atom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
N
attribute declaration . . . . . . . . . . . . . . . . . . . . . . . . 117 number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
attributed variables . . . . . . . . . . . . . . . . . . . . . . . . . 117
AVL trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 O
Operating System Utilities . . . . . . . . . . . . . . . . . . . 98
B or-parallelism. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
booting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 ordered set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
C P
parallelism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
cleanup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
profiling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
CLPQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
pseudo random . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
CLPR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
punctuation token . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
comment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Counting Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Q
D queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90, 91
declaration, attribute . . . . . . . . . . . . . . . . . . . . . . . 117
R
E Red-Black Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
regular expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Efficient Directed Graphs. . . . . . . . . . . . . . . . . . . . 106
end of term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
environment variables . . . . . . . . . . . . . . . . . . . . . . . . . 9 S
splay trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
F string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
floating-point number . . . . . . . . . . . . . . . . . . . . . . . . 15 string I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
SWI-Prolog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3, 13
H
heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 T
hProlog Attributed Variables . . . . . . . . . . . . . . . . 110
tabling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
timeout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
I token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
integer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 U
undrected graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
unweighted graphs . . . . . . . . . . . . . . . . . . . . . . . . . . 103
L updatable tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
list manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 update semantics . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Logtalk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 updating terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
utilities on terms . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
M
machine optimizations . . . . . . . . . . . . . . . . . . . . . . . . 4 V
macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
206 YAP Prolog User’s Manual