This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
YAProlog/YAP Prolog User’s Manual.html

28503 lines
1.8 MiB
Raw Permalink Blame History

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created on October 18, 2010 by texi2html 5.0
texi2html was written by:
Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>YAP Prolog User&rsquo;s Manual</title>
<meta name="description" content="YAP Prolog User&rsquo;s Manual">
<meta name="keywords" content="YAP Prolog User&rsquo;s Manual">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 5.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:pre}
span.nolinebreak {white-space:pre}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<h1>YAP User&rsquo;s Manual</h1>
<h3 align="right">Version 6.2.0</h3>
<strong>V&iacute;tor Santos Costa,</strong><br>
<strong>Lu&iacute;s Damas,</strong><br>
<strong>Rog&eacute;rio Reis, and</strong><br>
<strong>R&uacute;ben Azevedo</strong><br>
<p>Copyright &copy; 1989-2000 L. Damas, V. Santos Costa and Universidade
do Porto.
</p>
<p>Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
</p>
<p>Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
</p>
<p>Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions.
</p>
<hr>
<a name="SEC_Contents"></a>
<h1>Table of Contents</h1>
<div class="contents">
<ul class="no-bullet">
<li><a name="toc-Introduction" href="#Intro">Introduction</a></li>
<li><a name="toc-Installing-YAP" href="#Install">1 Installing YAP</a>
<ul class="no-bullet">
<li><a name="toc-Tuning-the-Functionality-of-YAP" href="#Configuration-Options">1.1 Tuning the Functionality of YAP</a></li>
<li><a name="toc-Tuning-YAP-for-a-Particular-Machine-and-Compiler" href="#Machine-Options">1.2 Tuning YAP for a Particular Machine and Compiler</a></li>
<li><a name="toc-Tuning-YAP-for-GCC_002e" href="#Tuning-for-GCC">1.3 Tuning YAP for <code>GCC</code>.</a>
<ul class="no-bullet">
<li><a name="toc-Compiling-Under-Visual-C_002b_002b-1" href="#Compiling-Under-Visual-C_002b_002b">1.3.1 Compiling Under Visual C++</a></li>
<li><a name="toc-Compiling-Under-SGI_0027s-cc" href="#Tuning-for-SGI-cc">1.3.2 Compiling Under SGI&rsquo;s cc</a></li>
</ul>
</li>
</ul></li>
<li><a name="toc-Running-YAP" href="#Run">2 Running YAP</a>
<ul class="no-bullet">
<li><a name="toc-Running-YAP-Interactively-1" href="#Running-YAP-Interactively">2.1 Running YAP Interactively</a></li>
<li><a name="toc-Running-Prolog-Files-1" href="#Running-Prolog-Files">2.2 Running Prolog Files</a></li>
</ul></li>
<li><a name="toc-Syntax-1" href="#Syntax">3 Syntax</a>
<ul class="no-bullet">
<li><a name="toc-Syntax-of-Terms" href="#Formal-Syntax">3.1 Syntax of Terms</a></li>
<li><a name="toc-Prolog-Tokens" href="#Tokens">3.2 Prolog Tokens</a>
<ul class="no-bullet">
<li><a name="toc-Numbers-1" href="#Numbers">3.2.1 Numbers</a>
<ul class="no-bullet">
<li><a name="toc-Integers-1" href="#Integers">3.2.1.1 Integers</a></li>
<li><a name="toc-Floating_002dpoint-Numbers" href="#Floats">3.2.1.2 Floating-point Numbers</a></li>
</ul></li>
<li><a name="toc-Character-Strings" href="#Strings">3.2.2 Character Strings</a></li>
<li><a name="toc-Atoms-1" href="#Atoms">3.2.3 Atoms</a></li>
<li><a name="toc-Variables-1" href="#Variables">3.2.4 Variables</a></li>
<li><a name="toc-Punctuation-Tokens-1" href="#Punctuation-Tokens">3.2.5 Punctuation Tokens</a></li>
<li><a name="toc-Layout-1" href="#Layout">3.2.6 Layout</a></li>
</ul></li>
<li><a name="toc-Wide-Character-Support" href="#Encoding">3.3 Wide Character Support</a>
<ul class="no-bullet">
<li><a name="toc-Wide-character-encodings-on-streams" href="#Stream-Encoding">3.3.1 Wide character encodings on streams</a></li>
<li><a name="toc-BOM_003a-Byte-Order-Mark" href="#BOM">3.3.2 BOM: Byte Order Mark</a></li>
</ul>
</li>
</ul></li>
<li><a name="toc-Loading-Programs-1" href="#Loading-Programs">4 Loading Programs</a>
<ul class="no-bullet">
<li><a name="toc-Program-loading-and-updating" href="#Compiling">4.1 Program loading and updating</a></li>
<li><a name="toc-Changing-the-Compiler_0027s-Behavior" href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></li>
<li><a name="toc-Conditional-Compilation-1" href="#Conditional-Compilation">4.3 Conditional Compilation</a></li>
<li><a name="toc-Saving-and-Loading-Prolog-States" href="#Saving">4.4 Saving and Loading Prolog States</a></li>
</ul></li>
<li><a name="toc-The-Module-System" href="#Modules">5 The Module System</a>
<ul class="no-bullet">
<li><a name="toc-Module-Concepts-1" href="#Module-Concepts">5.1 Module Concepts</a></li>
<li><a name="toc-Defining-a-New-Module" href="#Defining-Modules">5.2 Defining a New Module</a></li>
<li><a name="toc-Using-Modules-1" href="#Using-Modules">5.3 Using Modules</a></li>
<li><a name="toc-Meta_002dPredicates-in-Modules-1" href="#Meta_002dPredicates-in-Modules">5.4 Meta-Predicates in Modules</a></li>
<li><a name="toc-Re_002dExporting-Predicates-From-Other-Modules" href="#Re_002dExporting-Modules">5.5 Re-Exporting Predicates From Other Modules</a></li>
</ul></li>
<li><a name="toc-Built_002dIn-Predicates" href="#Built_002dins">6 Built-In Predicates</a>
<ul class="no-bullet">
<li><a name="toc-Control-Predicates" href="#Control">6.1 Control Predicates</a></li>
<li><a name="toc-Handling-Undefined-Procedures" href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></li>
<li><a name="toc-Message-Handling" href="#Messages">6.3 Message Handling</a></li>
<li><a name="toc-Predicates-on-terms" href="#Testing-Terms">6.4 Predicates on terms</a></li>
<li><a name="toc-Predicates-on-Atoms-1" href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></li>
<li><a name="toc-Predicates-on-Characters-1" href="#Predicates-on-Characters">6.6 Predicates on Characters</a></li>
<li><a name="toc-Comparing-Terms-1" href="#Comparing-Terms">6.7 Comparing Terms</a></li>
<li><a name="toc-Arithmetic-1" href="#Arithmetic">6.8 Arithmetic</a></li>
<li><a name="toc-I_002fO-Predicates" href="#I_002fO">6.9 I/O Predicates</a>
<ul class="no-bullet">
<li><a name="toc-Handling-Streams-and-Files-1" href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></li>
<li><a name="toc-Handling-Streams-and-Files" href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></li>
<li><a name="toc-Handling-Input_002fOutput-of-Terms" href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></li>
<li><a name="toc-Handling-Input_002fOutput-of-Characters" href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></li>
<li><a name="toc-Input_002fOutput-Predicates-applied-to-Streams" href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></li>
<li><a name="toc-Compatible-C_002dProlog-predicates-for-Terminal-I_002fO" href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></li>
<li><a name="toc-Controlling-Input_002fOutput" href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></li>
<li><a name="toc-Using-Sockets-From-YAP" href="#Sockets">6.9.8 Using Sockets From YAP</a></li>
</ul></li>
<li><a name="toc-Using-the-Clausal-Data-Base" href="#Database">6.10 Using the Clausal Data Base</a>
<ul class="no-bullet">
<li><a name="toc-Modification-of-the-Data-Base" href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></li>
<li><a name="toc-Looking-at-the-Data-Base" href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></li>
<li><a name="toc-Using-Data-Base-References" href="#Database-References">6.10.3 Using Data Base References</a></li>
</ul></li>
<li><a name="toc-Internal-Data-Base" href="#Internal-Database">6.11 Internal Data Base</a></li>
<li><a name="toc-The-Blackboard" href="#BlackBoard">6.12 The Blackboard</a></li>
<li><a name="toc-Collecting-Solutions-to-a-Goal" href="#Sets">6.13 Collecting Solutions to a Goal</a></li>
<li><a name="toc-Grammar-Rules" href="#Grammars">6.14 Grammar Rules</a></li>
<li><a name="toc-Access-to-Operating-System-Functionality" href="#OS">6.15 Access to Operating System Functionality</a></li>
<li><a name="toc-Term-Modification-1" href="#Term-Modification">6.16 Term Modification</a></li>
<li><a name="toc-Global-Variables-1" href="#Global-Variables">6.17 Global Variables</a></li>
<li><a name="toc-Profiling-Prolog-Programs" href="#Profiling">6.18 Profiling Prolog Programs</a>
<ul class="no-bullet">
<li><a name="toc-The-Count-Profiler" href="#The-Count-Profiler">6.18.1 The Count Profiler</a></li>
<li><a name="toc-Tick-Profiler" href="#Tick-Profiler">6.18.2 Tick Profiler</a></li>
</ul></li>
<li><a name="toc-Counting-Calls" href="#Call-Counting">6.19 Counting Calls</a></li>
<li><a name="toc-Arrays-1" href="#Arrays">6.20 Arrays</a></li>
<li><a name="toc-Predicate-Information" href="#Preds">6.21 Predicate Information</a></li>
<li><a name="toc-Miscellaneous" href="#Misc">6.22 Miscellaneous</a></li>
</ul></li>
<li><a name="toc-Library-Predicates" href="#Library">7 Library Predicates</a>
<ul class="no-bullet">
<li><a name="toc-Aggregate-1" href="#Aggregate">7.1 Aggregate</a></li>
<li><a name="toc-Apply-Macros" href="#Apply">7.2 Apply Macros</a></li>
<li><a name="toc-Association-Lists-1" href="#Association-Lists">7.3 Association Lists</a></li>
<li><a name="toc-AVL-Trees-1" href="#AVL-Trees">7.4 AVL Trees</a></li>
<li><a name="toc-Heaps-1" href="#Heaps">7.5 Heaps</a></li>
<li><a name="toc-List-Manipulation" href="#Lists">7.6 List Manipulation</a></li>
<li><a name="toc-Line-Manipulation-Utilities" href="#LineUtilities">7.7 Line Manipulation Utilities</a></li>
<li><a name="toc-Maplist" href="#MapList">7.8 Maplist</a></li>
<li><a name="toc-Matrix-Library" href="#matrix">7.9 Matrix Library</a></li>
<li><a name="toc-MATLAB-Package-Interface" href="#MATLAB">7.10 MATLAB Package Interface</a></li>
<li><a name="toc-Non_002dBacktrackable-Data-Structures-1" href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></li>
<li><a name="toc-Ordered-Sets-1" href="#Ordered-Sets">7.12 Ordered Sets</a></li>
<li><a name="toc-Pseudo-Random-Number-Integer-Generator" href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></li>
<li><a name="toc-Queues-1" href="#Queues">7.14 Queues</a></li>
<li><a name="toc-Random-Number-Generator" href="#Random">7.15 Random Number Generator</a></li>
<li><a name="toc-Read-Utilities-1" href="#Read-Utilities">7.16 Read Utilities</a></li>
<li><a name="toc-Red_002dBlack-Trees-1" href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></li>
<li><a name="toc-Regular-Expressions" href="#RegExp">7.18 Regular Expressions</a></li>
<li><a name="toc-SWI_002dProlog_0027s-shlib-library" href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></li>
<li><a name="toc-Splay-Trees-1" href="#Splay-Trees">7.20 Splay Trees</a></li>
<li><a name="toc-Reading-From-and-Writing-To-Strings" href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></li>
<li><a name="toc-Calling-The-Operating-System-from-YAP" href="#System">7.22 Calling The Operating System from YAP</a></li>
<li><a name="toc-Utilities-On-Terms" href="#Terms">7.23 Utilities On Terms</a></li>
<li><a name="toc-Trie-DataStructure" href="#Tries">7.24 Trie DataStructure</a></li>
<li><a name="toc-Call-Cleanup" href="#Cleanup">7.25 Call Cleanup</a></li>
<li><a name="toc-Calls-With-Timeout" href="#Timeout">7.26 Calls With Timeout</a></li>
<li><a name="toc-Updatable-Binary-Trees" href="#Trees">7.27 Updatable Binary Trees</a></li>
<li><a name="toc-Unweighted-Graphs" href="#UGraphs">7.28 Unweighted Graphs</a></li>
<li><a name="toc-Directed-Graphs" href="#DGraphs">7.29 Directed Graphs</a></li>
<li><a name="toc-Undirected-Graphs" href="#UnDGraphs">7.30 Undirected Graphs</a></li>
<li><a name="toc-Lambda-Expressions" href="#Lambda">7.31 Lambda Expressions</a></li>
<li><a name="toc-LAM-1" href="#LAM">7.32 LAM</a></li>
</ul></li>
<li><a name="toc-SWI_002dProlog-Emulation" href="#SWI_002dProlog">8 SWI-Prolog Emulation</a>
<ul class="no-bullet">
<li><a name="toc-Invoking-Predicates-on-all-Members-of-a-List-1" href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></li>
<li><a name="toc-Forall-1" href="#Forall">8.2 Forall</a></li>
</ul></li>
<li><a name="toc-SWI-Global-variables" href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a>
<ul class="no-bullet">
<li><a name="toc-Compatibility-of-Global-Variables" href="#Compatibility-of-Global-Variables">9.1 Compatibility of Global Variables</a></li>
</ul></li>
<li><a name="toc-Extensions-to-Prolog" href="#Extensions">10 Extensions to Prolog</a>
<ul class="no-bullet">
<li><a name="toc-Rational-Trees-1" href="#Rational-Trees">10.1 Rational Trees</a></li>
<li><a name="toc-Co_002droutining-1" href="#Co_002droutining">10.2 Co-routining</a></li>
</ul></li>
<li><a name="toc-Attributed-Variables-1" href="#Attributed-Variables">11 Attributed Variables</a>
<ul class="no-bullet">
<li><a name="toc-hProlog-and-SWI_002dProlog-style-Attribute-Declarations" href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></li>
<li><a name="toc-SICStus-Prolog-style-Attribute-Declarations" href="#Old-Style-Attribute-Declarations">11.2 SICStus Prolog style Attribute Declarations</a>
<ul class="no-bullet">
<li><a name="toc-Attribute-Declarations-1" href="#Attribute-Declarations">11.2.1 Attribute Declarations</a></li>
<li><a name="toc-Attribute-Manipulation-1" href="#Attribute-Manipulation">11.2.2 Attribute Manipulation</a></li>
<li><a name="toc-Attributed-Unification-1" href="#Attributed-Unification">11.2.3 Attributed Unification</a></li>
<li><a name="toc-Displaying-Attributes-1" href="#Displaying-Attributes">11.2.4 Displaying Attributes</a></li>
<li><a name="toc-Projecting-Attributes-1" href="#Projecting-Attributes">11.2.5 Projecting Attributes</a></li>
<li><a name="toc-Attribute-Examples-1" href="#Attribute-Examples">11.2.6 Attribute Examples</a></li>
</ul>
</li>
</ul></li>
<li><a name="toc-Constraint-Logic-Programming-over-Reals" href="#CLPR">12 Constraint Logic Programming over Reals</a>
<ul class="no-bullet">
<li><a name="toc-Solver-Predicates" href="#CLPR-Solver-Predicates">12.1 Solver Predicates</a></li>
<li><a name="toc-Syntax-of-the-predicate-arguments" href="#CLPR-Syntax">12.2 Syntax of the predicate arguments</a></li>
<li><a name="toc-Use-of-unification" href="#CLPR-Unification">12.3 Use of unification</a></li>
<li><a name="toc-Non_002dLinear-Constraints" href="#CLPR-Non_002dlinear-Constraints">12.4 Non-Linear Constraints</a></li>
</ul></li>
<li><a name="toc-CHR_003a-Constraint-Handling-Rules" href="#CHR">13 CHR: Constraint Handling Rules</a>
<ul class="no-bullet">
<li><a name="toc-Introduction-1" href="#CHR-Introduction">13.1 Introduction</a></li>
<li><a name="toc-Syntax-and-Semantics" href="#CHR-Syntax-and-Semantics">13.2 Syntax and Semantics</a>
<ul class="no-bullet">
<li><a name="toc-Syntax-2" href="#Syntax-2">13.2.1 Syntax</a></li>
<li><a name="toc-Semantics" href="#Semantics">13.2.2 Semantics</a>
<ul class="no-bullet">
<li><a name="toc-Rule-Types" href="#Rule-Types">Rule Types</a></li>
<li><a name="toc-Rule-Names" href="#Rule-Names">Rule Names</a></li>
<li><a name="toc-Pragmas" href="#Pragmas">Pragmas</a></li>
<li><a name="toc-Options" href="#Options">Options</a></li>
</ul>
</li>
</ul></li>
<li><a name="toc-CHR-in-YAP-Programs-1" href="#CHR-in-YAP-Programs">13.3 CHR in YAP Programs</a>
<ul class="no-bullet">
<li><a name="toc-Embedding-in-Prolog-Programs" href="#Embedding-in-Prolog-Programs">13.3.1 Embedding in Prolog Programs</a></li>
<li><a name="toc-Constraint-declaration" href="#Constraint-declaration">13.3.2 Constraint declaration</a></li>
<li><a name="toc-Compilation" href="#Compilation">13.3.3 Compilation</a></li>
</ul></li>
<li><a name="toc-Debugging-2" href="#CHR-Debugging">13.4 Debugging</a>
<ul class="no-bullet">
<li><a name="toc-Ports" href="#Ports">13.4.1 Ports</a></li>
<li><a name="toc-Tracing" href="#Tracing">13.4.2 Tracing</a></li>
<li><a name="toc-CHR-Debugging-Predicates" href="#CHR-Debugging-Predicates">13.4.3 CHR Debugging Predicates</a></li>
</ul></li>
<li><a name="toc-Examples" href="#CHR-Examples">13.5 Examples</a></li>
<li><a name="toc-Compatibility-with-SICStus-CHR" href="#CHR-Compatibility">13.6 Compatibility with SICStus CHR</a></li>
<li><a name="toc-Guidelines" href="#CHR-Guidelines">13.7 Guidelines</a></li>
</ul></li>
<li><a name="toc-Logtalk-1" href="#Logtalk">14 Logtalk</a></li>
<li><a name="toc-MYDDAS-1" href="#MYDDAS">15 MYDDAS</a>
<ul class="no-bullet">
<li><a name="toc-Requirements-and-Installation-Guide-1" href="#Requirements-and-Installation-Guide">15.1 Requirements and Installation Guide</a></li>
<li><a name="toc-MYDDAS-Architecture-1" href="#MYDDAS-Architecture">15.2 MYDDAS Architecture</a></li>
<li><a name="toc-Loading-MYDDAS-1" href="#Loading-MYDDAS">15.3 Loading MYDDAS</a></li>
<li><a name="toc-Connecting-to-and-disconnecting-from-a-Database-Server-1" href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></li>
<li><a name="toc-Accessing-a-Relation-1" href="#Accessing-a-Relation">15.5 Accessing a Relation</a></li>
<li><a name="toc-View-Level-Interface-1" href="#View-Level-Interface">15.6 View Level Interface</a></li>
<li><a name="toc-Accessing-Tables-in-Data-Sources-Using-SQL-1" href="#Accessing-Tables-in-Data-Sources-Using-SQL">15.7 Accessing Tables in Data Sources Using SQL</a></li>
<li><a name="toc-Insertion-of-Rows-1" href="#Insertion-of-Rows">15.8 Insertion of Rows</a></li>
<li><a name="toc-Types-of-Attributes-1" href="#Types-of-Attributes">15.9 Types of Attributes</a></li>
<li><a name="toc-Number-of-Fields-1" href="#Number-of-Fields">15.10 Number of Fields</a></li>
<li><a name="toc-Describing-a-Relation-1" href="#Describing-a-Relation">15.11 Describing a Relation</a></li>
<li><a name="toc-Enumeration-Relations" href="#Enumerating-Relations">15.12 Enumeration Relations</a></li>
<li><a name="toc-The-MYDDAS-MySQL-Top-Level-1" href="#The-MYDDAS-MySQL-Top-Level">15.13 The MYDDAS MySQL Top Level</a></li>
<li><a name="toc-Other-MYDDAS-Properties-1" href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></li>
</ul></li>
<li><a name="toc-Threads-1" href="#Threads">16 Threads</a>
<ul class="no-bullet">
<li><a name="toc-Creating-and-Destroying-Prolog-Threads-1" href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></li>
<li><a name="toc-Monitoring-Threads-1" href="#Monitoring-Threads">16.2 Monitoring Threads</a></li>
<li><a name="toc-Thread-communication" href="#Thread-Communication">16.3 Thread communication</a>
<ul class="no-bullet">
<li><a name="toc-Message-Queues-1" href="#Message-Queues">16.3.1 Message Queues</a></li>
<li><a name="toc-Signalling-Threads-1" href="#Signalling-Threads">16.3.2 Signalling Threads</a></li>
<li><a name="toc-Threads-and-Dynamic-Predicates-1" href="#Threads-and-Dynamic-Predicates">16.3.3 Threads and Dynamic Predicates</a></li>
</ul></li>
<li><a name="toc-Thread-Synchronisation-1" href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></li>
</ul></li>
<li><a name="toc-Parallelism-1" href="#Parallelism">17 Parallelism</a></li>
<li><a name="toc-Tabling-1" href="#Tabling">18 Tabling</a></li>
<li><a name="toc-Tracing-at-Low-Level" href="#Low-Level-Tracing">19 Tracing at Low Level</a></li>
<li><a name="toc-Profiling-the-Abstract-Machine" href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></li>
<li><a name="toc-Debugging-1" href="#Debugging">21 Debugging</a>
<ul class="no-bullet">
<li><a name="toc-Debugging-Predicates" href="#Deb-Preds">21.1 Debugging Predicates</a></li>
<li><a name="toc-Interacting-with-the-debugger" href="#Deb-Interaction">21.2 Interacting with the debugger</a></li>
</ul></li>
<li><a name="toc-Efficiency-Considerations" href="#Efficiency">22 Efficiency Considerations</a>
<ul class="no-bullet">
<li><a name="toc-Deterministic-Programs" href="#Deterministic-Programs">22.1 Deterministic Programs</a></li>
<li><a name="toc-Non_002dDeterministic-Programs" href="#Non_002dDeterministic-Programs">22.2 Non-Deterministic Programs</a></li>
<li><a name="toc-Data_002dBase-Operations" href="#Data_002dBase-Operations">22.3 Data-Base Operations</a></li>
<li><a name="toc-Indexing" href="#Indexing">22.4 Indexing</a></li>
<li><a name="toc-Profiling-1" href="#Profiling-1">22.5 Profiling</a></li>
</ul></li>
<li><a name="toc-C-Language-interface-to-YAP" href="#C_002dInterface">23 C Language interface to YAP</a>
<ul class="no-bullet">
<li><a name="toc-Terms-1" href="#Manipulating-Terms">23.1 Terms</a></li>
<li><a name="toc-Unification" href="#Unifying-Terms">23.2 Unification</a></li>
<li><a name="toc-Strings-1" href="#Manipulating-Strings">23.3 Strings</a></li>
<li><a name="toc-Memory-Allocation-1" href="#Memory-Allocation">23.4 Memory Allocation</a></li>
<li><a name="toc-Controlling-YAP-Streams-from-C" href="#Controlling-Streams">23.5 Controlling YAP Streams from <code>C</code></a></li>
<li><a name="toc-Utility-Functions-in-C" href="#Utility-Functions">23.6 Utility Functions in <code>C</code></a></li>
<li><a name="toc-From-C-back-to-Prolog" href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></li>
<li><a name="toc-Module-Manipulation-in-C-1" href="#Module-Manipulation-in-C">23.8 Module Manipulation in C</a></li>
<li><a name="toc-Miscellaneous-C-Functions" href="#Miscellaneous-C_002dFunctions">23.9 Miscellaneous C Functions</a></li>
<li><a name="toc-Writing-predicates-in-C" href="#Writing-C">23.10 Writing predicates in C</a></li>
<li><a name="toc-Loading-Object-Files" href="#Loading-Objects">23.11 Loading Object Files</a></li>
<li><a name="toc-Saving-and-Restoring" href="#Save_0026Rest">23.12 Saving and Restoring</a></li>
<li><a name="toc-Changes-to-the-C_002dInterface-in-YAP4" href="#YAP4-Notes">23.13 Changes to the C-Interface in YAP4</a></li>
</ul></li>
<li><a name="toc-Using-YAP-as-a-Library" href="#YAPLibrary">24 Using YAP as a Library</a></li>
<li><a name="toc-Compatibility-with-Other-Prolog-systems" href="#Compatibility">25 Compatibility with Other Prolog systems</a>
<ul class="no-bullet">
<li><a name="toc-Compatibility-with-the-C_002dProlog-interpreter" href="#C_002dProlog">25.1 Compatibility with the C-Prolog interpreter</a>
<ul class="no-bullet">
<li><a name="toc-Major-Differences-between-YAP-and-C_002dProlog_002e" href="#Major-Differences-with-C_002dProlog">25.1.1 Major Differences between YAP and C-Prolog.</a></li>
<li><a name="toc-YAP-predicates-fully-compatible-with-C_002dProlog" href="#Fully-C_002dProlog-Compatible">25.1.2 YAP predicates fully compatible with C-Prolog</a></li>
<li><a name="toc-YAP-predicates-not-strictly-compatible-with-C_002dProlog" href="#Not-Strictly-C_002dProlog-Compatible">25.1.3 YAP predicates not strictly compatible with C-Prolog</a></li>
<li><a name="toc-YAP-predicates-not-available-in-C_002dProlog" href="#Not-in-C_002dProlog">25.1.4 YAP predicates not available in C-Prolog</a></li>
<li><a name="toc-YAP-predicates-not-available-in-C_002dProlog-1" href="#Not-in-YAP">25.1.5 YAP predicates not available in C-Prolog</a></li>
</ul></li>
<li><a name="toc-Compatibility-with-the-Quintus-and-SICStus-Prolog-systems" href="#SICStus-Prolog">25.2 Compatibility with the Quintus and SICStus Prolog systems</a>
<ul class="no-bullet">
<li><a name="toc-Major-Differences-between-YAP-and-SICStus-Prolog_002e" href="#Major-Differences-with-SICStus">25.2.1 Major Differences between YAP and SICStus Prolog.</a></li>
<li><a name="toc-YAP-predicates-fully-compatible-with-SICStus-Prolog" href="#Fully-SICStus-Compatible">25.2.2 YAP predicates fully compatible with SICStus Prolog</a></li>
<li><a name="toc-YAP-predicates-not-strictly-compatible-with-SICStus-Prolog" href="#Not-Strictly-SICStus-Compatible">25.2.3 YAP predicates not strictly compatible with SICStus Prolog</a></li>
<li><a name="toc-YAP-predicates-not-available-in-SICStus-Prolog" href="#Not-in-SICStus-Prolog">25.2.4 YAP predicates not available in SICStus Prolog</a></li>
</ul></li>
<li><a name="toc-Compatibility-with-the-ISO-Prolog-standard" href="#ISO-Prolog">25.3 Compatibility with the ISO Prolog standard</a></li>
</ul></li>
<li><a name="toc-Summary-of-YAP-Predefined-Operators" href="#Operators">Appendix A Summary of YAP Predefined Operators</a></li>
<li><a name="toc-Predicate-Index-1" href="#Predicate-Index">Predicate Index</a></li>
<li><a name="toc-Concept-Index-1" href="#Concept-Index">Concept Index</a></li>
</ul>
</div>
<hr>
<a name="Top"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[ &lt; ]</td>
<td valign="middle" align="left">[<a href="#Intro" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="YAP-Prolog"></a>
<h1 class="top">YAP Prolog</h1>
<p>This file documents the YAP Prolog System version 6.2.0, a
high-performance Prolog compiler developed at LIACC, Universidade do
Porto. YAP is based on David H. D. Warren&rsquo;s WAM (Warren Abstract
Machine), with several optimizations for better performance. YAP follows
the Edinburgh tradition, and is largely compatible with DEC-10 Prolog,
Quintus Prolog, and especially with C-Prolog.
</p>
<p>This file contains extracts of the SWI-Prolog manual, as written by Jan
Wielemaker. Our thanks to the author for his kind permission in allowing
us to include his text in this document.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Intro">Introduction</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Install">1 Installing YAP</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Installation
</td></tr>
<tr><td align="left" valign="top"><a href="#Run">2 Running YAP</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Syntax">3 Syntax</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The syntax of YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Loading-Programs">4 Loading Programs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Loading Prolog programs
</td></tr>
<tr><td align="left" valign="top"><a href="#Modules">5 The Module System</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Using Modules in YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Built_002dins">6 Built-In Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Library">7 Library Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI-Prolog emulation
</td></tr>
<tr><td align="left" valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Global Variables for Prolog
</td></tr>
<tr><td align="left" valign="top"><a href="#Extensions">10 Extensions to Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Extensions to Standard YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Rational-Trees">10.1 Rational Trees</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Working with Rational Trees
</td></tr>
<tr><td align="left" valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Changing the Execution of Goals
</td></tr>
<tr><td align="left" valign="top"><a href="#Attributed-Variables">11 Attributed Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Using attributed Variables
</td></tr>
<tr><td align="left" valign="top"><a href="#CLPR">12 Constraint Logic Programming over Reals</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The CLP(R) System
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR">13 CHR: Constraint Handling Rules</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The CHR System
</td></tr>
<tr><td align="left" valign="top"><a href="#Logtalk">14 Logtalk</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The Logtalk Object-Oriented System
</td></tr>
<tr><td align="left" valign="top"><a href="#MYDDAS">15 MYDDAS</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The YAP Database Interface
</td></tr>
<tr><td align="left" valign="top"><a href="#Threads">16 Threads</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Thread Library
</td></tr>
<tr><td align="left" valign="top"><a href="#Parallelism">17 Parallelism</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Running in Or-Parallel
</td></tr>
<tr><td align="left" valign="top"><a href="#Tabling">18 Tabling</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Storing Intermediate Solutions of programs
</td></tr>
<tr><td align="left" valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Profiling Abstract Machine Instructions
</td></tr>
<tr><td align="left" valign="top"><a href="#Low-Level-Tracing">19 Tracing at Low Level</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Tracing at Abstract Machine Level
</td></tr>
<tr><td align="left" valign="top"><a href="#Debugging">21 Debugging</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Using the Debugger
</td></tr>
<tr><td align="left" valign="top"><a href="#Efficiency">22 Efficiency Considerations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#C_002dInterface">23 C Language interface to YAP</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Interfacing predicates written in C
</td></tr>
<tr><td align="left" valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Using YAP as a library in other programs
</td></tr>
<tr><td align="left" valign="top"><a href="#Compatibility">25 Compatibility with Other Prolog systems</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Compatibility with other Prolog systems
</td></tr>
<tr><td align="left" valign="top"><a href="#Predicate-Index">Predicate Index</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> An item for each predicate
</td></tr>
<tr><td align="left" valign="top"><a href="#Concept-Index">Concept Index</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> An item for each concept
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Built In Predicates
</pre></th></tr><tr><td align="left" valign="top"><a href="#Control">6.1 Control Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Controlling the execution of Prolog programs
</td></tr>
<tr><td align="left" valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Handling calls to Undefined Procedures
</td></tr>
<tr><td align="left" valign="top"><a href="#Messages">6.3 Message Handling</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Message Handling in YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Predicates on Terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Manipulating Atoms
</td></tr>
<tr><td align="left" valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Manipulating Characters
</td></tr>
<tr><td align="left" valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Comparison of Terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Arithmetic in YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#I_002fO">6.9 I/O Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Input/Output with YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Database">6.10 Using the Clausal Data Base</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Modifying Prolog&rsquo;s Database
</td></tr>
<tr><td align="left" valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Finding All Possible Solutions
</td></tr>
<tr><td align="left" valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Preds">6.21 Predicate Information</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Updating Prolog Terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Manipulating Global Variables
</td></tr>
<tr><td align="left" valign="top"><a href="#Profiling">6.18 Profiling Prolog Programs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Profiling Prolog Execution
</td></tr>
<tr><td align="left" valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Limiting the Maximum Number of Reductions
</td></tr>
<tr><td align="left" valign="top"><a href="#Arrays">6.20 Arrays</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Supporting Global and Local Arrays
</td></tr>
<tr><td align="left" valign="top"><a href="#Preds">6.21 Predicate Information</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Information on Predicates
</td></tr>
<tr><td align="left" valign="top"><a href="#Misc">6.22 Miscellaneous</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Miscellaneous Predicates
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Running
</pre></th></tr><tr><td align="left" valign="top"><a href="#Running-YAP-Interactively">2.1 Running YAP Interactively</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Interacting with YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Running-Prolog-Files">2.2 Running Prolog Files</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Running Prolog files as scripts
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Syntax
</pre></th></tr><tr><td align="left" valign="top"><a href="#Formal-Syntax">3.1 Syntax of Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Tokens">3.2 Prolog Tokens</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Syntax of Prolog tokens
</td></tr>
<tr><td align="left" valign="top"><a href="#Encoding">3.3 Wide Character Support</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How characters are encoded and Wide Character Support
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Tokens
</pre></th></tr><tr><td align="left" valign="top"><a href="#Numbers">3.2.1 Numbers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Integer and Floating-Point Numbers
</td></tr>
<tr><td align="left" valign="top"><a href="#Strings">3.2.2 Character Strings</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Sequences of Characters
</td></tr>
<tr><td align="left" valign="top"><a href="#Atoms">3.2.3 Atoms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Atomic Constants
</td></tr>
<tr><td align="left" valign="top"><a href="#Variables">3.2.4 Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Logical Variables
</td></tr>
<tr><td align="left" valign="top"><a href="#Punctuation-Tokens">3.2.5 Punctuation Tokens</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Tokens that separate other tokens
</td></tr>
<tr><td align="left" valign="top"><a href="#Layout">3.2.6 Layout</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Comments and Other Layout Rules
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Numbers
</pre></th></tr><tr><td align="left" valign="top"><a href="#Integers">3.2.1.1 Integers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How Integers are read and represented
</td></tr>
<tr><td align="left" valign="top"><a href="#Floats">3.2.1.2 Floating-point Numbers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Floating Point Numbers
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Encoding
</pre></th></tr><tr><td align="left" valign="top"><a href="#Stream-Encoding">3.3.1 Wide character encodings on streams</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How Prolog Streams can be coded
</td></tr>
<tr><td align="left" valign="top"><a href="#BOM">3.3.2 BOM: Byte Order Mark</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The Byte Order Mark
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Loading Programs
</pre></th></tr><tr><td align="left" valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Program Loading and Updating
</td></tr>
<tr><td align="left" valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Changing the compiler&rsquo;s parameters
</td></tr>
<tr><td align="left" valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Compiling program fragments
</td></tr>
<tr><td align="left" valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Saving and Restoring Programs
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Modules
</pre></th></tr><tr><td align="left" valign="top"><a href="#Module-Concepts">5.1 Module Concepts</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The Key Ideas in Modules
</td></tr>
<tr><td align="left" valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How To Define a New Module
</td></tr>
<tr><td align="left" valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How to Use a Module
</td></tr>
<tr><td align="left" valign="top"><a href="#Meta_002dPredicates-in-Modules">5.4 Meta-Predicates in Modules</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How to Handle New Meta-Predicates
</td></tr>
<tr><td align="left" valign="top"><a href="#Re_002dExporting-Modules">5.5 Re-Exporting Predicates From Other Modules</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How to Re-export Predicates From Other Modules
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Input/Output
</pre></th></tr><tr><td align="left" valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> C-Prolog Compatible File Handling
</td></tr>
<tr><td align="left" valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Input/Output of terms
</td></tr>
<tr><td align="left" valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Input/Output of Characters
</td></tr>
<tr><td align="left" valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Input/Output using Streams
</td></tr>
<tr><td align="left" valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> C-Prolog compatible Character I/O to terminal
</td></tr>
<tr><td align="left" valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Controlling your Input/Output
</td></tr>
<tr><td align="left" valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Using Sockets from YAP
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Database
</pre></th></tr><tr><td align="left" valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Asserting and Retracting
</td></tr>
<tr><td align="left" valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Finding out what is in the Data Base
</td></tr>
<tr><td align="left" valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> YAP&rsquo;s Internal Database
</td></tr>
<tr><td align="left" valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Storing and Fetching Terms in the BlackBoard
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Library
</pre></th></tr><tr><td align="left" valign="top"><a href="#Aggregate">7.1 Aggregate</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI and SICStus compatible aggregate library
</td></tr>
<tr><td align="left" valign="top"><a href="#Apply">7.2 Apply Macros</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI-Compatible Apply library.
</td></tr>
<tr><td align="left" valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Binary Tree Implementation of Association Lists.
</td></tr>
<tr><td align="left" valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Predicates to add and lookup balanced binary trees.
</td></tr>
<tr><td align="left" valign="top"><a href="#Heaps">7.5 Heaps</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Labelled binary tree where the key of each node is less
than or equal to the keys of its children.
</td></tr>
<tr><td align="left" valign="top"><a href="#Lambda">7.31 Lambda Expressions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Ulrich Neumerkel&rsquo;s Lambda Library
</td></tr>
<tr><td align="left" valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Lists">7.6 List Manipulation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#MapList">7.8 Maplist</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI-Compatible Apply library.
</td></tr>
<tr><td align="left" valign="top"><a href="#matrix">7.9 Matrix Library</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Matrix Objects
</td></tr>
<tr><td align="left" valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Matlab Interface
</td></tr>
<tr><td align="left" valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Queues, Heaps, and Beams.
</td></tr>
<tr><td align="left" valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Ordered Set Manipulation
</td></tr>
<tr><td align="left" valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Pseudo Random Numbers
</td></tr>
<tr><td align="left" valign="top"><a href="#Queues">7.14 Queues</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Queue Manipulation
</td></tr>
<tr><td align="left" valign="top"><a href="#Random">7.15 Random Number Generator</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Random Numbers
</td></tr>
<tr><td align="left" valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI inspired utilities for fast stream scanning.
</td></tr>
<tr><td align="left" valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Predicates to add, lookup and delete in red-black binary trees.
</td></tr>
<tr><td align="left" valign="top"><a href="#RegExp">7.18 Regular Expressions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Regular Expression Manipulation
</td></tr>
<tr><td align="left" valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI Prolog shlib library
</td></tr>
<tr><td align="left" valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Writing To and Reading From Strings
</td></tr>
<tr><td align="left" valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> System Utilities
</td></tr>
<tr><td align="left" valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Utilities on Terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Call With registered Cleanup Calls
</td></tr>
<tr><td align="left" valign="top"><a href="#Timeout">7.26 Calls With Timeout</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Call With Timeout
</td></tr>
<tr><td align="left" valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Directed Graphs Implemented With Red-Black Trees
</td></tr>
<tr><td align="left" valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Undirected Graphs Using DGraphs
</td></tr>
<tr><td align="left" valign="top"><a href="#LAM">7.32 LAM</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> LAM MPI
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Debugging
</pre></th></tr><tr><td align="left" valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Deb-Interaction">21.2 Interacting with the debugger</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Compatibility
</pre></th></tr><tr><td align="left" valign="top"><a href="#C_002dProlog">25.1 Compatibility with the C-Prolog interpreter</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#SICStus-Prolog">25.2 Compatibility with the Quintus and SICStus Prolog systems</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#ISO-Prolog">25.3 Compatibility with the ISO Prolog standard</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Attributes
</pre></th></tr><tr><td align="left" valign="top"><a href="#Attribute-Declarations">11.2.1 Attribute Declarations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Declaring New Attributes
</td></tr>
<tr><td align="left" valign="top"><a href="#Attribute-Manipulation">11.2.2 Attribute Manipulation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Setting and Reading Attributes
</td></tr>
<tr><td align="left" valign="top"><a href="#Attributed-Unification">11.2.3 Attributed Unification</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Tuning the Unification Algorithm
</td></tr>
<tr><td align="left" valign="top"><a href="#Displaying-Attributes">11.2.4 Displaying Attributes</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Displaying Attributes in User-Readable Form
</td></tr>
<tr><td align="left" valign="top"><a href="#Projecting-Attributes">11.2.5 Projecting Attributes</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Obtaining the Attributes of Interest
</td></tr>
<tr><td align="left" valign="top"><a href="#Attribute-Examples">11.2.6 Attribute Examples</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Two Simple Examples of how to use Attributes.
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of SWI-Prolog
</pre></th></tr><tr><td align="left" valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> maplist and friends
</td></tr>
<tr><td align="left" valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Emulating SWI-like attributed variables
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of CLPR
</pre></th></tr><tr><td align="left" valign="top"><a href="#CLPR-Solver-Predicates">12.1 Solver Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CLPR-Syntax">12.2 Syntax of the predicate arguments</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CLPR-Unification">12.3 Use of unification</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CLPR-Non_002dlinear-Constraints">12.4 Non-Linear Constraints</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of CHR
</pre></th></tr><tr><td align="left" valign="top"><a href="#CHR-Introduction">13.1 Introduction</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-Syntax-and-Semantics">13.2 Syntax and Semantics</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-in-YAP-Programs">13.3 CHR in YAP Programs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-Debugging">13.4 Debugging</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-Examples">13.5 Examples</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-Compatibility">13.6 Compatibility with SICStus CHR</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-Guidelines">13.7 Guidelines</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of C-Interface
</pre></th></tr><tr><td align="left" valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Primitives available to the C programmer
</td></tr>
<tr><td align="left" valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Primitives available to the C programmer
</td></tr>
<tr><td align="left" valign="top"><a href="#Unifying-Terms">23.2 Unification</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How to Unify Two Prolog Terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> From character arrays to Lists of codes and back
</td></tr>
<tr><td align="left" valign="top"><a href="#Memory-Allocation">23.4 Memory Allocation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Stealing Memory From YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Controlling-Streams">23.5 Controlling YAP Streams from <code>C</code></a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Control How YAP sees Streams
</td></tr>
<tr><td align="left" valign="top"><a href="#Utility-Functions">23.6 Utility Functions in <code>C</code></a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> From character arrays to Lists of codes and back
</td></tr>
<tr><td align="left" valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> From C to YAP to C to YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Module-Manipulation-in-C">23.8 Module Manipulation in C</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Create and Test Modules from within C
</td></tr>
<tr><td align="left" valign="top"><a href="#Miscellaneous-C_002dFunctions">23.9 Miscellaneous C Functions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Other Helpful Interface Functions
</td></tr>
<tr><td align="left" valign="top"><a href="#Writing-C">23.10 Writing predicates in C</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Writing Predicates in C
</td></tr>
<tr><td align="left" valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Save_0026Rest">23.12 Saving and Restoring</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#YAP4-Notes">23.13 Changes to the C-Interface in YAP4</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Changes in Foreign Predicates Interface
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of C-Prolog
</pre></th></tr><tr><td align="left" valign="top"><a href="#Major-Differences-with-C_002dProlog">25.1.1 Major Differences between YAP and C-Prolog.</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Fully-C_002dProlog-Compatible">25.1.2 YAP predicates fully compatible with C-Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Not-Strictly-C_002dProlog-Compatible">25.1.3 YAP predicates not strictly compatible with C-Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> YAP predicates not strictly as C-Prolog
</td></tr>
<tr><td align="left" valign="top"><a href="#Not-in-C_002dProlog">25.1.4 YAP predicates not available in C-Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Not-in-YAP">25.1.5 YAP predicates not available in C-Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> C-Prolog predicates not available in YAP
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of SICStus Prolog
</pre></th></tr><tr><td align="left" valign="top"><a href="#Major-Differences-with-SICStus">25.2.1 Major Differences between YAP and SICStus Prolog.</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Fully-SICStus-Compatible">25.2.2 YAP predicates fully compatible with SICStus Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Not-Strictly-SICStus-Compatible">25.2.3 YAP predicates not strictly compatible with SICStus Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> YAP predicates not strictly as
SICStus Prolog
</td></tr>
<tr><td align="left" valign="top"><a href="#Not-in-SICStus-Prolog">25.2.4 YAP predicates not available in SICStus Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Tables
</pre></th></tr><tr><td align="left" valign="top"><a href="#Operators">Appendix A Summary of YAP Predefined Operators</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Predefined operators
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
</pre></th></tr></table>
<hr size="6">
<a name="Intro"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Top" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Install" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Install" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Introduction"></a>
<h1 class="unnumbered">Introduction</h1>
<p>This document provides User information on version 6.2.0 of
YAP (<em>Yet Another Prolog</em>). The YAP Prolog System is a
high-performance Prolog compiler developed at LIACC, Universidade do
Porto. YAP provides several important features:
</p>
<ul>
<li> Speed: YAP is widely considered one of the fastest available
Prolog systems.
</li><li> Functionality: it supports stream I/O, sockets, modules,
exceptions, Prolog debugger, C-interface, dynamic code, internal
database, DCGs, saved states, co-routining, arrays, threads.
</li><li> We explicitly allow both commercial and non-commercial use of YAP.
</li></ul>
<p>YAP is based on the David H. D. Warren&rsquo;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.
</p>
<p>YAP implements most of the ISO-Prolog standard. We are striving at
full compatibility, and the manual describes what is still
missing. The manual also includes a (largely incomplete) comparison
with SICStus Prolog.
</p>
<p>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 <cite>The Art of Prolog</cite>, by
L. Sterling and E. Shapiro, published by &quot;The MIT Press, Cambridge
MA&quot;. Other references should include the classical <cite>Programming in
Prolog</cite>, by W.F. Clocksin and C.S. Mellish, published by
Springer-Verlag.
</p>
<p>YAP 4.3 is known to build with many versions of gcc (&lt;= gcc-2.7.2, &gt;=
gcc-2.8.1, &gt;= 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.
</p>
<p>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.
</p>
<p>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 <a href="mailto:yap-users AT lists.sourceforge.net">yap-users AT lists.sourceforge.net</a>. To
subscribe to the mailing list, visit the page
<a href="https://lists.sourceforge.net/lists/listinfo/yap-users">https://lists.sourceforge.net/lists/listinfo/yap-users</a>.
</p>
<p>On-line documentation is available for YAP at:
</p>
<p> <a href="http://www.ncc.up.pt/~vsc/YAP/">http://www.ncc.up.pt/~vsc/YAP/</a>
</p>
<p>Recent versions of YAP, including both source and selected binaries,
can be found from this same URL.
</p>
<p>This manual was written by V&iacute;tor Santos Costa,
Lu&iacute;s Damas, Rog&eacute;rio Reis, and R&uacute;ben Azevedo. The
manual is largely based on the DECsystem-10 Prolog User&rsquo;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&rsquo;Keefe. We would also like to gratefully
acknowledge the contributions from Ashwin Srinivasian.
</p>
<p>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.
</p>
<p>The packages are, in alphabetical order:
</p>
<ul>
<li> The CHR package developed by Tom Schrijvers,
Christian Holzbaur, and Jan Wielemaker.
</li><li> The CLP(R) package developed by Leslie De Koninck, Bart Demoen, Tom
Schrijvers, and Jan Wielemaker, based on the CLP(Q,R) implementation
by Christian Holzbaur.
</li><li> The Logtalk Object-Oriented system is developed at the University
of Beira Interior, Portugal, by Paulo Moura:
<p><a href="http://logtalk.org/">http://logtalk.org/</a>
</p>
<p>Logtalk is no longer distributed with YAP. Please use the Logtalk standalone
installer for a smooth integration with YAP.
</p>
</li><li> The Pillow WEB library developed at Universidad Politecnica de
Madrid by the CLIP group. This package is distributed under the FSF&rsquo;s
LGPL. Documentation on this package is distributed separately from
yap.tex.
</li><li> The <code>yap2swi</code> library implements some of the functionality of
SWI&rsquo;s PL interface. Please do refer to the SWI-Prolog home page:
<p><a href="http://www.swi-prolog.org">http://www.swi-prolog.org</a>
</p>
<p>for more information on SWI-Prolog and for a detailed description of its
foreign language interface.
</p>
</li></ul>
<hr>
<a name="Install"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Intro" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Intro" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Configuration-Options" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Run" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Installing-YAP"></a>
<h1 class="chapter">1 Installing YAP</h1>
<a name="index-installation"></a>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Configuration-Options">1.1 Tuning the Functionality of YAP</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Tuning the Functionality of YAP Machine
</td></tr>
<tr><td align="left" valign="top"><a href="#Machine-Options">1.2 Tuning YAP for a Particular Machine and Compiler</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
</table>
<p>To compile YAP it should be sufficient to:
</p>
<ol>
<li> <code>mkdir ARCH</code>.
</li><li> <code>cd ARCH</code>.
</li><li> <code>../configure ...options...</code>.
<p>Notice that by default <code>configure</code> gives you a vanilla
configuration. For instance, in order to use co-routining and/or CLP
you need to do
</p>
<div class="example">
<pre class="example">../configure --enable-coroutining ...options...
</pre></div>
<p>Please see section <a href="#Configuration-Options">Tuning the Functionality of YAP</a> for extra options.
</p>
</li><li> check the Makefile for any extensions or changes you want to
make.
<p>YAP uses <code>autoconf</code>. Recent versions of YAP try to follow GNU
conventions on where to place software.
</p>
<ul>
<li> The main executable is placed at <code>BINDIR</code>. This executable is
actually a script that calls the Prolog engine, stored at <code>LIBDIR</code>.
</li><li> <code>LIBDIR</code> is the directory where libraries are stored. YAPLIBDIR is a
subdirectory that contains the Prolog engine and a Prolog library.
</li><li> <code>INCLUDEDIR</code> is used if you want to use YAP as a library.
</li><li> <code>INFODIR</code> is where to store <code>info</code> files. Usually
<code>/usr/local/info</code>, <code>/usr/info</code>, or <code>/usr/share/info</code>.
</li></ul>
</li><li> <code>make</code>.
</li><li> If the compilation succeeds, try <code>./yap</code>.
</li><li> If you feel satisfied with the result, do <code>make install</code>.
</li><li> <code>make install-info</code> will create the info files in the
standard info directory.
</li><li> <code>make html</code> will create documentation in html format in the
predefined directory.
<p>In most systems you will need to be superuser in order to do <code>make
install</code> and <code>make info</code> on the standard directories.
</p></li></ol>
<hr>
<a name="Configuration-Options"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Install" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Install" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Install" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Machine-Options" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Run" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Tuning-the-Functionality-of-YAP"></a>
<h2 class="section">1.1 Tuning the Functionality of YAP</h2>
<a name="index-syntax"></a>
<p>Compiling YAP with the standard options give you a plain vanilla
Prolog. You can tune YAP to include extra functionality by calling
<code>configure</code> with the appropriate options:
</p>
<ul>
<li> <code>--enable-rational-trees=yes</code> gives you support for infinite
rational trees.
</li><li> <code>--enable-coroutining=yes</code> gives you support for coroutining,
including freezing of goals, attributed variables, and
constraints. This will also enable support for infinite rational
trees.
</li><li> <code>--enable-depth-limit=yes</code> allows depth limited evaluation, say for
implementing iterative deepening.
</li><li> <code>--enable-low-level-tracer=yes</code> allows support for tracing all calls,
retries, and backtracks in the system. This can help in debugging your
application, but results in performance loss.
</li><li> <code>--enable-wam-profile=yes</code> allows profiling of abstract machine
instructions. This is useful when developing YAP, should not be so
useful for normal users.
</li><li> <code>--enable-condor=yes</code> allows using the Condor system that
support High Throughput Computing (HTC) on large collections of
distributively owned computing resources.
</li><li> <code>--enable-tabling=yes</code> allows tabling support. This option
is still experimental.
</li><li> <code>--enable-parallelism={env-copy,sba,a-cow}</code> allows
or-parallelism supported by one of these three forms. This option is
still highly experimental.
</li><li> <code>--with-max-workers</code> allows definition of the maximum
number of parallel processes (its value can be consulted at runtime
using the flag <code>max_workers</code>).
</li><li> <code>--with-gmp[=DIR]</code> give a path to where one can find the
<code>GMP</code> library if not installed in the default path.
</li><li> <code>--enable-threads</code> allows using of the multi-threading
predicates provided by YAP. Depending on the operating system, the
option <code>--enable-pthread-locking</code> may also need to be used.
</li><li> <code>--with-max-threads</code> allows definition of the maximum
number of threads (the default value is 1024; its value can be consulted
at runtime using the flag <code>max_threads</code>).
</li></ul>
<p>Next section discusses machine dependent details.
</p>
<hr>
<a name="Machine-Options"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Install" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Configuration-Options" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Install" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Tuning-for-GCC" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Run" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Tuning-YAP-for-a-Particular-Machine-and-Compiler"></a>
<h2 class="section">1.2 Tuning YAP for a Particular Machine and Compiler</h2>
<a name="index-machine-optimizations"></a>
<p>The default options should give you best performance under
<code>GCC</code>. Although the system is tuned for this compiler
we have been able to compile versions of YAP under lcc in Linux,
Sun&rsquo;s cc compiler, IBM&rsquo;s xlc, SGI&rsquo;s cc, and Microsoft&rsquo;s Visual C++
6.0.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Tuning-for-GCC">1.3 Tuning YAP for <code>GCC</code>.</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Using the GNUCC compiler
</td></tr>
<tr><td align="left" valign="top"><a href="#Compiling-Under-Visual-C_002b_002b">1.3.1 Compiling Under Visual C++</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Using Microsoft&rsquo;s Visual C++ environment
</td></tr>
<tr><td align="left" valign="top"><a href="#Tuning-for-SGI-cc">1.3.2 Compiling Under SGI&rsquo;s cc</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Compiling Under SGI&rsquo;s <code>cc</code>
</td></tr>
</table>
<hr>
<a name="Tuning-for-GCC"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Install" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Machine-Options" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Install" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Compiling-Under-Visual-C_002b_002b" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Run" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Tuning-YAP-for-GCC_002e"></a>
<h2 class="section">1.3 Tuning YAP for <code>GCC</code>.</h2>
<p>YAP has been developed to take advantage of <code>GCC</code> (but not to
depend on it). The major advantage of <code>GCC</code> is threaded code and
explicit register reservation.
</p>
<p>YAP is set by default to compile with the best compilation flags we
know. Even so, a few specific options reduce portability. The option
</p><ul>
<li> <code>--enable-max-performance=yes</code> will try to support the best
available flags for a specific architectural model. Currently, the option
assumes a recent version of <code>GCC</code>.
</li><li> <code>--enable-debug-yap</code> compiles YAP so that it can be debugged
by tools such as <code>dbx</code> or <code>gdb</code>.
</li></ul>
<p>Here follow a few hints:
</p>
<p>On x86 machines the flags:
</p>
<div class="example">
<pre class="example">YAP_EXTRAS= ... -DBP_FREE=1
</pre></div>
<p>tells us to use the <code>%bp</code> register (frame-pointer) as the emulator&rsquo;s
program counter. This seems to be stable and is now default.
</p>
<p>On Sparc/Solaris2 use:
</p>
<div class="example">
<pre class="example">YAP_EXTRAS= ... -mno-app-regs -DOPTIMISE_ALL_REGS_FOR_SPARC=1
</pre></div>
<p>and YAP will get two extra registers! This trick does not work on
SunOS 4 machines.
</p>
<p>Note that versions of GCC can be tweaked to recognize different
processors within the same instruction set, e.g. 486, Pentium, and
PentiumPro for the x86; or Ultrasparc, and Supersparc for
Sparc. Unfortunately, some of these tweaks do may make YAP run slower or
not at all in other machines with the same instruction set, so they
cannot be made default.
</p>
<p>Last, the best options also depends on the version of GCC you are using, and
it is a good idea to consult the GCC manual under the menus &quot;Invoking
GCC&quot;/&quot;Submodel Options&quot;. Specifically, you should check
<code>-march=XXX</code> for recent versions of GCC/EGCS. In the case of
<code>GCC2.7</code> and other recent versions of <code>GCC</code> you can check:
</p>
<dl compact="compact">
<dt><code>486:</code></dt>
<dd><p>In order to take advantage of 486 specific optimizations in GCC 2.7.*:
</p>
<div class="example">
<pre class="example">YAP_EXTRAS= ... -m486 -DBP_FREE=1
</pre></div>
</dd>
<dt><code>Pentium:</code></dt>
<dd><div class="example">
<pre class="example">YAP_EXTRAS= ... -m486 -malign-loops=2 -malign-jumps=2 \
-malign-functions=2
</pre></div>
</dd>
<dt><code>PentiumPro and other recent Intel and AMD machines:</code></dt>
<dd><p>PentiumPros are known not to require alignment. Check your version of
<code>GCC</code> for the best <code>-march</code> option.
</p>
</dd>
<dt><code>Super and UltraSparcs:</code></dt>
<dd><div class="example">
<pre class="example">YAP_EXTRAS= ... -msupersparc
</pre></div>
</dd>
<dt><code>MIPS: if have a recent machine and you need a 64 bit wide address</code></dt>
<dd><p>space you can use the abi 64 bits or eabi option, as in:
</p><div class="example">
<pre class="example">CC=&quot;gcc -mabi=64&quot; ./configure --...
</pre></div>
<p>Be careful. At least for some versions of <code>GCC</code>, compiling with
<code>-g</code> seems to result in broken code.
</p>
</dd>
<dt><code>WIN32: GCC is distributed in the MINGW32 and CYGWIN packages.</code></dt>
<dd>
<p>The Mingw32 environment is available from the URL:
</p>
<p><code>http://www.mingw.org</code>
</p>
<p>You will need to install the <code>msys</code> and <code>mingw</code>
packages. You should be able to do configure, make and make install.
</p>
<p>If you use mingw32 you may want to search the contributed packages for
the <code>gmp</code> multi-precision arithmetic library. If you do setup YAP
with <code>gmp</code> note that <code>libgmp.dll</code> must be in the path,
otherwise YAP will not be able to execute.
</p>
<p>CygWin environment is available from the URL:
</p>
<p><code>http://www.cygwin.com</code>
</p>
<p>and mirrors. We suggest using recent versions of the cygwin shell. The
compilation steps under the cygwin shell are as follows:
</p>
<div class="example">
<pre class="example">mkdir cyg
$YAPSRC/configure --enable-coroutining \\
--enable-depth-limit \\
--enable-max-performance
make
make install
</pre></div>
<p>By default, YAP will use the <code>-mno-cygwin</code> 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&rsquo;s <code>CRTDLL.DLL</code> <code>C</code> run time library supplied with
Win32 platforms through the mingw32 interface. Note that some older
WIN95 systems may not have <code>CRTDLL.DLL</code>, in this case it should
be sufficient to import the file from a newer WIN95 or WIN98 machine.
</p>
<p>You should check the default installation path which is set to
<code>/YAP</code> in the standard Makefile. This string will usually
be expanded into <code>c:\YAP</code> by Windows.
</p>
<p>The cygwin environment does not provide <tt>gmp</tt> on the MINGW
subsystem. You can fetch a dll for the <tt>gmp</tt> library from
<a href="http://www.sf.net/projects/mingwrep">http://www.sf.net/projects/mingwrep</a>.
</p>
<p>It is also possible to configure YAP to be a part of the cygwin
environment. In this case you should use:
</p><div class="example">
<pre class="example">mkdir cyg
$YAPSRC/configure --enable-max-performance \\
--enable-cygwin=yes
make
make install
</pre></div>
<p>YAP will then compile using the cygwin library and will be installed
in cygwin&rsquo;s <code>/usr/local</code>. You can use YAP from a cygwin console,
or as a standalone application as long as it can find
<code>cygwin1.dll</code> in its path. Note that you may use to use
<code>--enable-depth-limit</code> for Aleph compatibility, and that you may
want to be sure that GMP is installed.
</p>
</dd>
</dl>
<hr>
<a name="Compiling-Under-Visual-C_002b_002b"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Install" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tuning-for-GCC" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tuning-for-GCC" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Tuning-for-SGI-cc" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Run" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Compiling-Under-Visual-C_002b_002b-1"></a>
<h3 class="subsection">1.3.1 Compiling Under Visual C++</h3>
<p>YAP compiles cleanly under Microsoft&rsquo;s Visual C++ release 6.0. We next
give a step-by-step tutorial on how to compile YAP manually using this
environment.
</p>
<p>First, it is a good idea to build YAP as a DLL:
</p>
<ol>
<li> create a project named yapdll using File.New. The project will be a
DLL project, initially empty.
<p>Notice that either the project is named yapdll or you must replace the
preprocessors variable <var>YAPDLL_EXPORTS</var> to match your project names
in the files <code>YAPInterface.h</code> and <code>c_interface.c</code>.
</p>
</li><li> add all .c files in the <var>$YAPSRC/C</var> directory and in the
<var>$YAPSRC\OPTYAP</var> directory to the Project&rsquo;s <code>Source Files</code> (use
FileView).
</li><li> add all .h files in the <var>$YAPSRC/H</var> directory,
<var>$YAPSRC\include</var> directory and in the <var>$YAPSRC\OPTYAP</var>
subdirectory to the Project&rsquo;s <code>Header Files</code>.
</li><li> Ideally, you should now use <code>m4</code> to generate extra .h from .m4 files and use
<code>configure</code> to create a <code>config.h</code>. Or, you can be lazy, and
fetch these files from <var>$YAPSRC\VC\include</var>.
</li><li> You may want to go to <code>Build.Set Active Configuration</code> and set <code>Project
Type</code> to <code>Release</code>
</li><li> To use YAP&rsquo;s own include directories you have to set the Project
option <code>Project.Project Settings.C/C++.Preprocessor.Additional
Include Directories</code> to include the directories <var>$YAPSRC\H</var>,
<var>$YAPSRC\VC\include</var>, <var>$YAPSRC\OPTYAP</var> and
<var>$YAPSRC\include</var>. The syntax is:
<div class="example">
<pre class="example">$YAPSRC\H, $YAPSRC\VC\include, $YAPSRC\OPTYAP, $YAPSRC\include
</pre></div>
</li><li> Build: the system should generate an <code>yapdll.dll</code> and an <code>yapdll.lib</code>.
</li><li> Copy the file <code>yapdll.dll</code> to your path. The file
<code>yapdll.lib</code> should also be copied to a location where the linker can find it.
</li></ol>
<p>Now you are ready to create a console interface for YAP:
</p><ol>
<li> create a second project say <code>wyap</code> with <code>File.New</code>. The project will be a
WIN32 console project, initially empty.
</li><li> add <var>$YAPSRC\console\yap.c</var> to the <code>Source Files</code>.
</li><li> add <var>$YAPSRC\VC\include\config.h</var> and the files in <var>$YAPSRC\include</var> to
the <code>Header Files</code>.
</li><li> You may want to go to <code>Build.Set Active Configuration</code> and set
<code>Project Type</code> to <code>Release</code>.
</li><li> you will eventually need to bootstrap the system by booting from
<code>boot.yap</code>, so write:
<div class="example">
<pre class="example"> -b $YAPSRC\pl\boot.yap
</pre></div>
<p> in <code>Project.Project Settings.Debug.Program Arguments</code>.
</p>
</li><li> You need the sockets and yap libraries. Add
<div class="example">
<pre class="example">ws2_32.lib yapdll.lib to
</pre></div>
<p>to
</p>
<p>to <code>Project.Project Settings.Link.Object/Library Modules</code>
</p>
<p>You may also need to set the <code>Link Path</code> so that VC++ will find <code>yapdll.lib</code>.
</p>
</li><li> set <code>Project.Project Settings.C/C++.Preprocessor.Additional
Include Directories</code> to include the <var>$YAPSRC/VC/include</var> and
<var>$YAPSRC/include</var>.
<p>The syntax is:
</p>
<div class="example">
<pre class="example">$YAPSRC\VC\include, $YAPSRC\include
</pre></div>
</li><li> Build the system.
</li><li> Use <code>Build.Start Debug</code> to boot the system, and then create the saved state with
<div class="example">
<pre class="example">['$YAPSRC\\pl\\init'].
save_program('startup.yss').
^Z
</pre></div>
<p>That&rsquo;s it, you&rsquo;ve got YAP and the saved state!
</p></li></ol>
<p>The $YAPSRC\VC directory has the make files to build YAP4.3.17 under VC++ 6.0.
</p>
<hr>
<a name="Tuning-for-SGI-cc"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Install" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Compiling-Under-Visual-C_002b_002b" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tuning-for-GCC" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Run" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Run" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Compiling-Under-SGI_0027s-cc"></a>
<h3 class="subsection">1.3.2 Compiling Under SGI&rsquo;s cc</h3>
<p>YAP should compile under the Silicon Graphic&rsquo;s <code>cc</code> compiler,
although we advise using the GNUCC compiler, if available.
</p>
<dl compact="compact">
<dt><code>64 bit</code></dt>
<dd><p>Support for 64 bits should work by using (under Bourne shell syntax):
</p><div class="example">
<pre class="example">CC=&quot;cc -64&quot; $YAP_SRC_PATH/configure --...
</pre></div>
</dd>
</dl>
<hr>
<a name="Run"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Install" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tuning-for-SGI-cc" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Running-YAP-Interactively" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Syntax" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Running-YAP"></a>
<h1 class="chapter">2 Running YAP</h1>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Running-YAP-Interactively">2.1 Running YAP Interactively</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Interacting with YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Running-Prolog-Files">2.2 Running Prolog Files</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Running Prolog files as scripts
</td></tr>
</table>
<a name="index-booting"></a>
<p>We next describe how to invoke YAP in Unix systems.
</p>
<hr>
<a name="Running-YAP-Interactively"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Run" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Run" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Run" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Running-Prolog-Files" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Syntax" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Running-YAP-Interactively-1"></a>
<h2 class="section">2.1 Running YAP Interactively</h2>
<p>Most often you will want to use YAP in interactive mode. Assuming that
YAP is in the user&rsquo;s search path, the top-level can be invoked under
Unix with the following command:
</p>
<div class="example">
<pre class="example">yap [-s n] [-h n] [-a n] [-c IP_HOST port ] [filename]
</pre></div>
<p>All the arguments and flags are optional and have the following meaning:
</p><dl compact="compact">
<dt><code>-?</code></dt>
<dd><p>print a short error message.
</p></dd>
<dt><code>-s<var>Size</var></code></dt>
<dd><p>allocate <var>Size</var> K bytes for local and global stacks. The user may
specify <tt>M</tt> bytes.
</p></dd>
<dt><code>-h<var>Size</var></code></dt>
<dd><p>allocate <var>Size</var> K bytes for heap and auxiliary stacks
</p></dd>
<dt><code>-t<var>Size</var></code></dt>
<dd><p>allocate <var>Size</var> K bytes for the trail stack
</p></dd>
<dt><code>-L<var>Size</var></code></dt>
<dd><p>SWI-compatible option to allocate <var>Size</var> K bytes for local and global stacks, the local stack
cannot be expanded. To avoid confusion with the load option, <var>Size</var>
must immediately follow the letter <code>L</code>.
</p></dd>
<dt><code>-G<var>Size</var></code></dt>
<dd><p>SWI-compatible option to allocate <var>Size</var> K bytes for local and global stacks; the global
stack cannot be expanded
</p></dd>
<dt><code>-T<var>Size</var></code></dt>
<dd><p>SWI-compatible option to allocate <var>Size</var> K bytes for the trail stack; the trail cannot be expanded.
</p></dd>
<dt><code>-l <var>YAP_FILE</var></code></dt>
<dd><p>compile the Prolog file <var>YAP_FILE</var> before entering the top-level.
</p></dd>
<dt><code>-L <var>YAP_FILE</var></code></dt>
<dd><p>compile the Prolog file <var>YAP_FILE</var> and then halt. This option is
useful for implementing scripts.
</p></dd>
<dt><code>-g <var>Goal</var></code></dt>
<dd><p>run the goal <var>Goal</var> before top-level. The goal is converted from
an atom to a Prolog term.
</p></dd>
<dt><code>-z <var>Goal</var></code></dt>
<dd><p>run the goal <var>Goal</var> as top-level. The goal is converted from
an atom to a Prolog term.
</p></dd>
<dt><code>-b <var>BOOT_FILE</var></code></dt>
<dd><p>boot code is in Prolog file <var>BOOT_FILE</var>. The filename must define
the predicate <code>'$live'/0</code>.
</p></dd>
<dt><code>-c <tt>IP_HOST</tt> <tt>port</tt></code></dt>
<dd><p>connect standard streams to host <tt>IP_HOST</tt> at port <tt>port</tt>
</p></dd>
<dt><code>filename</code></dt>
<dd><p>restore state saved in the given file
</p></dd>
<dt><code>-f</code></dt>
<dd><p>do not consult initial files
</p></dd>
<dt><code>-q</code></dt>
<dd><p>do not print informational messages
</p></dd>
<dt><code>--</code></dt>
<dd><p>separator for arguments to Prolog code. These arguments are visible
through the <code>unix/1</code> built-in predicate.
</p></dd>
</dl>
<p>Note that YAP will output an error message on the following conditions:
</p>
<ul>
<li>
a file name was given but the file does not exist or is not a saved
YAP state;
</li><li>
the necessary amount of memory could not be allocated;
</li><li>
the allocated memory is not enough to restore the state.
</li></ul>
<p>When restoring a saved state, YAP will allocate the
same amount of memory as that in use when the state was saved, unless a
different amount is specified by flags in the command line. By default,
YAP restores the file &lsquo;<samp>startup.yss</samp>&rsquo; from the current directory or from
the YAP library.
<a name="index-environment-variables"></a>
</p>
<a name="index-YAPBINDIR"></a>
<ul>
<li>
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.
<a name="index-YAPLIBDIR"></a>
</li><li>
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.
<a name="index-YAPSHAREDIR"></a>
</li><li>
YAP will try to find library files from the YAPSHAREDIR/library
directory.
</li></ul>
<hr>
<a name="Running-Prolog-Files"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Run" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Running-YAP-Interactively" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Run" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Syntax" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Syntax" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Running-Prolog-Files-1"></a>
<h2 class="section">2.2 Running Prolog Files</h2>
<p>YAP can also be used to run Prolog files as scripts, at least in
Unix-like environments. A simple example is shown next (do not forget
that the shell comments are very important):
</p>
<div class="example">
<table class="cartouche" border="1"><tr><td>
<pre class="example">#!/usr/local/bin/yap -L --
#
# Hello World script file using YAP
#
# put a dot because of syntax errors .
:- write('Hello World'), nl.
</pre></td></tr></table>
</div>
<p>The <code>#!</code> 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 <code>-L</code> 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 <code>#</code> (the comment sign for Unix&rsquo;s shell). YAP will
consult the file and execute any commands.
</p>
<p>A slightly more sophisticated example is:
</p>
<div class="example">
<table class="cartouche" border="1"><tr><td>
<pre class="example">#!/usr/bin/yap -L --
#
# Hello World script file using YAP
# .
:- initialization(main).
main :- write('Hello World'), nl.
</pre></td></tr></table>
</div>
<p>The <code>initialization</code> directive tells YAP to execute the goal main
after consulting the file. Source code is thus compiled and <code>main</code>
executed at the end. The <code>.</code> is useful while debugging the script
as a Prolog program: it guarantees that the syntax error will not
propagate to the Prolog code.
</p>
<p>Notice that the <code>--</code> is required so that the shell passes the extra
arguments to YAP. As an example, consider the following script
<code>dump_args</code>:
</p>
<div class="example">
<table class="cartouche" border="1"><tr><td>
<pre class="example">#!/usr/bin/yap -L --
#.
main( [] ).
main( [H|T] ) :-
write( H ), nl,
main( T ).
:- unix( argv(AllArgs) ), main( AllArgs ).
</pre></td></tr></table>
</div>
<p>If you this run this script with the arguments:
</p><div class="example">
<pre class="example">./dump_args -s 10000
</pre></div>
<p>the script will start an YAP process with stack size <code>10MB</code>, and
the list of arguments to the process will be empty.
</p>
<p>Often one wants to run the script as any other program, and for this it
is convenient to ignore arguments to YAP. This is possible by using
<code>L --</code> as in the next version of <code>dump_args</code>:
</p>
<div class="example">
<table class="cartouche" border="1"><tr><td>
<pre class="example">#!/usr/bin/yap -L --
main( [] ).
main( [H|T] ) :-
write( H ), nl,
main( T ).
:- unix( argv(AllArgs) ), main( AllArgs ).
</pre></td></tr></table>
</div>
<p>The <code>--</code> indicates the next arguments are not for YAP. Instead,
they must be sent directly to the <code>argv</code> built-in. Hence, running
</p><div class="example">
<pre class="example">./dump_args test
</pre></div>
<p>will write <code>test</code> on the standard output.
</p>
<hr>
<a name="Syntax"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Run" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Running-Prolog-Files" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Formal-Syntax" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Syntax-1"></a>
<h1 class="chapter">3 Syntax</h1>
<p>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 <i>tokens</i> from which Prolog <i>terms</i> are
built.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Formal-Syntax">3.1 Syntax of Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Syntax of terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Tokens">3.2 Prolog Tokens</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Syntax of Prolog tokens
</td></tr>
<tr><td align="left" valign="top"><a href="#Encoding">3.3 Wide Character Support</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How characters are encoded and Wide Character Support
</td></tr>
</table>
<hr>
<a name="Formal-Syntax"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Syntax" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Syntax" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Tokens" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Syntax-of-Terms"></a>
<h2 class="section">3.1 Syntax of Terms</h2>
<a name="index-syntax-1"></a>
<p>Below, we describe the syntax of YAP terms from the different
classes of tokens defined above. The formalism used will be <em>BNF</em>,
extended where necessary with attributes denoting integer precedence or
operator type.
</p>
<div class="example">
<pre class="example">
<code>
term ----&gt; subterm(1200) end_of_term_marker
subterm(N) ----&gt; term(M) [M &lt;= N]
term(N) ----&gt; op(N, fx) subterm(N-1)
| op(N, fy) subterm(N)
| subterm(N-1) op(N, xfx) subterm(N-1)
| subterm(N-1) op(N, xfy) subterm(N)
| subterm(N) op(N, yfx) subterm(N-1)
| subterm(N-1) op(N, xf)
| subterm(N) op(N, yf)
term(0) ----&gt; atom '(' arguments ')'
| '(' subterm(1200) ')'
| '{' subterm(1200) '}'
| list
| string
| number
| atom
| variable
arguments ----&gt; subterm(999)
| subterm(999) ',' arguments
list ----&gt; '[]'
| '[' list_expr ']'
list_expr ----&gt; subterm(999)
| subterm(999) list_tail
list_tail ----&gt; ',' list_expr
| ',..' subterm(999)
| '|' subterm(999)
</code>
</pre></div>
<p>Notes:
</p>
<ul>
<li>
<i>op(N,T)</i> denotes an atom which has been previously declared with type
<i>T</i> and base precedence <i>N</i>.
</li><li>
Since &rsquo;,&rsquo; is itself a pre-declared operator with type <i>xfy</i> and
precedence 1000, is <i>subterm</i> starts with a &rsquo;(&rsquo;, <i>op</i> must be
followed by a space to avoid ambiguity with the case of a functor
followed by arguments, e.g.:
<div class="example">
<pre class="example"><code> + (a,b) [the same as '+'(','(a,b)) of arity one]</code>
</pre></div>
<p>versus
</p><div class="example">
<pre class="example"><code> +(a,b) [the same as '+'(a,b) of arity two]</code>
</pre></div>
</li><li>
In the first rule for term(0) no blank space should exist between
<i>atom</i> and &rsquo;(&rsquo;.
</li><li>
<a name="index-end-of-term"></a>
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.
</li></ul>
<hr>
<a name="Tokens"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Formal-Syntax" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Syntax" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Numbers" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Prolog-Tokens"></a>
<h2 class="section">3.2 Prolog Tokens</h2>
<a name="index-token"></a>
<p>Prolog tokens are grouped into the following categories:
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Numbers">3.2.1 Numbers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Integer and Floating-Point Numbers
</td></tr>
<tr><td align="left" valign="top"><a href="#Strings">3.2.2 Character Strings</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Sequences of Characters
</td></tr>
<tr><td align="left" valign="top"><a href="#Atoms">3.2.3 Atoms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Atomic Constants
</td></tr>
<tr><td align="left" valign="top"><a href="#Variables">3.2.4 Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Logical Variables
</td></tr>
<tr><td align="left" valign="top"><a href="#Punctuation-Tokens">3.2.5 Punctuation Tokens</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Tokens that separate other tokens
</td></tr>
<tr><td align="left" valign="top"><a href="#Layout">3.2.6 Layout</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Comments and Other Layout Rules
</td></tr>
</table>
<hr>
<a name="Numbers"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tokens" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tokens" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Integers" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Numbers-1"></a>
<h3 class="subsection">3.2.1 Numbers</h3>
<a name="index-number"></a>
<p>Numbers can be further subdivided into integer and floating-point numbers.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Integers">3.2.1.1 Integers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How Integers are read and represented
</td></tr>
<tr><td align="left" valign="top"><a href="#Floats">3.2.1.2 Floating-point Numbers</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Floating Point Numbers
</td></tr>
</table>
<hr>
<a name="Integers"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Numbers" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Numbers" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Floats" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Integers-1"></a>
<h4 class="subsubsection">3.2.1.1 Integers</h4>
<a name="index-integer"></a>
<p>Integer numbers
are described by the following regular expression:
</p>
<div class="example">
<pre class="example"><code>
&lt;integer&gt; := {&lt;digit&gt;+&lt;single-quote&gt;|0{xXo}}&lt;alpha_numeric_char&gt;+
</code>
</pre></div>
<p>where {...} stands for optionality, <i>+</i> optional repetition (one or
more times), <i>&lt;digit&gt;</i> denotes one of the characters 0 ... 9, <i>|</i>
denotes or, and <i>&lt;single-quote&gt;</i> denotes the character &quot;&rsquo;&quot;. The digits
before the <i>&lt;single-quote&gt;</i> character, when present, form the number
basis, that can go from 0, 1 and up to 36. Letters from <code>A</code> to
<code>Z</code> are used when the basis is larger than 10.
</p>
<p>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 &rsquo;e&rsquo;, &rsquo;E&rsquo;, or &rsquo;.&rsquo;.
</p>
<p>Following the ISO standard, YAP also accepts directives of the
form <code>0x</code> to represent numbers in hexadecimal base and of the form
<code>0o</code> to represent numbers in octal base. For usefulness,
YAP also accepts directives of the form <code>0X</code> to represent
numbers in hexadecimal base.
</p>
<p>Example:
the following tokens all denote the same integer
</p><div class="example">
<pre class="example"><code>10 2'1010 3'101 8'12 16'a 36'a 0xa 0o12</code>
</pre></div>
<p>Numbers of the form <code>0'a</code> are used to represent character
constants. So, the following tokens denote the same integer:
</p><div class="example">
<pre class="example"><code>0'd 100</code>
</pre></div>
<p>YAP (version 6.2.0) 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.
</p>
<hr>
<a name="Floats"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Integers" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Numbers" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Strings" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Floating_002dpoint-Numbers"></a>
<h4 class="subsubsection">3.2.1.2 Floating-point Numbers</h4>
<a name="index-floating_002dpoint-number"></a>
<p>Floating-point numbers are described by:
</p>
<div class="example">
<pre class="example"><code>
&lt;float&gt; := &lt;digit&gt;+{&lt;dot&gt;&lt;digit&gt;+}
&lt;exponent-marker&gt;{&lt;sign&gt;}&lt;digit&gt;+
|&lt;digit&gt;+&lt;dot&gt;&lt;digit&gt;+
{&lt;exponent-marker&gt;{&lt;sign&gt;}&lt;digit&gt;+}
</code>
</pre></div>
<p>where <i>&lt;dot&gt;</i> denotes the decimal-point character &rsquo;.&rsquo;,
<i>&lt;exponent-marker&gt;</i> denotes one of &rsquo;e&rsquo; or &rsquo;E&rsquo;, and <i>&lt;sign&gt;</i> denotes
one of &rsquo;+&rsquo; or &rsquo;-&rsquo;.
</p>
<p>Examples:
</p><div class="example">
<pre class="example"><code>10.0 10e3 10e-3 3.1415e+3</code>
</pre></div>
<p>Floating-point numbers are represented as a double in the target
machine. This is usually a 64-bit number.
</p>
<hr>
<a name="Strings"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Floats" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tokens" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Atoms" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Character-Strings"></a>
<h3 class="subsection">3.2.2 Character Strings</h3>
<a name="index-string"></a>
<p>Strings are described by the following rules:
</p><div class="example">
<pre class="example"> string --&gt; '&quot;' string_quoted_characters '&quot;'
string_quoted_characters --&gt; '&quot;' '&quot;' string_quoted_characters
string_quoted_characters --&gt; '\'
escape_sequence string_quoted_characters
string_quoted_characters --&gt;
string_character string_quoted_characters
escape_sequence --&gt; 'a' | 'b' | 'r' | 'f' | 't' | 'n' | 'v'
escape_sequence --&gt; '\' | '&quot;' | ''' | '`'
escape_sequence --&gt; at_most_3_octal_digit_seq_char '\'
escape_sequence --&gt; 'x' at_most_2_hexa_digit_seq_char '\'
</pre></div>
<p>where <code>string_character</code> in any character except the double quote
and escape characters.
</p>
<p>Examples:
</p><div class="example">
<pre class="example"><code>&quot;&quot; &quot;a string&quot; &quot;a double-quote:&quot;&quot;&quot; </code>
</pre></div>
<p>The first string is an empty string, the last string shows the use of
double-quoting. The implementation of YAP represents strings as
lists of integers. Since YAP 4.3.0 there is no static limit on string
size.
</p>
<p>Escape sequences can be used to include the non-printable characters
<code>a</code> (alert), <code>b</code> (backspace), <code>r</code> (carriage return),
<code>f</code> (form feed), <code>t</code> (horizontal tabulation), <code>n</code> (new
line), and <code>v</code> (vertical tabulation). Escape sequences also be
include the meta-characters <code>\</code>, <code>&quot;</code>, <code>'</code>, and
<code>`</code>. Last, one can use escape sequences to include the characters
either as an octal or hexadecimal number.
</p>
<p>The next examples demonstrates the use of escape sequences in YAP:
</p>
<div class="example">
<pre class="example"><code>&quot;\x0c\&quot; &quot;\01\&quot; &quot;\f&quot; &quot;\\&quot; </code>
</pre></div>
<p>The first three examples return a list including only character 12 (form
feed). The last example escapes the escape character.
</p>
<p>Escape sequences were not available in C-Prolog and in original
versions of YAP up to 4.2.0. Escape sequences can be disable by using:
</p><div class="example">
<pre class="example"><code>:- yap_flag(character_escapes,off).</code>
</pre></div>
<hr>
<a name="Atoms"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Strings" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tokens" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Variables" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Atoms-1"></a>
<h3 class="subsection">3.2.3 Atoms</h3>
<a name="index-atom"></a>
<p>Atoms are defined by one of the following rules:
</p><div class="example">
<pre class="example"> atom --&gt; solo-character
atom --&gt; lower-case-letter name-character*
atom --&gt; symbol-character+
atom --&gt; single-quote single-quote
atom --&gt; ''' atom_quoted_characters '''
atom_quoted_characters --&gt; ''' ''' atom_quoted_characters
atom_quoted_characters --&gt; '\' atom_sequence string_quoted_characters
atom_quoted_characters --&gt; character string_quoted_characters
</pre></div>
<p>where:
</p><div class="example">
<pre class="example"> &lt;solo-character&gt; denotes one of: ! ;
&lt;symbol-character&gt; denotes one of: # &amp; * + - . / : &lt;
= &gt; ? @ \ ^ ` ~
&lt;lower-case-letter&gt; denotes one of: a...z
&lt;name-character&gt; denotes one of: _ a...z A...Z 0....9
&lt;single-quote&gt; denotes: '
</pre></div>
<p>and <code>string_character</code> denotes any character except the double quote
and escape characters. Note that escape sequences in strings and atoms
follow the same rules.
</p>
<p>Examples:
</p><div class="example">
<pre class="example"><code>a a12x '$a' ! =&gt; '1 2'</code>
</pre></div>
<p>Version <code>4.2.0</code> 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.
</p>
<hr>
<a name="Variables"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Atoms" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tokens" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Punctuation-Tokens" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Variables-1"></a>
<h3 class="subsection">3.2.4 Variables</h3>
<a name="index-variable"></a>
<p>Variables are described by:
</p><div class="example">
<pre class="example"> &lt;variable-starter&gt;&lt;variable-character&gt;+
</pre></div>
<p>where
</p><div class="example">
<pre class="example"> &lt;variable-starter&gt; denotes one of: _ A...Z
&lt;variable-character&gt; denotes one of: _ a...z A...Z
</pre></div>
<a name="index-anonymous-variable"></a>
<p>If a variable is referred only once in a term, it needs not to be named
and one can use the character <code>_</code> to represent the variable. These
variables are known as anonymous variables. Note that different
occurrences of <code>_</code> on the same term represent <em>different</em>
anonymous variables.
</p>
<hr>
<a name="Punctuation-Tokens"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Variables" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tokens" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Layout" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Punctuation-Tokens-1"></a>
<h3 class="subsection">3.2.5 Punctuation Tokens</h3>
<a name="index-punctuation-token"></a>
<p>Punctuation tokens consist of one of the following characters:
</p><div class="example">
<pre class="example">( ) , [ ] { } |
</pre></div>
<p>These characters are used to group terms.
</p>
<hr>
<a name="Layout"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Punctuation-Tokens" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tokens" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Encoding" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Layout-1"></a>
<h3 class="subsection">3.2.6 Layout</h3>
<a name="index-comment"></a>
<p>Any characters with ASCII code less than or equal to 32 appearing before
a token are ignored.
</p>
<p>All the text appearing in a line after the character <i>%</i> is taken to
be a comment and ignored (including <i>%</i>). Comments can also be
inserted by using the sequence <code>/*</code> to start the comment and
<code>*/</code> 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.
</p>
<hr>
<a name="Encoding"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Layout" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Syntax" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Stream-Encoding" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Wide-Character-Support"></a>
<h2 class="section">3.3 Wide Character Support</h2>
<a name="index-encodings"></a>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Stream-Encoding">3.3.1 Wide character encodings on streams</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How Prolog Streams can be coded
</td></tr>
<tr><td align="left" valign="top"><a href="#BOM">3.3.2 BOM: Byte Order Mark</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The Byte Order Mark
</td></tr>
</table>
<a name="index-UTF_002d8"></a>
<a name="index-Unicode"></a>
<a name="index-UCS"></a>
<a name="index-internationalization"></a>
<p>YAP now implements a SWI-Prolog compatible interface to wide
characters and the Universal Character Set (UCS). The following text
was adapted from the SWI-Prolog manual.
</p>
<p>YAP now supports wide characters, characters with character
codes above 255 that cannot be represented in a single byte.
<em>Universal Character Set</em> (UCS) is the ISO/IEC 10646 standard
that specifies a unique 31-bits unsigned integer for any character in
any language. It is a superset of 16-bit Unicode, which in turn is
a superset of ISO 8859-1 (ISO Latin-1), a superset of US-ASCII. UCS
can handle strings holding characters from multiple languages and
character classification (uppercase, lowercase, digit, etc.) and
operations such as case-conversion are unambiguously defined.
</p>
<p>For this reason YAP, following SWI-Prolog, has two representations for
atoms. If the text fits in ISO Latin-1, it is represented as an array
of 8-bit characters. Otherwise the text is represented as an array of
wide chars, which may take 16 or 32 bits. This representational issue
is completely transparent to the Prolog user. Users of the foreign
language interface sometimes need to be aware of these issues though.
</p>
<p>Character coding comes into view when characters of strings need to be
read from or written to file or when they have to be communicated to
other software components using the foreign language interface. In this
section we only deal with I/O through streams, which includes file I/O
as well as I/O through network sockets.
</p>
<hr>
<a name="Stream-Encoding"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Encoding" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Encoding" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#BOM" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Wide-character-encodings-on-streams"></a>
<h3 class="subsection">3.3.1 Wide character encodings on streams</h3>
<p>Although characters are uniquely coded using the UCS standard
internally, streams and files are byte (8-bit) oriented and there are a
variety of ways to represent the larger UCS codes in an 8-bit octet
stream. The most popular one, especially in the context of the web, is
UTF-8. Bytes 0...127 represent simply the corresponding US-ASCII
character, while bytes 128...255 are used for multi-byte
encoding of characters placed higher in the UCS space. Especially on
MS-Windows the 16-bit Unicode standard, represented by pairs of bytes is
also popular.
</p>
<p>Prolog I/O streams have a property called <em>encoding</em> which
specifies the used encoding that influence <code>get_code/2</code> and
<code>put_code/2</code> as well as all the other text I/O predicates.
</p>
<p>The default encoding for files is derived from the Prolog flag
<code>encoding</code>, which is initialised from the environment. If the
environment variable <code>LANG</code> ends in &quot;UTF-8&quot;, this encoding is
assumed. Otherwise the default is <code>text</code> and the translation is
left to the wide-character functions of the C-library (note that the
Prolog native UTF-8 mode is considerably faster than the generic
<code>mbrtowc()</code> one). The encoding can be specified explicitly in
<code>load_files/2</code> for loading Prolog source with an alternative
encoding, <code>open/4</code> when opening files or using <code>set_stream/2</code> on
any open stream (not yet implemented). For Prolog source files we also
provide the <code>encoding/1</code> directive that can be used to switch
between encodings that are compatible to US-ASCII (<code>ascii</code>,
<code>iso_latin_1</code>, <code>utf8</code> and many locales).
For
additional information and Unicode resources, please visit
<a href="http://www.unicode.org/">http://www.unicode.org/</a>.
</p>
<p>YAP currently defines and supports the following encodings:
</p>
<dl compact="compact">
<dt><code>octet</code></dt>
<dd><p>Default encoding for <em>binary</em> streams. This causes
the stream to be read and written fully untranslated.
</p>
</dd>
<dt><code>ascii</code></dt>
<dd><p>7-bit encoding in 8-bit bytes. Equivalent to <code>iso_latin_1</code>,
but generates errors and warnings on encountering values above
127.
</p>
</dd>
<dt><code>iso_latin_1</code></dt>
<dd><p>8-bit encoding supporting many western languages. This causes
the stream to be read and written fully untranslated.
</p>
</dd>
<dt><code>text</code></dt>
<dd><p>C-library default locale encoding for text files. Files are read and
written using the C-library functions <code>mbrtowc()</code> and
<code>wcrtomb()</code>. This may be the same as one of the other locales,
notably it may be the same as <code>iso_latin_1</code> for western
languages and <code>utf8</code> in a UTF-8 context.
</p>
</dd>
<dt><code>utf8</code></dt>
<dd><p>Multi-byte encoding of full UCS, compatible to <code>ascii</code>.
See above.
</p>
</dd>
<dt><code>unicode_be</code></dt>
<dd><p>Unicode Big Endian. Reads input in pairs of bytes, most
significant byte first. Can only represent 16-bit characters.
</p>
</dd>
<dt><code>unicode_le</code></dt>
<dd><p>Unicode Little Endian. Reads input in pairs of bytes, least
significant byte first. Can only represent 16-bit characters.
</p></dd>
</dl>
<p>Note that not all encodings can represent all characters. This implies
that writing text to a stream may cause errors because the stream
cannot represent these characters. The behaviour of a stream on these
errors can be controlled using <code>open/4</code> or <code>set_stream/2</code> (not
implemented). Initially the terminal stream write the characters using
Prolog escape sequences while other streams generate an I/O exception.
</p>
<hr>
<a name="BOM"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Stream-Encoding" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Encoding" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="BOM_003a-Byte-Order-Mark"></a>
<h3 class="subsection">3.3.2 BOM: Byte Order Mark</h3>
<a name="index-BOM"></a>
<a name="index-Byte-Order-Mark"></a>
<p>From <a href="#Stream-Encoding">Wide character encodings on streams</a>, you may have got the impression text-files are
complicated. This section deals with a related topic, making live often
easier for the user, but providing another worry to the programmer.
<strong>BOM</strong> or <em>Byte Order Marker</em> is a technique for
identifying Unicode text-files as well as the encoding they use. Such
files start with the Unicode character <code>0xFEFF</code>, a non-breaking,
zero-width space character. This is a pretty unique sequence that is not
likely to be the start of a non-Unicode file and uniquely distinguishes
the various Unicode file formats. As it is a zero-width blank, it even
doesn&rsquo;t produce any output. This solves all problems, or ...
</p>
<p>Some formats start of as US-ASCII and may contain some encoding mark to
switch to UTF-8, such as the <code>encoding=&quot;UTF-8&quot;</code> in an XML header.
Such formats often explicitly forbid the the use of a UTF-8 BOM. In
other cases there is additional information telling the encoding making
the use of a BOM redundant or even illegal.
</p>
<p>The BOM is handled by the <code>open/4</code> predicate. By default, text-files are
probed for the BOM when opened for reading. If a BOM is found, the
encoding is set accordingly and the property <code>bom(true)</code> is
available through <code>stream_property/2</code>. When opening a file for
writing, writing a BOM can be requested using the option
<code>bom(true)</code> with <code>open/4</code>.
</p>
<hr>
<a name="Loading-Programs"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Syntax" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#BOM" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Compiling" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Loading-Programs-1"></a>
<h1 class="chapter">4 Loading Programs</h1>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Loading Programs
</pre></th></tr><tr><td align="left" valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Program Loading and Updating
</td></tr>
<tr><td align="left" valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Changing the compiler&rsquo;s parameters
</td></tr>
<tr><td align="left" valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Compiling program fragments
</td></tr>
<tr><td align="left" valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Saving and Restoring Programs
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
</pre></th></tr></table>
<hr>
<a name="Compiling"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Loading-Programs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Setting-the-Compiler" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Program-loading-and-updating"></a>
<h2 class="section">4.1 Program loading and updating</h2>
<dl compact="compact">
<dt><code>consult(<var>+F</var>)</code></dt>
<dd><a name="index-consult_002f1"></a>
<a name="index-consult_002f1-1"></a>
<a name="index-consult_002f1-2"></a>
<p>Adds the clauses written in file <var>F</var> or in the list of files <var>F</var>
to the program.
</p>
<p>In YAP <code>consult/1</code> does not remove previous clauses for
the procedures defined in <var>F</var>. Moreover, note that all code in YAP
is compiled.
</p>
</dd>
<dt><code>reconsult(<var>+F</var>)</code></dt>
<dd><a name="index-reconsult_002f1"></a>
<a name="index-reconsult_002f1-1"></a>
<a name="index-reconsult_002f1-2"></a>
<p>Updates the program replacing the
previous definitions for the predicates defined in <var>F</var>.
</p>
</dd>
<dt><code>[<var>+F</var>]</code></dt>
<dd><a name="index-_005b_005d_002f1"></a>
<a name="index-_005b_005d_002f1-1"></a>
<a name="index-_005b_005d_002f1-2"></a>
<p>The same as <code>consult(F)</code>.
</p>
</dd>
<dt><code>[-<var>+F</var>]</code></dt>
<dd><a name="index-_005b_002d_005d_002f1"></a>
<a name="index-_005b_002d_005d_002f1-1"></a>
<a name="index-_005b_002d_005d_002f1-2"></a>
<p>The same as <code>reconsult(F)</code>
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">?- [file1, -file2, -file3, file4].
</pre></div>
<p>will consult <code>file1</code> <code>file4</code> and reconsult <code>file2</code> and
<code>file3</code>.
</p>
</dd>
<dt><code>compile(<var>+F</var>)</code></dt>
<dd><a name="index-compile_002f1"></a>
<a name="index-compile_002f1-1"></a>
<a name="index-compile_002f1-2"></a>
<p>In YAP, the same as <code>reconsult/1</code>.
</p>
</dd>
<dt><code>load_files(<var>+Files</var>, <var>+Options</var>)</code></dt>
<dd><a name="index-load_005ffiles_002f2"></a>
<a name="index-load_005ffiles_002f2-1"></a>
<a name="index-load_005ffiles_002f2-2"></a>
<p>General implementation of <code>consult</code>. Execution is controlled by the
following flags:
</p>
<dl compact="compact">
<dt><code>autoload(+<var>Autoload</var>)</code></dt>
<dd><p>SWI-compatible option where if <var>Autoload</var> is <code>true</code> predicates
are loaded on first call. Currently
not supported.
</p></dd>
<dt><code>derived_from(+<var>File</var>)</code></dt>
<dd><p> SWI-compatible option to control make. Currently
not supported.
</p></dd>
<dt><code>encoding(+<var>Encoding</var>)</code></dt>
<dd><p>Character encoding used in consulting files. Please see section <a href="#Encoding">Wide Character Support</a> for
supported encodings.
</p>
</dd>
<dt><code>expand(+<var>Bool</var>)</code></dt>
<dd><p> Not yet implemented. In SWI-Prolog, if <code>true</code>, run the
filenames through <code>expand_file_name/2</code> and load the returned
files. Default is false, except for <code>consult/1</code> which is
intended for interactive use.
</p>
</dd>
<dt><code>if(+<var>Condition</var>)</code></dt>
<dd><p> Load the file only if the specified <var>Condition</var> is
satisfied. The value <code>true</code> the file unconditionally,
<code>changed</code> loads the file if it was not loaded before, or has
been modified since it was loaded the last time, <code>not_loaded</code>
loads the file if it was not loaded before.
</p>
</dd>
<dt><code>imports(+<var>ListOrAll</var>)</code></dt>
<dd><p> If <code>all</code> and the file is a module file, import all public
predicates. Otherwise import only the named predicates. Each
predicate is referred to as <code>&lt;name&gt;/&lt;arity&gt;</code>. This option has
no effect if the file is not a module file.
</p>
</dd>
<dt><code>must_be_module(+<var>Bool</var>)</code></dt>
<dd><p> If true, raise an error if the file is not a module file. Used by
<code>use_module/[1,2]</code>.
</p>
</dd>
<dt><code>silent(+<var>Bool</var>)</code></dt>
<dd><p> If true, load the file without printing a message. The specified value is the default for all files loaded as a result of loading the specified files.
</p>
</dd>
<dt><code>stream(+<var>Input</var>)</code></dt>
<dd><p> This SWI-Prolog extension compiles the data from the stream
<var>Input</var>. If this option is used, <var>Files</var> must be a single
atom which is used to identify the source-location of the loaded
clauses as well as remove all clauses if the data is re-consulted.
</p>
<p> This option is added to allow compiling from non-file locations such as databases, the web, the user (see consult/1) or other servers.
</p>
</dd>
<dt><code>compilation_mode(+<var>Mode</var>)</code></dt>
<dd><p> This extension controls how procedures are compiled. If <var>Mode</var>
is <code>compact</code> clauses are compiled and no source code is stored;
if it is <code>source</code> clauses are compiled and source code is stored;
if it is <code>assert_all</code> clauses are asserted into the data-base.
</p></dd>
</dl>
</dd>
<dt><code>ensure_loaded(<var>+F</var>) [ISO]</code></dt>
<dd><a name="index-ensure_005floaded_002f1"></a>
<a name="index-compile_002f1-3"></a>
<a name="index-compile_002f1-4"></a>
<p>When the files specified by <var>F</var> are module files,
<code>ensure_loaded/1</code> loads them if they have note been previously
loaded, otherwise advertises the user about the existing name clashes
and prompts about importing or not those predicates. Predicates which
are not public remain invisible.
</p>
<p>When the files are not module files, <code>ensure_loaded/1</code> loads them
if they have not been loaded before, does nothing otherwise.
</p>
<p><var>F</var> must be a list containing the names of the files to load.
</p>
</dd>
<dt><code>make</code></dt>
<dd><a name="index-make_002f0"></a>
<a name="index-make_002f0-1"></a>
<a name="index-make_002f0-2"></a>
<p> SWI-Prolog built-in to consult all source files that have been
changed since they were consulted. It checks all loaded source
files. make/0 can be combined with the compiler to speed up the
development of large packages. In this case compile the package
using
</p>
<div class="example">
<pre class="example"> sun% pl -g make -o my_program -c file ...
</pre></div>
<p> If &lsquo;my_program&rsquo; is started it will first reconsult all source files
that have changed since the compilation.
</p>
</dd>
<dt><code>include(<var>+F</var>) [ISO]</code></dt>
<dd><a name="index-include_002f1-_0028directive_0029"></a>
<a name="index-compile_002f1-_0028directive_0029"></a>
<a name="index-compile_002f1-_0028directive_0029-1"></a>
<p>The <code>include</code> directive includes the text files or sequence of text
files specified by <var>F</var> into the file being currently consulted.
</p>
</dd>
</dl>
<hr>
<a name="Setting-the-Compiler"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Loading-Programs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Compiling" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Conditional-Compilation" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Changing-the-Compiler_0027s-Behavior"></a>
<h2 class="section">4.2 Changing the Compiler&rsquo;s Behavior</h2>
<p>This section presents a set of built-ins predicates designed to set the
environment for the compiler.
</p>
<dl compact="compact">
<dt><code>source_mode(-<var>O</var>,+<var>N</var>)</code></dt>
<dd><a name="index-source_005fmode_002f2"></a>
<a name="index-source_005fmode_002f2-1"></a>
<a name="index-source_005fmode_002f2-2"></a>
<p>The state of source mode can either be on or off. When the source mode
is on, all clauses are kept both as compiled code and in a &quot;hidden&quot;
database. <var>O</var> is unified with the previous state and the mode is set
according to <var>N</var>.
</p>
</dd>
<dt><code>source</code></dt>
<dd><a name="index-source_002f0"></a>
<a name="index-source_002f0-1"></a>
<a name="index-source_002f0-2"></a>
<p>After executing this goal, YAP keeps information on the source
of the predicates that will be consulted. This enables the use of
<code>listing/0</code>, <code>listing/1</code> and <code>clause/2</code> for those
clauses.
</p>
<p>The same as <code>source_mode(_,on)</code> or as declaring all newly defined
static procedures as <code>public</code>.
</p>
</dd>
<dt><code>no_source</code></dt>
<dd><a name="index-no_005fsource_002f0"></a>
<a name="index-no_005fsource_002f0-1"></a>
<a name="index-no_005fsource_002f0-2"></a>
<p>The opposite to <code>source</code>.
</p>
<p>The same as <code>source_mode(_,off)</code>.
</p>
</dd>
<dt><code>compile_expressions</code></dt>
<dd><a name="index-compile_005fexpressions_002f0"></a>
<a name="index-compile_005fexpressions_002f0-1"></a>
<a name="index-compile_005fexpressions_002f0-2"></a>
<p>After a call to this predicate, arithmetical expressions will be compiled.
(see example below). This is the default behavior.
</p>
</dd>
<dt><code>do_not_compile_expressions</code></dt>
<dd><a name="index-do_005fnot_005fcompile_005fexpressions_002f0"></a>
<a name="index-do_005fnot_005fcompile_005fexpressions_002f0-1"></a>
<a name="index-do_005fnot_005fcompile_005fexpressions_002f0-2"></a>
<p>After a call to this predicate, arithmetical expressions will not be compiled.
</p><div class="example">
<pre class="example">?- 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.
</pre></div>
</dd>
<dt><code>hide(+<var>Atom</var>)</code></dt>
<dd><a name="index-hide_002f1"></a>
<a name="index-hide_002f1-1"></a>
<a name="index-hide_002f1-2"></a>
<p>Make atom <var>Atom</var> invisible.
</p>
</dd>
<dt><code>unhide(+<var>Atom</var>)</code></dt>
<dd><a name="index-unhide_002f1"></a>
<a name="index-unhide_002f1-1"></a>
<a name="index-unhide_002f1-2"></a>
<p>Make hidden atom <var>Atom</var> visible.
</p>
</dd>
<dt><code>hide_predicate(+<var>Pred</var>)</code></dt>
<dd><a name="index-hide_005fpredicate_002f1"></a>
<a name="index-hide_005fpredicate_002f1-1"></a>
<a name="index-hide_005fpredicate_002f1-2"></a>
<p>Make predicate <var>Pred</var> invisible to <code>current_predicate/2</code>,
<code>listing</code>, and friends.
</p>
</dd>
<dt><code>expand_exprs(-<var>O</var>,+<var>N</var>)</code></dt>
<dd><a name="index-expand_005fexprs_002f2"></a>
<a name="index-expand_005fexprs_002f2-1"></a>
<a name="index-expand_005fexprs_002f2-2"></a>
<p>Puts YAP in state <var>N</var> (<code>on</code> or <code>off</code>) and unify
<var>O</var> with the previous state, where <var>On</var> is equivalent to
<code>compile_expressions</code> and <code>off</code> is equivalent to
<code>do_not_compile_expressions</code>. This predicate was kept to maintain
compatibility with C-Prolog.
</p>
</dd>
<dt><code>path(-<var>D</var>)</code></dt>
<dd><a name="index-path_002f1"></a>
<a name="index-path_002f1-1"></a>
<a name="index-path_002f1-2"></a>
<p>Unifies <var>D</var> with the current directory search-path of YAP.
Note that this search-path is only used by YAP to find the
files for <code>consult/1</code>, <code>reconsult/1</code> and <code>restore/1</code> and
should not be taken for the system search path.
</p>
</dd>
<dt><code>add_to_path(+<var>D</var>)</code></dt>
<dd><a name="index-add_005fto_005fpath_002f1"></a>
<a name="index-path_002f1-3"></a>
<a name="index-path_002f1-4"></a>
<p>Adds <var>D</var> to the end of YAP&rsquo;s directory search path.
</p>
</dd>
<dt><code>add_to_path(+<var>D</var>,+<var>N</var>)</code></dt>
<dd><a name="index-add_005fto_005fpath_002f2"></a>
<a name="index-path_002f1-5"></a>
<a name="index-path_002f1-6"></a>
<p>Inserts <var>D</var> in the position, of the directory search path of
YAP, specified by <var>N</var>. <var>N</var> must be either of
<code>first</code> or <code>last</code>.
</p>
</dd>
<dt><code>remove_from_path(+<var>D</var>)</code></dt>
<dd><a name="index-remove_005ffrom_005fpath_002f1"></a>
<a name="index-remove_005ffrom_005fpath_002f1-1"></a>
<a name="index-remove_005ffrom_005fpath_002f1-2"></a>
<p>Remove <var>D</var> from YAP&rsquo;s directory search path.
</p>
</dd>
<dt><code>style_check(+<var>X</var>)</code></dt>
<dd><a name="index-style_005fcheck_002f1"></a>
<a name="index-style_005fcheck_002f1-1"></a>
<a name="index-style_005fcheck_002f1-2"></a>
<p>Turns on style checking according to the attribute specified by <var>X</var>,
which must be one of the following:
</p><dl compact="compact">
<dt><code>single_var</code></dt>
<dd><p>Checks single occurrences of named variables in a clause.
</p></dd>
<dt><code>discontiguous</code></dt>
<dd><p>Checks non-contiguous clauses for the same predicate in a file.
</p></dd>
<dt><code>multiple</code></dt>
<dd><p>Checks the presence of clauses for the same predicate in more than one
file when the predicate has not been declared as <code>multifile</code>
</p></dd>
<dt><code>all</code></dt>
<dd><p>Performs style checking for all the cases mentioned above.
</p></dd>
</dl>
<p>By default, style checking is disabled in YAP unless we are in
<code>sicstus</code> or <code>iso</code> language mode.
</p>
<p>The <code>style_check/1</code> built-in is now deprecated. Please use the
<code>set_prolog_flag/1</code> instead.
</p>
</dd>
<dt><code>no_style_check(+<var>X</var>)</code></dt>
<dd><a name="index-no_005fstyle_005fcheck_002f1"></a>
<a name="index-style_005fcheck_002f1-3"></a>
<a name="index-style_005fcheck_002f1-4"></a>
<p>Turns off style checking according to the attribute specified by
<var>X</var>, which has the same meaning as in <code>style_check/1</code>.
</p>
<p>The <code>no_style_check/1</code> built-in is now deprecated. Please use the
<code>set_prolog_flag/1</code> instead.
</p>
</dd>
<dt><code>multifile <var>P</var> [ISO]</code></dt>
<dd><a name="index-multifile_002f1-_0028directive_0029"></a>
<a name="index-multifile_002f1-_0028directive_0029-1"></a>
<a name="index-multifile_002f1-_0028directive_0029-2"></a>
<p>Instructs the compiler about the declaration of a predicate <var>P</var> 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.
</p>
<p>Multifile declarations affect <code>reconsult/1</code> and <code>compile/1</code>:
when a multifile predicate is reconsulted, only the clauses from the
same file are removed.
</p>
<p>Since YAP4.3.0 multifile procedures can be static or dynamic.
</p>
</dd>
<dt><code>discontiguous(+<var>G</var>) [ISO]</code></dt>
<dd><a name="index-discontiguous_002f1-_0028directive_0029"></a>
<a name="index-discontiguous_002f1-_0028directive_0029-1"></a>
<a name="index-discontiguous_002f1-_0028directive_0029-2"></a>
<p>Declare that the arguments are discontiguous procedures, that is,
clauses for discontigous procedures may be separated by clauses from
other procedures.
</p>
</dd>
<dt><code>initialization(+<var>G</var>) [ISO]</code></dt>
<dd><a name="index-initialization_002f1-_0028directive_0029"></a>
<a name="index-initialization_002f1-_0028directive_0029-1"></a>
<a name="index-initialization_002f1-_0028directive_0029-2"></a>
<p>The compiler will execute goals <var>G</var> after consulting the current
file.
</p>
</dd>
<dt><code>initialization(+<var>Goal</var>,+<var>When</var>)</code></dt>
<dd><a name="index-initialization_002f2-_0028directive_0029"></a>
<a name="index-initialization_002f2-_0028directive_0029-1"></a>
<a name="index-initialization_002f2-_0028directive_0029-2"></a>
<p>Similar to <code>initialization/1</code>, but allows for specifying when
<var>Goal</var> is executed while loading the program-text:
</p>
<dl compact="compact">
<dt><code>now</code></dt>
<dd><p> Execute <var>Goal</var> immediately.
</p></dd>
<dt><code>after_load</code></dt>
<dd><p> Execute <var>Goal</var> after loading program-text. This is the same as initialization/1.
</p></dd>
<dt><code>restore</code></dt>
<dd><p> Do not execute <var>Goal</var> while loading the program, but only when
restoring a state (not implemented yet).
</p></dd>
</dl>
</dd>
<dt><code>library_directory(+<var>D</var>)</code></dt>
<dd><a name="index-library_005fdirectory_002f1"></a>
<a name="index-library_005fdirectory_002f1-1"></a>
<a name="index-library_005fdirectory_002f1-2"></a>
<p>Succeeds when <var>D</var> is a current library directory name. Library
directories are the places where files specified in the form
<code>library(<var>File</var>)</code> are searched by the predicates
<code>consult/1</code>, <code>reconsult/1</code>, <code>use_module/1</code> or
<code>ensure_loaded/1</code>.
</p>
</dd>
<dt><code>file_search_path(+<var>NAME</var>,-<var>DIRECTORY</var>)</code></dt>
<dd><a name="index-file_005fsearch_005fpath_002f2"></a>
<a name="index-file_005fsearch_005fpath_002f2-1"></a>
<a name="index-file_005fsearch_005fpath_002f2-2"></a>
<p>Allows writing file names as compound terms. The <var>NAME</var> and
<var>DIRECTORY</var> must be atoms. The predicate may generate multiple
solutions. The predicate is originally defined as follows:
</p>
<div class="example">
<pre class="example">file_search_path(library,A) :-
library_directory(A).
file_search_path(system,A) :-
prolog_flag(host_type,A).
</pre></div>
<p>Thus, <code>[library(A)]</code> will search for a file using
<code>library_directory/1</code> to obtain the prefix.
</p>
</dd>
<dt><code>library_directory(+<var>D</var>)</code></dt>
<dd><a name="index-library_005fdirectory_002f1-3"></a>
<a name="index-library_005fdirectory_002f1-4"></a>
<a name="index-library_005fdirectory_002f1-5"></a>
<p>Succeeds when <var>D</var> is a current library directory name. Library
directories are the places where files specified in the form
<code>library(<var>File</var>)</code> are searched by the predicates
<code>consult/1</code>, <code>reconsult/1</code>, <code>use_module/1</code> or
<code>ensure_loaded/1</code>.
</p>
</dd>
<dt><code>prolog_file_name(+<var>Name</var>,-<var>FullPath</var>)</code></dt>
<dd><a name="index-prolog_005ffile_005fname_002f2"></a>
<a name="index-prolog_005ffile_005fname_002f1"></a>
<a name="index-prolog_005ffile_005fname_002f2-1"></a>
<p>Unify <var>FullPath</var> with the absolute path YAP would use to consult
file <var>Name</var>.
</p>
</dd>
<dt><code>public <var>P</var> [ISO extension]</code></dt>
<dd><a name="index-public_002f1-_0028directive_0029"></a>
<a name="index-public_002f1-_0028directive_0029-1"></a>
<a name="index-public_002f1-_0028directive_0029-2"></a>
<p>Instructs the compiler that the source of a predicate of a list of
predicates <var>P</var> must be kept. This source is then accessible through
the <code>clause/2</code> procedure and through the <code>listing</code> family of
built-ins.
</p>
<p>Note that all dynamic procedures are public. The <code>source</code> directive
defines all new or redefined predicates to be public.
</p>
<p>Since YAP4.3.0 multifile procedures can be static or dynamic.
</p>
</dd>
</dl>
<hr>
<a name="Conditional-Compilation"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Loading-Programs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Setting-the-Compiler" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Saving" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Conditional-Compilation-1"></a>
<h2 class="section">4.3 Conditional Compilation</h2>
<p>Conditional compilation builds on the same principle as
<code>term_expansion/2</code>, <code>goal_expansion/2</code> and the expansion of
grammar rules to compile sections of the source-code
conditionally. One of the reasons for introducing conditional
compilation is to simplify writing portable code.
</p>
<p>Note that these directives can only be appear as separate terms in the
input. Typical usage scenarios include:
</p>
<ul>
<li> Load different libraries on different dialects
</li><li> Define a predicate if it is missing as a system predicate
</li><li> Realise totally different implementations for a particular
part of the code due to different capabilities.
</li><li> Realise different configuration options for your software.
</li></ul>
<dl compact="compact">
<dt><code>if(+<var>Goal</var>)</code></dt>
<dd><a name="index-if_002f1-directive"></a>
<a name="index-if_002f1"></a>
<a name="index-if_002f1-1"></a>
<p>Compile subsequent code only if <var>Goal</var> succeeds. For enhanced
portability, <var>Goal</var> is processed by <code>expand_goal/2</code> before execution.
If an error occurs, the error is printed and processing proceeds as if
<var>Goal</var> has failed.
</p>
</dd>
<dt><code>else</code></dt>
<dd><a name="index-else_002f0-directive"></a>
<a name="index-else_002f0"></a>
<a name="index-else_002f0-1"></a>
<p>Start &lsquo;else&rsquo; branch.
</p>
</dd>
<dt><code>endif</code></dt>
<dd><a name="index-endif_002f0-directive"></a>
<a name="index-endif_002f0"></a>
<a name="index-endif_002f0-1"></a>
<p>End of conditional compilation.
</p>
</dd>
<dt><code>elif(+<var>Goal</var>)</code></dt>
<dd><a name="index-elif_002f1-directive"></a>
<a name="index-elif_002f1"></a>
<a name="index-elif_002f1-1"></a>
<p>Equivalent to <code>:- else. :-if(Goal) ... :- endif.</code> In a sequence
as below, the section below the first matching elif is processed, If
no test succeeds the else branch is processed.
</p>
<div class="example">
<pre class="example">:- if(test1).
section_1.
:- elif(test2).
section_2.
:- elif(test3).
section_3.
:- else.
section_else.
:- endif.
</pre></div>
</dd>
</dl>
<hr>
<a name="Saving"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Loading-Programs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Conditional-Compilation" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Programs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Saving-and-Loading-Prolog-States"></a>
<h2 class="section">4.4 Saving and Loading Prolog States</h2>
<dl compact="compact">
<dt><code>save(+<var>F</var>)</code></dt>
<dd><a name="index-save_002f1"></a>
<a name="index-save_002f1-1"></a>
<a name="index-save_002f1-2"></a>
<p>Saves an image of the current state of YAP in file <var>F</var>. From
<strong>YAP4.1.3</strong> onwards, YAP saved states are executable
files in the Unix ports.
</p>
</dd>
<dt><code>save(+<var>F</var>,-<var>OUT</var>)</code></dt>
<dd><a name="index-save_002f2"></a>
<a name="index-save_002f2-1"></a>
<a name="index-save_002f2-2"></a>
<p>Saves an image of the current state of YAP in file <var>F</var>. From
<strong>YAP4.1.3</strong> onwards, YAP saved states are executable
files in the Unix ports.
</p>
<p>Unify <var>OUT</var> with 1 when saving the file and <var>OUT</var> with 0 when
restoring the saved state.
</p>
</dd>
<dt><code>save_program(+<var>F</var>)</code></dt>
<dd><a name="index-save_005fprogram_002f1"></a>
<a name="index-save_005fprogram_002f1-1"></a>
<a name="index-save_005fprogram_002f1-2"></a>
<p>Saves an image of the current state of the YAP database in file
<var>F</var>.
</p>
</dd>
<dt><code>save_program(+<var>F</var>, :<var>G</var>)</code></dt>
<dd><a name="index-save_005fprogram_002f2"></a>
<a name="index-save_005fprogram_002f2-1"></a>
<a name="index-save_005fprogram_002f2-2"></a>
<p>Saves an image of the current state of the YAP database in file
<var>F</var>, and guarantee that execution of the restored code will start by
trying goal <var>G</var>.
</p>
</dd>
<dt><code>restore(+<var>F</var>)</code></dt>
<dd><a name="index-restore_002f1"></a>
<a name="index-restore_002f1-1"></a>
<a name="index-restore_002f1-2"></a>
<p>Restores a previously saved state of YAP from file <var>F</var>.
</p>
<p>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.
</p></dd>
</dl>
<hr>
<a name="Modules"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Loading-Programs" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Saving" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Module-Concepts" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="The-Module-System"></a>
<h1 class="chapter">5 The Module System</h1>
<p>Module systems are quite important for the development of large
applications. YAP implements a module system compatible with the Quintus
Prolog module system.
</p>
<p>The YAP module system is predicate-based. This means a module consists
of a set of predicates (or procedures), such that some predicates are
public and the others are local to a module. Atoms and terms in general
are global to the system. Moreover, the module system is flat, meaning
that we do not support a hierarchy of modules. Modules can
automatically import other modules, though. For compatibility with other
module systems the YAP module system is non-strict, meaning both that
there is a way to access predicates private to a module and that it
is possible to declare predicates for a module from some other module.
</p>
<p>YAP allows one to ignore the module system if one does not want to use
it. Last note that using the module system does not introduce any
significant overheads.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Module-Concepts">5.1 Module Concepts</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The Key Ideas in Modules
</td></tr>
<tr><td align="left" valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How To Define a New Module
</td></tr>
<tr><td align="left" valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How to Use a Module
</td></tr>
<tr><td align="left" valign="top"><a href="#Meta_002dPredicates-in-Modules">5.4 Meta-Predicates in Modules</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How to Handle New Meta-Predicates
</td></tr>
<tr><td align="left" valign="top"><a href="#Re_002dExporting-Modules">5.5 Re-Exporting Predicates From Other Modules</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How to Re-export Predicates From Other Modules
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
</pre></th></tr></table>
<hr>
<a name="Module-Concepts"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Defining-Modules" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Module-Concepts-1"></a>
<h2 class="section">5.1 Module Concepts</h2>
<p>The YAP module system applies to predicates. All predicates belong to a
module. System predicates belong to the module <code>primitives</code>, and by
default new predicates belong to the module <code>user</code>. Predicates from
the module <code>primitives</code> are automatically visible to every module.
</p>
<p>Every predicate must belong to a module. This module is called its
<em>source module</em>.
</p>
<p>By default, the source module for a clause occurring in a source file
with a module declaration is the declared module. For goals typed in
a source file without module declarations, their module is the module
the file is being loaded into. If no module declarations exist, this is
the current <em>type-in module</em>. The default type-in module is
<code>user</code>, but one can set the current module by using the built-in
<code>module/1</code>.
</p>
<p>Note that in this module system one can explicitly specify the source
mode for a clause by prefixing a clause with its module, say:
</p><div class="example">
<pre class="example">user:(a :- b).
</pre></div>
<p>In fact, to specify the source module for a clause it is sufficient to
specify the source mode for the clause&rsquo;s head:
</p><div class="example">
<pre class="example">user:a :- b.
</pre></div>
<p>The rules for goals are similar. If a goal appears in a text file with a
module declaration, the goal&rsquo;s source module is the declared
module. Otherwise, it is the module the file is being loaded into or the
type-in module.
</p>
<p>One can override this rule by prefixing a goal with the module it is
supposed to be executed in, say:
</p><div class="example">
<pre class="example">nasa:launch(apollo,13).
</pre></div>
<p>will execute the goal <code>launch(apollo,13)</code> as if the current source
module was <code>nasa</code>.
</p>
<p>Note that this rule breaks encapsulation and should be used with care.
</p>
<hr>
<a name="Defining-Modules"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Module-Concepts" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Using-Modules" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Defining-a-New-Module"></a>
<h2 class="section">5.2 Defining a New Module</h2>
<p>A new module is defined by a <code>module</code> declaration:
</p>
<dl compact="compact">
<dt><code>module(+<var>M</var>,+<var>L</var>)</code></dt>
<dd><a name="index-module_002f2-_0028directive_0029"></a>
<a name="index-module_002f2-_0028directive_0029-1"></a>
<a name="index-module_002f2-_0028directive_0029-2"></a>
<p>This directive defines the file where it appears as a module file; it
must be the first declaration in the file.
<var>M</var> must be an atom specifying the module name; <var>L</var> must be a list
containing the module&rsquo;s public predicates specification, in the form
<code>[predicate_name/arity,...]</code>.
</p>
<p>The public predicates of a module file can be made accessible by other
files through the directives <code>use_module/1</code>, <code>use_module/2</code>,
<code>ensure_loaded/1</code> and the predicates <code>consult/1</code> or
<code>reconsult/1</code>. The non-public predicates
of a module file are not visible by other files; they can, however, be
accessed by prefixing the module name with the
<code>:/2</code> operator.
</p>
</dd>
</dl>
<p>The built-in <code>module/1</code> sets the current source module:
</p><dl compact="compact">
<dt><code>module(+<var>M</var>,+<var>L</var>, +<var>Options</var>)</code></dt>
<dd><a name="index-module_002f3-_0028directive_0029"></a>
<a name="index-module_002f3-_0028directive_0029-1"></a>
<a name="index-module_002f3-_0028directive_0029-2"></a>
<p>Similar to <code>module/2</code>, this directive defines the file where it
appears in as a module file; it must be the first declaration in the file.
<var>M</var> must be an atom specifying the module name; <var>L</var> must be a
list containing the module&rsquo;s public predicates specification, in the
form <code>[predicate_name/arity,...]</code>.
</p>
<p>The last argument <var>Options</var> must be a list of options, which can be:
</p>
<dl compact="compact">
<dt><code>filename</code></dt>
<dd><p> the filename for a module to import into the current module.
</p>
</dd>
<dt><code>library(file)</code></dt>
<dd><p> a library file to import into the current module.
</p>
</dd>
<dt><code>hide(<var>Opt</var>)</code></dt>
<dd><p> if <var>Opt</var> is <code>false</code>, keep source code for current module, if
<code>true</code>, disable.
</p></dd>
</dl>
</dd>
<dt><code>module(+<var>M</var>)</code></dt>
<dd><a name="index-module_002f1"></a>
<a name="index-module_002f1-1"></a>
<a name="index-module_002f1-2"></a>
<p>Defines <var>M</var> to be the current working or type-in module. All files
which are not bound 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 <code><var>Module</var>:<var>File</var></code>, when
loading the file.
</p>
</dd>
</dl>
<hr>
<a name="Using-Modules"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Defining-Modules" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Meta_002dPredicates-in-Modules" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Using-Modules-1"></a>
<h2 class="section">5.3 Using Modules</h2>
<p>By default, all procedures to consult a file will load the modules
defined therein. The two following declarations allow one to import a
module explicitly. They differ on whether one imports all predicate
declared in the module or not.
</p>
<dl compact="compact">
<dt><code>use_module(+<var>F</var>)</code></dt>
<dd><a name="index-use_005fmodule_002f1"></a>
<a name="index-use_005fmodule_002f1-1"></a>
<a name="index-use_005fmodule_002f1-2"></a>
<p>Loads the files specified by <var>F</var>, importing all their public
predicates. Predicate name clashes are resolved by asking the user about
importing or not the predicate. A warning is displayed when <var>F</var> is
not a module file.
</p>
</dd>
<dt><code>use_module(+<var>F</var>,+<var>L</var>)</code></dt>
<dd><a name="index-use_005fmodule_002f2"></a>
<a name="index-use_005fmodule_002f2-1"></a>
<a name="index-use_005fmodule_002f2-2"></a>
<p>Loads the files specified by <var>F</var>, importing the predicates specified
in the list <var>L</var>. Predicate name clashes are resolved by asking the
user about importing or not the predicate. A warning is displayed when
<var>F</var> is not a module file.
</p>
</dd>
<dt><code>use_module(?<var>M</var>,?<var>F</var>,+<var>L</var>)</code></dt>
<dd><a name="index-use_005fmodule_002f3"></a>
<a name="index-use_005fmodule_002f3-1"></a>
<a name="index-use_005fmodule_002f3-2"></a>
<p>If module <var>M</var> has been defined, import the procedures in <var>L</var> to
the current module. Otherwise, load the files specified by <var>F</var>,
importing the predicates specified in the list <var>L</var>.
</p></dd>
</dl>
<hr>
<a name="Meta_002dPredicates-in-Modules"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Using-Modules" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Re_002dExporting-Modules" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Meta_002dPredicates-in-Modules-1"></a>
<h2 class="section">5.4 Meta-Predicates in Modules</h2>
<p>The module system must know whether predicates operate on goals or
clauses. Otherwise, such predicates would call a goal in the module they
were defined, instead of calling it in the module they are currently
executing. So, for instance, consider a file example.pl:
</p><div class="example">
<pre class="example">:- module(example,[a/1]).
a(G) :- call(G)
</pre></div>
<p>We import this module with <code>use_module(example)</code> into module
<code>user</code>. The expected behavior for a goal <code>a(p)</code> is to
execute goal <code>p</code> within the module <code>user</code>. However,
<code>a/1</code> will call <code>p</code> within module <code>example</code>.
</p>
<p>The <code>meta_predicate/1</code> declaration informs the system that some
arguments of a predicate are goals, clauses, clauses heads or other
terms related to a module, and that these arguments must be prefixed
with the current source module:
</p>
<dl compact="compact">
<dt><code>meta_predicate <var>G1</var>,....,<var>Gn</var></code></dt>
<dd><a name="index-meta_005fpredicate_002f1-_0028directive_0029"></a>
<a name="index-meta_005fpredicate_002f1-_0028directive_0029-1"></a>
<a name="index-meta_005fpredicate_002f1-_0028directive_0029-2"></a>
<p>Each <var>Gi</var> is a mode specification.
</p>
<p>If the argument is <code>:</code> or an integer, the argument is a call and
must be expanded. Otherwise, the argument is not expanded. Note
that the system already includes declarations for all built-ins.
</p>
<p>For example, the declaration for <code>call/1</code> and <code>setof/3</code> are:
</p>
<div class="example">
<pre class="example">:- meta_predicate call(:), setof(?,:,?).
</pre></div>
</dd>
</dl>
<p>The previous example is expanded to the following code which explains,
why the goal <code>a(p)</code> calls <code>p</code> in <code>example</code> and not in
<code>user</code>. The goal <code>call(G)</code> is expanded because of the
meta-predicate declaration for <code>call/1</code>.
</p>
<div class="example">
<pre class="example">:- module(example,[a/1]).
a(G) :- call(example:G)
</pre></div>
<p>By adding a meta-predicate declaration for <code>a/1</code>, the goal
<code>a(p)</code> in module user will be expanded to <code>a(user:p)</code>
thereby preserving the module information.
</p>
<div class="example">
<pre class="example">:- module(example,[a/1]).
:- meta_predicate a(:).
a(G) :- call(G)
</pre></div>
<p>An alternate mechanism is the directive <code>module_transparent/1</code>
offered for compatibility with SWI-Prolog.
</p>
<dl compact="compact">
<dt><code>module_transparent +<var>Preds</var></code></dt>
<dd><a name="index-module_005ftransparent_002f1-_0028directive_0029"></a>
<a name="index-module_005ftransparent_002f1-_0028directive_0029-1"></a>
<a name="index-module_005ftransparent_002f1-_0028directive_0029-2"></a>
<p> <var>Preds</var> is a comma separated sequence of name/arity predicate
indicators (like
<code>dynamic/1</code>). Each goal associated with a transparent declared
predicate will inherit the context module from its parent goal.
</p></dd>
</dl>
<hr>
<a name="Re_002dExporting-Modules"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Meta_002dPredicates-in-Modules" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Re_002dExporting-Predicates-From-Other-Modules"></a>
<h2 class="section">5.5 Re-Exporting Predicates From Other Modules</h2>
<p>It is sometimes convenient to re-export predicates originally defined in
a different module. This is often useful if you are adding to the
functionality of a module, or if you are composing a large module with
several small modules. The following declarations can be used for that purpose:
</p>
<dl compact="compact">
<dt><code>reexport(+<var>F</var>)</code></dt>
<dd><a name="index-reexport_002f1"></a>
<a name="index-reexport_002f1-1"></a>
<a name="index-reexport_002f1-2"></a>
<p>Export all predicates defined in file <var>F</var> as if they were defined in
the current module.
</p>
</dd>
<dt><code>reexport(+<var>F</var>,+<var>Decls</var>)</code></dt>
<dd><a name="index-reexport_002f2"></a>
<a name="index-reexport_002f2-1"></a>
<a name="index-reexport_002f2-2"></a>
<p>Export predicates defined in file <var>F</var> according to <var>Decls</var>. The
declarations may be of the form:
</p><ul>
<li> A list of predicate declarations to be exported. Each declaration
may be a predicate indicator or of the form &ldquo;<var>PI</var> <code>as</code>
<var>NewName</var>&rdquo;, meaning that the predicate with indicator <var>PI</var> is
to be exported under name <var>NewName</var>.
</li><li> <code>except</code>(<var>List</var>)
In this case, all predicates not in <var>List</var> are exported. Moreover,
if &ldquo;<var>PI</var> <code>as</code> <var>NewName</var>&rdquo; is found, the predicate with
indicator <var>PI</var> is to be exported under name <var>NewName</var>&nbsp;as
before.
</li></ul>
</dd>
</dl>
<p>Re-exporting predicates must be used with some care. Please, take into
account the following observations:
</p>
<ul>
<li>
The <code>reexport</code> declarations must be the first declarations to
follow the <code>module</code> declaration.
</li><li>
It is possible to use both <code>reexport</code> and <code>use_module</code>, but
all predicates reexported are automatically available for use in the
current module.
</li><li>
In order to obtain efficient execution, YAP compiles dependencies
between re-exported predicates. In practice, this means that changing a
<code>reexport</code> declaration and then <strong>just</strong> recompiling the file
may result in incorrect execution.
</li></ul>
<hr>
<a name="Built_002dins"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Re_002dExporting-Modules" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Control" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Built_002dIn-Predicates"></a>
<h1 class="chapter">6 Built-In Predicates</h1>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Built-ins, Debugging, Syntax, Top
</pre></th></tr><tr><td align="left" valign="top"><a href="#Control">6.1 Control Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Controlling the Execution of Prolog Programs
</td></tr>
<tr><td align="left" valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Handling calls to Undefined Procedures
</td></tr>
<tr><td align="left" valign="top"><a href="#Messages">6.3 Message Handling</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Message Handling in YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Predicates on Terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Manipulating Atoms
</td></tr>
<tr><td align="left" valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Manipulating Characters
</td></tr>
<tr><td align="left" valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Comparison of Terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Arithmetic in YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#I_002fO">6.9 I/O Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Input/Output with YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Database">6.10 Using the Clausal Data Base</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Modifying Prolog&rsquo;s Database
</td></tr>
<tr><td align="left" valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Finding All Possible Solutions
</td></tr>
<tr><td align="left" valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Preds">6.21 Predicate Information</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Updating Prolog Terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Manipulating Global Variables
</td></tr>
<tr><td align="left" valign="top"><a href="#Profiling">6.18 Profiling Prolog Programs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Profiling Prolog Execution
</td></tr>
<tr><td align="left" valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Limiting the Maximum Number of Reductions
</td></tr>
<tr><td align="left" valign="top"><a href="#Arrays">6.20 Arrays</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Supporting Global and Local Arrays
</td></tr>
<tr><td align="left" valign="top"><a href="#Preds">6.21 Predicate Information</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Information on Predicates
</td></tr>
<tr><td align="left" valign="top"><a href="#Misc">6.22 Miscellaneous</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Miscellaneous Predicates
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
</pre></th></tr></table>
<hr>
<a name="Control"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Undefined-Procedures" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Control-Predicates"></a>
<h2 class="section">6.1 Control Predicates</h2>
<p>This chapter describes the predicates for controlling the execution of
Prolog programs.
</p>
<p>In the description of the arguments of functors the following notation
will be used:
</p>
<ul>
<li>
a preceding plus sign will denote an argument as an &quot;input argument&quot; -
it cannot be a free variable at the time of the call;
</li><li>
a preceding minus sign will denote an &quot;output argument&quot;;
</li><li>
an argument with no preceding symbol can be used in both ways.
</li></ul>
<dl compact="compact">
<dt><code>+<var>P</var>, +<var>Q</var> [ISO]</code></dt>
<dd><a name="index-_002c_002f2"></a>
<a name="index-_002c_002f2-1"></a>
<a name="index-_002c_002f2-2"></a>
<p>Conjunction of goals (and).
</p>
<p>Example:
</p><div class="example">
<pre class="example"> p(X) :- q(X), r(X).
</pre></div>
<p>should be read as &quot;p(<var>X</var>) if q(<var>X</var>) and r(<var>X</var>)&quot;.
</p>
</dd>
<dt><code>+<var>P</var> ; +<var>Q</var> [ISO]</code></dt>
<dd><a name="index-_003b_002f2"></a>
<a name="index-_003b_002f2-1"></a>
<a name="index-_003b_002f2-2"></a>
<p>Disjunction of goals (or).
</p>
<p>Example:
</p><div class="example">
<pre class="example"> p(X) :- q(X); r(X).
</pre></div>
<p>should be read as &quot;p(<var>X</var>) if q(<var>X</var>) or r(<var>X</var>)&quot;.
</p>
</dd>
<dt><code>true [ISO]</code></dt>
<dd><a name="index-true_002f0"></a>
<a name="index-true_002f0-1"></a>
<a name="index-true_002f0-2"></a>
<p>Succeeds once.
</p>
</dd>
<dt><code>fail [ISO]</code></dt>
<dd><a name="index-fail_002f0"></a>
<a name="index-fail_002f0-1"></a>
<a name="index-fail_002f0-2"></a>
<p>Fails always.
</p>
</dd>
<dt><code>false</code></dt>
<dd><a name="index-false_002f0"></a>
<a name="index-false_002f0-1"></a>
<a name="index-false_002f0-2"></a>
<p>The same as fail
</p>
</dd>
<dt><code>! [ISO]</code></dt>
<dd><a name="index-_0021_002f0"></a>
<a name="index-_0021_002f0-1"></a>
<a name="index-_0021_002f0-2"></a>
<p> Read as &quot;cut&quot;. Cuts any choices taken in the current procedure.
When first found &quot;cut&quot; succeeds as a goal, but if backtracking should
later return to it, the parent goal (the one which matches the head of
the clause containing the &quot;cut&quot;, causing the clause activation) will
fail. This is an extra-logical predicate and cannot be explained in
terms of the declarative semantics of Prolog.
</p>
<p>example:
</p>
<div class="example">
<pre class="example"> member(X,[X|_]).
member(X,[_|L]) :- member(X,L).
</pre></div>
<p>With the above definition
</p>
<div class="example">
<pre class="example"> ?- member(X,[1,2,3]).
</pre></div>
<p>will return each element of the list by backtracking. With the following
definition:
</p>
<div class="example">
<pre class="example"> member(X,[X|_]) :- !.
member(X,[_|L]) :- member(X,L).
</pre></div>
<p>the same query would return only the first element of the
list, since backtracking could not &quot;pass through&quot; the cut.
</p>
</dd>
<dt><code>\+ +<var>P</var> [ISO]</code></dt>
<dd><a name="index-_005c_002b_002f1"></a>
<a name="index-_005c_002b_002f1-1"></a>
<a name="index-_005c_002b_002f1-2"></a>
<p>Goal <var>P</var> is not provable. The execution of this predicate fails if
and only if the goal <var>P</var> finitely succeeds. It is not a true logical
negation, which is impossible in standard Prolog, but
&quot;negation-by-failure&quot;.
</p>
<p>This predicate might be defined as:
</p><div class="example">
<pre class="example"> \+(P) :- P, !, fail.
\+(_).
</pre></div>
<p>if <var>P</var> did not include &quot;cuts&quot;.
</p>
</dd>
<dt><code>not +<var>P</var></code></dt>
<dd><a name="index-not_002f1"></a>
<a name="index-not_002f1-1"></a>
<a name="index-not_002f1-2"></a>
<p>Goal <var>P</var> is not provable. The same as <code>'\+ <var>P</var>'</code>.
</p>
<p>This predicate is kept for compatibility with C-Prolog and previous
versions of YAP. Uses of <code>not/1</code> should be replace by
<code>(\+)/1</code>, as YAP does not implement true negation.
</p>
</dd>
<dt><code>+<var>P</var> -&gt; +<var>Q</var> [ISO]</code></dt>
<dd><a name="index-_002d_003e_002f2"></a>
<a name="index-_002d_003e_002f2-1"></a>
<a name="index-_002d_003e_002f2-2"></a>
<p>Read as &quot;if-then-else&quot; or &quot;commit&quot;. This operator is similar to the
conditional operator of imperative languages and can be used alone or
with an else part as follows:
</p>
<dl compact="compact">
<dt><code>+P -&gt; +Q</code></dt>
<dd><p>&quot;if P then Q&quot;.
</p></dd>
<dt><code>+P -&gt; +Q; +R</code></dt>
<dd><p>&quot;if P then Q else R&quot;.
</p></dd>
</dl>
<p>These two predicates could be defined respectively in Prolog as:
</p><div class="example">
<pre class="example"> (P -&gt; Q) :- P, !, Q.
</pre></div>
<p>and
</p><div class="example">
<pre class="example"> (P -&gt; Q; R) :- P, !, Q.
(P -&gt; Q; R) :- R.
</pre></div>
<p>if there were no &quot;cuts&quot; in <var>P</var>, <var>Q</var> and <var>R</var>.
</p>
<p>Note that the commit operator works by &quot;cutting&quot; any alternative
solutions of <var>P</var>.
</p>
<p>Note also that you can use chains of commit operators like:
</p><div class="example">
<pre class="example"> P -&gt; Q ; R -&gt; S ; T.
</pre></div>
<p>Note that <code>(-&gt;)/2</code> does not affect the scope of cuts in its
arguments.
</p>
</dd>
<dt><code>+<var>Condition</var> *-&gt; +<var>Action</var> ; +<var>Else</var></code></dt>
<dd><a name="index-_002d_003e_002a_002f2"></a>
<a name="index-_002d_003e_002a_002f2-1"></a>
<a name="index-_002d_003e_002a_002f2-2"></a>
<p>This construct implements the so-called <em>soft-cut</em>. The control is
defined as follows: If <var>Condition</var> succeeds at least once, the
semantics is the same as (<var>Condition</var>, <var>Action</var>). If
<var>Condition</var> does not succeed, the semantics is that of (\+
<var>Condition</var>, <var>Else</var>). In other words, If <var>Condition</var>
succeeds at least once, simply behave as the conjunction of
<var>Condition</var> and <var>Action</var>, otherwise execute <var>Else</var>.
</p>
<p> The construct <var>A *-&gt; B</var>, i.e. without an <var>Else</var> branch, is
translated as the normal conjunction <var>A</var>, <var>B</var>.
</p>
</dd>
<dt><code>repeat [ISO]</code></dt>
<dd><a name="index-repeat_002f0"></a>
<a name="index-repeat_002f0-1"></a>
<a name="index-repeat_002f0-2"></a>
<p>Succeeds repeatedly.
</p>
<p>In the next example, <code>repeat</code> is used as an efficient way to implement
a loop. The next example reads all terms in a file:
</p>
<div class="example">
<pre class="example"> a :- repeat, read(X), write(X), nl, X=end_of_file, !.
</pre></div>
<p>the loop is effectively terminated by the cut-goal, when the test-goal
<code>X=end</code> succeeds. While the test fails, the goals <code>read(X)</code>,
<code>write(X)</code>, and <code>nl</code> are executed repeatedly, because
backtracking is caught by the <code>repeat</code> goal.
</p>
<p>The built-in <code>repeat/1</code> could be defined in Prolog by:
</p><div class="example">
<pre class="example"> repeat.
repeat :- repeat.
</pre></div>
</dd>
<dt><code>call(+<var>P</var>) [ISO]</code></dt>
<dd><a name="index-call_002f1"></a>
<a name="index-call_002f1-1"></a>
<a name="index-call_002f1-2"></a>
<p> If <var>P</var> is instantiated to an atom or a compound term, the goal
<code>call(<var>P</var>)</code> is executed as if the value of <code>P</code> was found
instead of the call to <code>call/1</code>, except that any &quot;cut&quot; occurring in
<var>P</var> only cuts alternatives in the execution of <var>P</var>.
</p>
</dd>
<dt><code>incore(+<var>P</var>)</code></dt>
<dd><a name="index-incore_002f1"></a>
<a name="index-incore_002f1-1"></a>
<a name="index-incore_002f1-2"></a>
<p>The same as <code>call/1</code>.
</p>
</dd>
<dt><code>call(+<var>Closure</var>,...,?<var>Ai</var>,...)</code></dt>
<dd><a name="index-call_002fn"></a>
<a name="index-call_002fn-1"></a>
<a name="index-call_002fn-2"></a>
<p>Meta-call where <var>Closure</var> is a closure that is converted into a goal by
appending the <var>Ai</var> additional arguments. The number of arguments varies
between 0 and 10.
</p>
</dd>
<dt><code>call_with_args(+<var>Name</var>,...,?<var>Ai</var>,...)</code></dt>
<dd><a name="index-call_005fwith_005fargs_002fn"></a>
<a name="index-call_005fwith_005fargs_002fn-1"></a>
<a name="index-call_005fwith_005fargs_002fn-2"></a>
<p>Meta-call where <var>Name</var> is the name of the procedure to be called and
the <var>Ai</var> are the arguments. The number of arguments varies between 0
and 10. New code should use <code>call/N</code> for better portability.
</p>
<p>If <var>Name</var> is a complex term, then <code>call_with_args/n</code> behaves as
<code>call/n</code>:
</p>
<div class="example">
<pre class="example">call(p(X1,...,Xm), Y1,...,Yn) :- p(X1,...,Xm,Y1,...,Yn).
</pre></div>
</dd>
<dt><code>+<var>P</var></code></dt>
<dd><p> The same as <code>call(<var>P</var>)</code>. This feature has been kept to provide
compatibility with C-Prolog. When compiling a goal, YAP
generates a <code>call(<var>X</var>)</code> whenever a variable <var>X</var> is found as
a goal.
</p>
<div class="example">
<pre class="example"> a(X) :- X.
</pre></div>
<p>is converted to:
</p><div class="example">
<pre class="example"> a(X) :- call(X).
</pre></div>
</dd>
<dt><code>if(?<var>G</var>,?<var>H</var>,?<var>I</var>)</code></dt>
<dd><a name="index-if_002f3"></a>
<a name="index-if_002f3-1"></a>
<a name="index-if_002f3-2"></a>
<p>Call goal <var>H</var> once per each solution of goal <var>H</var>. If goal
<var>H</var> has no solutions, call goal <var>I</var>.
</p>
<p>The built-in <code>if/3</code> is similar to <code>-&gt;/3</code>, with the difference
that it will backtrack over the test goal. Consider the following
small data-base:
</p>
<div class="example">
<pre class="example">a(1). b(a). c(x).
a(2). b(b). c(y).
</pre></div>
<p>Execution of an <code>if/3</code> query will proceed as follows:
</p>
<div class="example">
<pre class="example"> ?- if(a(X),b(Y),c(Z)).
X = 1,
Y = a ? ;
X = 1,
Y = b ? ;
X = 2,
Y = a ? ;
X = 2,
Y = b ? ;
no
</pre></div>
<p>The system will backtrack over the two solutions for <code>a/1</code> and the
two solutions for <code>b/1</code>, generating four solutions.
</p>
<p>Cuts are allowed inside the first goal <var>G</var>, but they will only prune
over <var>G</var>.
</p>
<p>If you want <var>G</var> to be deterministic you should use if-then-else, as
it is both more efficient and more portable.
</p>
</dd>
<dt><code>once(:<var>G</var>) [ISO]</code></dt>
<dd><a name="index-once_002f1"></a>
<a name="index-once_002f1-1"></a>
<a name="index-once_002f1-2"></a>
<p>Execute the goal <var>G</var> only once. The predicate is defined by:
</p>
<div class="example">
<pre class="example"> once(G) :- call(G), !.
</pre></div>
<p>Note that cuts inside <code>once/1</code> can only cut the other goals inside
<code>once/1</code>.
</p>
</dd>
<dt><code>forall(:<var>Cond</var>,:<var>Action</var>)</code></dt>
<dd><a name="index-forall_002f2"></a>
<a name="index-forall_002f2-1"></a>
<a name="index-forall_002f2-2"></a>
<p>For all alternative bindings of <var>Cond</var> <var>Action</var> can be
proven. The example verifies that all arithmetic statements in the list
<var>L</var> are correct. It does not say which is wrong if one proves wrong.
</p>
<div class="example">
<pre class="example">?- forall(member(Result = Formula, [2 = 1 + 1, 4 = 2 * 2]),
Result =:= Formula).
</pre></div>
</dd>
<dt><code>ignore(:<var>Goal</var>)</code></dt>
<dd><a name="index-ignore_002f1"></a>
<a name="index-ignore_002f1-1"></a>
<a name="index-ignore_002f1-2"></a>
<p>Calls <var>Goal</var> as <code>once/1</code>, but succeeds, regardless of whether
<code>Goal</code> succeeded or not. Defined as:
</p>
<div class="example">
<pre class="example">ignore(Goal) :-
Goal, !.
ignore(_).
</pre></div>
</dd>
<dt><code>abort</code></dt>
<dd><a name="index-abort_002f0"></a>
<a name="index-abort_002f0-1"></a>
<a name="index-abort_002f0-2"></a>
<p>Abandons the execution of the current goal and returns to top level. All
break levels (see <code>break/0</code> below) are terminated. It is mainly
used during debugging or after a serious execution error, to return to
the top-level.
</p>
</dd>
<dt><code>break</code></dt>
<dd><a name="index-break_002f0"></a>
<a name="index-break_002f0-1"></a>
<a name="index-break_002f0-2"></a>
<p>Suspends the execution of the current goal and creates a new execution
level similar to the top level, displaying the following message:
</p>
<div class="example">
<pre class="example"> [ Break (level &lt;number&gt;) ]
</pre></div>
<p>telling the depth of the break level just entered. To return to the
previous level just type the end-of-file character or call the
end_of_file predicate. This predicate is especially useful during
debugging.
</p>
</dd>
<dt><code>halt [ISO]</code></dt>
<dd><a name="index-halt_002f0"></a>
<a name="index-halt_002f0-1"></a>
<a name="index-halt_002f0-2"></a>
<p>Halts Prolog, and exits to the calling application. In YAP,
<code>halt/0</code> returns the exit code <code>0</code>.
</p>
</dd>
<dt><code>halt(+ <var>I</var>) [ISO]</code></dt>
<dd><a name="index-halt_002f1"></a>
<a name="index-halt_002f1-1"></a>
<a name="index-halt_002f1-2"></a>
<p>Halts Prolog, and exits to the calling application returning the code
given by the integer <var>I</var>.
</p>
</dd>
<dt><code>catch(+<var>Goal</var>,+<var>Exception</var>,+<var>Action</var>) [ISO]</code></dt>
<dd><a name="index-catch_002f3"></a>
<a name="index-catch_002f3-1"></a>
<a name="index-catch_002f3-2"></a>
<p>The goal <code>catch(<var>Goal</var>,<var>Exception</var>,<var>Action</var>)</code> tries to
execute goal <var>Goal</var>. If during its execution, <var>Goal</var> throws an
exception <var>E&rsquo;</var> and this exception unifies with <var>Exception</var>, the
exception is considered to be caught and <var>Action</var> is executed. If
the exception <var>E&rsquo;</var> does not unify with <var>Exception</var>, control
again throws the exception.
</p>
<p>The top-level of YAP maintains a default exception handler that
is responsible to capture uncaught exceptions.
</p>
</dd>
<dt><code>throw(+<var>Ball</var>) [ISO]</code></dt>
<dd><a name="index-throw_002f1"></a>
<a name="index-throw_002f1-1"></a>
<a name="index-throw_002f1-2"></a>
<p>The goal <code>throw(<var>Ball</var>)</code> throws an exception. Execution is
stopped, and the exception is sent to the ancestor goals until reaching
a matching <code>catch/3</code>, or until reaching top-level.
</p>
</dd>
<dt><code>garbage_collect</code></dt>
<dd><a name="index-garbage_005fcollect_002f0"></a>
<a name="index-garbage_005fcollect_002f0-1"></a>
<a name="index-garbage_005fcollect_002f0-2"></a>
<p>The goal <code>garbage_collect</code> forces a garbage collection.
</p>
</dd>
<dt><code>garbage_collect_atoms</code></dt>
<dd><a name="index-garbage_005fcollect_005fatoms_002f0"></a>
<a name="index-garbage_005fcollect_005fatoms_002f0-1"></a>
<a name="index-garbage_005fcollect_005fatoms_002f0-2"></a>
<p>The goal <code>garbage_collect</code> forces a garbage collection of the atoms
in the data-base. Currently, only atoms are recovered.
</p>
</dd>
<dt><code>gc</code></dt>
<dd><a name="index-gc_002f0"></a>
<a name="index-gc_002f0-1"></a>
<a name="index-gc_002f0-2"></a>
<p>The goal <code>gc</code> enables garbage collection. The same as
<code>yap_flag(gc,on)</code>.
</p>
</dd>
<dt><code>nogc</code></dt>
<dd><a name="index-nogc_002f0"></a>
<a name="index-nogc_002f0-1"></a>
<a name="index-nogc_002f0-2"></a>
<p>The goal <code>nogc</code> disables garbage collection. The same as
<code>yap_flag(gc,off)</code>.
</p>
</dd>
<dt><code>grow_heap(+<var>Size</var>)</code></dt>
<dd><a name="index-grow_005fheap_002f1"></a>
<a name="index-grow_005fheap_002f1-1"></a>
<p>Increase heap size <var>Size</var> kilobytes.
</p>
</dd>
<dt><code>grow_stack(+<var>Size</var>)</code></dt>
<dd><a name="index-grow_005fstack_002f1"></a>
<a name="index-grow_005fstack_002f1-1"></a>
<a name="index-grow_005fstack_002f1-2"></a>
<p>Increase stack size <var>Size</var> kilobytes.
</p>
</dd>
</dl>
<hr>
<a name="Undefined-Procedures"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Control" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Messages" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Handling-Undefined-Procedures"></a>
<h2 class="section">6.2 Handling Undefined Procedures</h2>
<p>A predicate in a module is said to be undefined if there are no clauses
defining the predicate, and if the predicate has not been declared to be
dynamic. What YAP does when trying to execute undefined predicates can
be specified in three different ways:
</p><ul>
<li> By setting an YAP flag, through the <code>yap_flag/2</code> or
<code>set_prolog_flag/2</code> built-ins. This solution generalizes the
ISO standard.
</li><li> By using the <code>unknown/2</code> built-in (this solution is
compatible with previous releases of YAP).
</li><li> By defining clauses for the hook predicate
<code>user:unknown_predicate_handler/3</code>. This solution is compatible
with SICStus Prolog.
</li></ul>
<p>In more detail:
</p><dl compact="compact">
<dt><code>unknown(-<var>O</var>,+<var>N</var>)</code></dt>
<dd><a name="index-unknown_002f2"></a>
<a name="index-unknown_002f2-1"></a>
<a name="index-unknown_002f2-2"></a>
<p>Specifies an handler to be called is a program tries to call an
undefined static procedure <var>P</var>.
</p>
<p>The arity of <var>N</var> may be zero or one. If the arity is <code>0</code>, the
new action must be one of <code>fail</code>, <code>warning</code>, or
<code>error</code>. If the arity is <code>1</code>, <var>P</var> is an user-defined
handler and at run-time, the argument to the handler <var>P</var> will be
unified with the undefined goal. Note that <var>N</var> must be defined prior
to calling <code>unknown/2</code>, and that the single argument to <var>N</var> must
be unbound.
</p>
<p>In YAP, the default action is to <code>fail</code> (note that in the ISO
Prolog standard the default action is <code>error</code>).
</p>
<p>After defining <code>undefined/1</code> by:
</p><div class="example">
<pre class="example">undefined(A) :- format('Undefined predicate: ~w~n',[A]), fail.
</pre></div>
<p>and executing the goal:
</p><div class="example">
<pre class="example">unknown(U,undefined(X)).
</pre></div>
<p>a call to a predicate for which no clauses were defined will result in
the output of a message of the form:
</p><div class="example">
<pre class="example">Undefined predicate: user:xyz(A1,A2)
</pre></div>
<p>followed by the failure of that call.
</p>
</dd>
<dt><code>yap_flag(unknown,+<var>SPEC</var>)</code></dt>
<dd><p>Alternatively, one can use <code>yap_flag/2</code>,
<code>current_prolog_flag/2</code>, or <code>set_prolog_flag/2</code>, to set this
functionality. In this case, the first argument for the built-ins should
be <code>unknown</code>, and the second argument should be either
<code>error</code>, <code>warning</code>, <code>fail</code>, or a goal.
</p>
</dd>
<dt><code>user:unknown_predicate_handler(+G,+M,?NG)</code></dt>
<dd><a name="index-unknown_005fpredicate_005fhandler_002f3"></a>
<a name="index-unknown_005fpredicate_005fhandler_002f3-1"></a>
<a name="index-unknown_005fpredicate_005fhandler_002f3-2"></a>
<p>The user may also define clauses for
<code>user:unknown_predicate_handler/3</code> hook predicate. This
user-defined procedure is called before any system processing for the
undefined procedure, with the first argument <var>G</var> set to the current
goal, and the second <var>M</var> set to the current module. The predicate
<var>G</var> will be called from within the user module.
</p>
<p>If <code>user:unknown_predicate_handler/3</code> succeeds, the system will
execute <var>NG</var>. If <code>user:unknown_predicate_handler/3</code> fails, the
system will execute default action as specified by <code>unknown/2</code>.
</p>
</dd>
<dt><code>exception(+<var>Exception</var>, +<var>Context</var>, -<var>Action</var>)</code></dt>
<dd><a name="index-exception_002f3"></a>
<a name="index-exception_002f3-1"></a>
<a name="index-exception_002f3-2"></a>
<p> Dynamic predicate, normally not defined. Called by the Prolog system on run-time exceptions that can be repaired &lsquo;just-in-time&rsquo;. The values for <var>Exception</var> are described below. See also <code>catch/3</code> and <code>throw/1</code>.
If this hook predicate succeeds it must instantiate the <var>Action</var> argument to the atom <code>fail</code> to make the operation fail silently, <code>retry</code> to tell Prolog to retry the operation or <code>error</code> to make the system generate an exception. The action <code>retry</code> only makes sense if this hook modified the environment such that the operation can now succeed without error.
</p>
<dl compact="compact">
<dt><code>undefined_predicate</code></dt>
<dd><p><var>Context</var> is instantiated to a predicate-indicator (<var>Module:Name/Arity</var>). If the predicate fails Prolog will generate an existence_error exception. The hook is intended to implement alternatives to the SWI built-in autoloader, such as autoloading code from a database. Do not use this hook to suppress existence errors on predicates. See also <code>unknown</code>.
</p></dd>
<dt><code>undefined_global_variable</code></dt>
<dd><p><var>Context</var> is instantiated to the name of the missing global variable. The hook must call <code>nb_setval/2</code> or <code>b_setval/2</code> before returning with the action retry.
</p></dd>
</dl>
</dd>
</dl>
<hr>
<a name="Messages"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Undefined-Procedures" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Testing-Terms" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Message-Handling"></a>
<h2 class="section">6.3 Message Handling</h2>
<p>The interaction between YAP and the user relies on YAP&rsquo;s ability to
portray messages. These messages range from prompts to error
information. All message processing is performed through the builtin
<code>print_message/2</code>, in two steps:
</p>
<ul>
<li> The message is processed into a list of commands
</li><li> The commands in the list are sent to the <code>format/3</code> builtin
in sequence.
</li></ul>
<p>The first argument to <code>print_message/2</code> specifies the importance of
the message. The options are:
</p>
<dl compact="compact">
<dt><code>error</code></dt>
<dd><p>error handling
</p></dd>
<dt><code>warning</code></dt>
<dd><p>compilation and run-time warnings,
</p></dd>
<dt><code>informational</code></dt>
<dd><p>generic informational messages
</p></dd>
<dt><code>help</code></dt>
<dd><p>help messages (not currently implemented in YAP)
</p></dd>
<dt><code>query</code></dt>
<dd><p>query used in query processing (not currently implemented in YAP)
</p></dd>
<dt><code>silent</code></dt>
<dd><p>messages that do not produce output but that can be intercepted by hooks.
</p></dd>
</dl>
<p>The next table shows the main predicates and hooks associated to message
handling in YAP:
</p><dl compact="compact">
<dt><code>print_message(+<var>Kind</var>, <var>Term</var>)</code></dt>
<dd><a name="index-print_005fmessage_002f2"></a>
<a name="index-print_005fmessage_002f2-1"></a>
<a name="index-print_005fmessage_002f2-2"></a>
<p>The predicate print_message/2 is used to print messages, notably from
exceptions in a human-readable format. <var>Kind</var> is one of
<code>informational</code>, <code>banner</code>, <code>warning</code>, <code>error</code>,
<code>help</code> or <code>silent</code>. A human-readable message is printed to
the stream <code>user_error</code>.
</p>
<p>If the Prolog flag <code>verbose</code> is <code>silent</code>, messages with
<var>Kind</var> <code>informational</code>, or <code>banner</code> are treated as
silent.</p>
<p>This predicate first translates the <var>Term</var> into a list of &lsquo;message
lines&rsquo; (see <code>print_message_lines/3</code> for details). Next it will
call the hook <code>message_hook/3</code> to allow the user intercepting the
message. If <code>message_hook/3</code> fails it will print the message unless
<var>Kind</var> is silent.
</p>
<p>If you need to report errors from your own predicates, we advise you to
stick to the existing error terms if you can; but should you need to
invent new ones, you can define corresponding error messages by
asserting clauses for <code>prolog:message/2</code>. You will need to declare
the predicate as multifile.
</p>
</dd>
<dt><code>print_message_lines(+<var>Stream</var>, +<var>Prefix</var>, +<var>Lines</var>)</code></dt>
<dd><a name="index-print_005fmessage_005flines_002f3"></a>
<a name="index-print_005fmessage_005flines_002f3-1"></a>
<a name="index-print_005fmessage_005flines_002f3-2"></a>
<p>Print a message (see <code>print_message/2</code>) that has been translated to
a list of message elements. The elements of this list are:
</p>
<dl compact="compact">
<dt><code><code>&lt;Format&gt;</code>-<code>&lt;Args&gt;</code></code></dt>
<dd><p> Where <var>Format</var> is an atom and <var>Args</var> is a list
of format argument. Handed to <code>format/3</code>.
</p></dd>
<dt><code><code>flush</code></code></dt>
<dd><p> If this appears as the last element, <var>Stream</var> is flushed
(see <code>flush_output/1</code>) and no final newline is generated.
</p></dd>
<dt><code><code>at_same_line</code></code></dt>
<dd><p> If this appears as first element, no prefix is printed for
the first line and the line-position is not forced to 0
(see <code>format/1</code>, <code>~N</code>).
</p></dd>
<dt><code><code>&lt;Format&gt;</code></code></dt>
<dd><p> Handed to <code>format/3</code> as <code>format(Stream, Format, [])</code>.
</p></dd>
<dt><code>nl</code></dt>
<dd><p> A new line is started and if the message is not complete
the <var>Prefix</var> is printed too.
</p></dd>
</dl>
</dd>
<dt><code>user:message_hook(+<var>Term</var>, +<var>Kind</var>, +<var>Lines</var>)</code></dt>
<dd><a name="index-message_005fhook_002f3"></a>
<a name="index-message_005fhook_002f3-1"></a>
<a name="index-message_005fhook_002f3-2"></a>
<p>Hook predicate that may be define in the module <code>user</code> to intercept
messages from <code>print_message/2</code>. <var>Term</var> and <var>Kind</var> are the
same as passed to <code>print_message/2</code>. <var>Lines</var> is a list of
format statements as described with <code>print_message_lines/3</code>.
</p>
<p>This predicate should be defined dynamic and multifile to allow other
modules defining clauses for it too.
</p>
</dd>
<dt><code>message_to_string(+<var>Term</var>, -<var>String</var>)</code></dt>
<dd><a name="index-message_005fto_005fstring_002f2"></a>
<a name="index-message_005fto_005fstring_002f2-1"></a>
<a name="index-message_005fto_005fstring_002f2-2"></a>
<p>Translates a message-term into a string object. Primarily intended for SWI-Prolog emulation.
</p></dd>
</dl>
<hr>
<a name="Testing-Terms"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Messages" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Predicates-on-Atoms" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Predicates-on-terms"></a>
<h2 class="section">6.4 Predicates on terms</h2>
<dl compact="compact">
<dt><code>var(<var>T</var>) [ISO]</code></dt>
<dd><a name="index-var_002f1"></a>
<a name="index-var_002f1-1"></a>
<a name="index-var_002f1-2"></a>
<p>Succeeds if <var>T</var> is currently a free variable, otherwise fails.
</p>
</dd>
<dt><code>atom(<var>T</var>) [ISO]</code></dt>
<dd><a name="index-atom_002f1"></a>
<a name="index-atom_002f1-1"></a>
<a name="index-atom_002f1-2"></a>
<p>Succeeds if and only if <var>T</var> is currently instantiated to an atom.
</p>
</dd>
<dt><code>atomic(T) [ISO]</code></dt>
<dd><a name="index-atomic_002f1"></a>
<a name="index-atomic_002f1-1"></a>
<a name="index-atomic_002f1-2"></a>
<p>Checks whether <var>T</var> is an atomic symbol (atom or number).
</p>
</dd>
<dt><code>compound(<var>T</var>) [ISO]</code></dt>
<dd><a name="index-compound_002f1"></a>
<a name="index-compound_002f1-1"></a>
<a name="index-compound_002f1-2"></a>
<p>Checks whether <var>T</var> is a compound term.
</p>
</dd>
<dt><code>db_reference(<var>T</var>)</code></dt>
<dd><a name="index-db_005freference_002f1C"></a>
<a name="index-db_005freference_002f1"></a>
<a name="index-db_005freference_002f1-1"></a>
<p>Checks whether <var>T</var> is a database reference.
</p>
</dd>
<dt><code>float(<var>T</var>) [ISO]</code></dt>
<dd><a name="index-float_002f1"></a>
<a name="index-float_002f1-1"></a>
<a name="index-float_002f1-2"></a>
<p>Checks whether <var>T</var> is a floating point number.
</p>
</dd>
<dt><code>rational(<var>T</var>)</code></dt>
<dd><a name="index-rational_002f1"></a>
<a name="index-rational_002f1-1"></a>
<a name="index-rational_002f1-2"></a>
<p>Checks whether <code>T</code> is a rational number.
</p>
</dd>
<dt><code>integer(<var>T</var>) [ISO]</code></dt>
<dd><a name="index-integer_002f1"></a>
<a name="index-integer_002f1-1"></a>
<a name="index-integer_002f1-2"></a>
<p>Succeeds if and only if <var>T</var> is currently instantiated to an integer.
</p>
</dd>
<dt><code>nonvar(<var>T</var>) [ISO]</code></dt>
<dd><a name="index-nonvar_002f1"></a>
<a name="index-nonvar_002f1-1"></a>
<a name="index-nonvar_002f1-2"></a>
<p>The opposite of <code>var(<var>T</var>)</code>.
</p>
</dd>
<dt><code>number(<var>T</var>) [ISO]</code></dt>
<dd><a name="index-number_002f1"></a>
<a name="index-number_002f1-1"></a>
<a name="index-number_002f1-2"></a>
<p>Checks whether <code>T</code> is an integer, rational or a float.
</p>
</dd>
<dt><code>primitive(<var>T</var>)</code></dt>
<dd><a name="index-primitive_002f1"></a>
<a name="index-primitive_002f1-1"></a>
<a name="index-primitive_002f1-2"></a>
<p>Checks whether <var>T</var> is an atomic term or a database reference.
</p>
</dd>
<dt><code>simple(<var>T</var>)</code></dt>
<dd><a name="index-simple_002f1"></a>
<a name="index-simple_002f1-1"></a>
<a name="index-simple_002f1-2"></a>
<p>Checks whether <var>T</var> is unbound, an atom, or a number.
</p>
</dd>
<dt><code>callable(<var>T</var>)</code></dt>
<dd><a name="index-callable_002f1"></a>
<a name="index-callable_002f1-1"></a>
<a name="index-callable_002f1-2"></a>
<p>Checks whether <var>T</var> is a callable term, that is, an atom or a
compound term.
</p>
</dd>
<dt><code>numbervars(<var>T</var>,+<var>N1</var>,-<var>Nn</var>)</code></dt>
<dd><a name="index-numbervars_002f3"></a>
<a name="index-numbervars_002f3-1"></a>
<a name="index-numbervars_002f3-2"></a>
<p>Instantiates each variable in term <var>T</var> to a term of the form:
<code>'$VAR'(<var>I</var>)</code>, with <var>I</var> increasing from <var>N1</var> to <var>Nn</var>.
</p>
</dd>
<dt><code>ground(<var>T</var>)</code></dt>
<dd><a name="index-ground_002f1"></a>
<a name="index-ground_002f1-1"></a>
<a name="index-ground_002f1-2"></a>
<p>Succeeds if there are no free variables in the term <var>T</var>.
</p>
</dd>
<dt><code>arg(+<var>N</var>,+<var>T</var>,<var>A</var>) [ISO]</code></dt>
<dd><a name="index-arg_002f3"></a>
<a name="index-arg_002f3-1"></a>
<a name="index-arg_002f3-2"></a>
<p>Succeeds if the argument <var>N</var> of the term <var>T</var> unifies with
<var>A</var>. The arguments are numbered from 1 to the arity of the term.
</p>
<p>The current version will generate an error if <var>T</var> or <var>N</var> are
unbound, if <var>T</var> is not a compound term, of if <var>N</var> is not a positive
integer. Note that previous versions of YAP would fail silently
under these errors.
</p>
</dd>
<dt><code>functor(<var>T</var>,<var>F</var>,<var>N</var>) [ISO]</code></dt>
<dd><a name="index-functor_002f3"></a>
<a name="index-functor_002f3-1"></a>
<a name="index-functor_002f3-2"></a>
<p>The top functor of term <var>T</var> is named <var>F</var> and has arity <var>N</var>.
</p>
<p>When <var>T</var> is not instantiated, <var>F</var> and <var>N</var> must be. If
<var>N</var> is 0, <var>F</var> must be an atomic symbol, which will be unified
with <var>T</var>. If <var>N</var> is not 0, then <var>F</var> must be an atom and
<var>T</var> becomes instantiated to the most general term having functor
<var>F</var> and arity <var>N</var>. If <var>T</var> is instantiated to a term then
<var>F</var> and <var>N</var> are respectively unified with its top functor name
and arity.
</p>
<p>In the current version of YAP the arity <var>N</var> must be an
integer. Previous versions allowed evaluable expressions, as long as the
expression would evaluate to an integer. This feature is not available
in the ISO Prolog standard.
</p>
</dd>
<dt><code><var>T</var> =.. <var>L</var> [ISO]</code></dt>
<dd><a name="index-_003d_002e_002e_002f2"></a>
<a name="index-_003d_002e_002e_002f2-1"></a>
<a name="index-_003d_002e_002e_002f2-2"></a>
<p>The list <var>L</var> is built with the functor and arguments of the term
<var>T</var>. If <var>T</var> is instantiated to a variable, then <var>L</var> must be
instantiated either to a list whose head is an atom, or to a list
consisting of just a number.
</p>
</dd>
<dt><code><var>X</var> = <var>Y</var> [ISO]</code></dt>
<dd><a name="index-_003d_002f2"></a>
<a name="index-_003d_002f2-1"></a>
<a name="index-_003d_002f2-2"></a>
<p>Tries to unify terms <var>X</var> and <var>Y</var>.
</p>
</dd>
<dt><code><var>X</var> \= <var>Y</var> [ISO]</code></dt>
<dd><a name="index-_005c_003d_002f2"></a>
<a name="index-_005c_003d_002f2-1"></a>
<a name="index-_005c_003d_002f2-2"></a>
<p>Succeeds if terms <var>X</var> and <var>Y</var> are not unifiable.
</p>
</dd>
<dt><code>unify_with_occurs_check(?T1,?T2) [ISO]</code></dt>
<dd><a name="index-unify_005fwith_005foccurs_005fcheck_002f2"></a>
<a name="index-unify_005fwith_005foccurs_005fcheck_002f2-1"></a>
<a name="index-unify_005fwith_005foccurs_005fcheck_002f2-2"></a>
<p>Obtain the most general unifier of terms <var>T1</var> and <var>T2</var>, if there
is one.
</p>
<p>This predicate implements the full unification algorithm. An example:n
</p><div class="example">
<pre class="example">unify_with_occurs_check(a(X,b,Z),a(X,A,f(B)).
</pre></div>
<p>will succeed with the bindings <code>A = b</code> and <code>Z = f(B)</code>. On the
other hand:
</p><div class="example">
<pre class="example">unify_with_occurs_check(a(X,b,Z),a(X,A,f(Z)).
</pre></div>
<p>would fail, because <code>Z</code> is not unifiable with <code>f(Z)</code>. Note that
<code>(=)/2</code> would succeed for the previous examples, giving the following
bindings <code>A = b</code> and <code>Z = f(Z)</code>.
</p>
</dd>
<dt><code>copy_term(?<var>TI</var>,-<var>TF</var>) [ISO]</code></dt>
<dd><a name="index-copy_005fterm_002f2"></a>
<a name="index-copy_005fterm_002f2-1"></a>
<a name="index-copy_005fterm_002f2-2"></a>
<p>Term <var>TF</var> is a variant of the original term <var>TI</var>, such that for
each variable <var>V</var> in the term <var>TI</var> there is a new variable <var>V&rsquo;</var>
in term <var>TF</var>. Notice that:
</p>
<ul>
<li> suspended goals and attributes for attributed variables in
<var>TI</var> are also duplicated;
</li><li> ground terms are shared between the new and the old term.
</li></ul>
<p>If you do not want any sharing to occur please use
<code>duplicate_term/2</code>.
</p>
</dd>
<dt><code>duplicate_term(?<var>TI</var>,-<var>TF</var>)</code></dt>
<dd><a name="index-duplicate_005fterm_002f2"></a>
<a name="index-duplicate_005fterm_002f2-1"></a>
<a name="index-duplicate_005fterm_002f2-2"></a>
<p>Term <var>TF</var> is a variant of the original term <var>TI</var>, such that
for each variable <var>V</var> in the term <var>TI</var> there is a new variable
<var>V&rsquo;</var> in term <var>TF</var>, and the two terms do not share any
structure. All suspended goals and attributes for attributed variables
in <var>TI</var> are also duplicated.
</p>
<p>Also refer to <code>copy_term/2</code>.
</p>
</dd>
<dt><code>is_list(+<var>List</var>)</code></dt>
<dd><a name="index-is_005flist_002f1"></a>
<a name="index-is_005flist_002f1-1"></a>
<a name="index-is_005flist_002f1-2"></a>
<p>True when <var>List</var> is a proper list. That is, <var>List</var>
is bound to the empty list (nil) or a term with functor &rsquo;.&rsquo; and arity 2.
</p>
</dd>
<dt><code>?<var>Term1</var> =@= ?<var>Term2</var></code></dt>
<dd><a name="index-_003d_002f2-3"></a>
<a name="index-_003d_002f2-4"></a>
<a name="index-_003d_002f2-5"></a>
<p>Same as <code>variant/2</code>, succeeds if <var>Term1</var> and <var>Term2</var> are variant terms.
</p>
</dd>
<dt><code>subsumes_term(?<var>Subsumer</var>, ?<var>Subsumed</var>)</code></dt>
<dd><a name="index-subsumes_005fterm_002f2"></a>
<a name="index-subsumes_005fterm_002f2-1"></a>
<a name="index-subsumes_005fterm_002f2-2"></a>
<p>Succeed if <var>Submuser</var> subsumes <var>Subsuned</var> but does not bind any
variable in <var>Subsumer</var>.
</p>
</dd>
<dt><code>acyclic_term(?<var>Term</var>)</code></dt>
<dd><a name="index-cyclic_005fterm_002f1"></a>
<a name="index-cyclic_005fterm_002f1-1"></a>
<a name="index-cyclic_005fterm_002f1-2"></a>
<p>Succeed if the argument <var>Term</var> is an acyclic term.
</p>
</dd>
</dl>
<hr>
<a name="Predicates-on-Atoms"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Testing-Terms" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Predicates-on-Characters" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Predicates-on-Atoms-1"></a>
<h2 class="section">6.5 Predicates on Atoms</h2>
<p>The following predicates are used to manipulate atoms:
</p>
<dl compact="compact">
<dt><code>name(<var>A</var>,<var>L</var>)</code></dt>
<dd><a name="index-name_002f2"></a>
<a name="index-name_002f2-1"></a>
<a name="index-name_002f2-2"></a>
<p>The predicate holds when at least one of the arguments is ground
(otherwise, an error message will be displayed). The argument <var>A</var> will
be unified with an atomic symbol and <var>L</var> with the list of the ASCII
codes for the characters of the external representation of <var>A</var>.
</p>
<div class="example">
<pre class="example"> name(yap,L).
</pre></div>
<p>will return:
</p><div class="example">
<pre class="example"> L = [121,97,112].
</pre></div>
<p>and
</p><div class="example">
<pre class="example"> name(3,L).
</pre></div>
<p>will return:
</p><div class="example">
<pre class="example"> L = [51].
</pre></div>
</dd>
<dt><code>atom_chars(?<var>A</var>,?<var>L</var>) [ISO]</code></dt>
<dd><a name="index-atom_005fchars_002f2"></a>
<a name="index-atom_005fchars_002f2-1"></a>
<a name="index-atom_005fchars_002f2-2"></a>
<p>The predicate holds when at least one of the arguments is ground
(otherwise, an error message will be displayed). The argument <var>A</var> must
be unifiable with an atom, and the argument <var>L</var> with the list of the
characters of <var>A</var>.
</p>
</dd>
<dt><code>atom_codes(?<var>A</var>,?<var>L</var>) [ISO]</code></dt>
<dd><a name="index-atom_005fcodes_002f2"></a>
<a name="index-atom_005fcodes_002f2-1"></a>
<a name="index-atom_005fcodes_002f2-2"></a>
<p>The predicate holds when at least one of the arguments is ground
(otherwise, an error message will be displayed). The argument <var>A</var> will
be unified with an atom and <var>L</var> with the list of the ASCII
codes for the characters of the external representation of <var>A</var>.
</p>
</dd>
<dt><code>atom_concat(+<var>As</var>,?<var>A</var>)</code></dt>
<dd><a name="index-atom_005fconcat_002f2"></a>
<a name="index-atom_005fconcat_002f2-1"></a>
<a name="index-atom_005fconcat_002f2-2"></a>
<p>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.
</p>
</dd>
<dt><code>atomic_concat(+<var>As</var>,?<var>A</var>)</code></dt>
<dd><a name="index-atomic_005fconcat_002f2"></a>
<a name="index-atomic_005fconcat_002f2-1"></a>
<a name="index-atomic_005fconcat_002f2-2"></a>
<p>The predicate holds when the first argument is a list of atomic terms, 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.
</p>
</dd>
<dt><code>atomic_list_concat(+<var>As</var>,?<var>A</var>)</code></dt>
<dd><a name="index-atomic_005flist_005fconcat_002f2"></a>
<a name="index-atomic_005flist_005fconcat_002f2-1"></a>
<a name="index-atomic_005flist_005fconcat_002f2-2"></a>
<p>The predicate holds when the first argument is a list of atomic terms, 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.
</p>
</dd>
<dt><code>atomic_list_concat(?<var>As</var>,+<var>Separator</var>,?<var>A</var>)</code></dt>
<dd><a name="index-atomic_005flist_005fconcat_002f3"></a>
<a name="index-atomic_005flist_005fconcat_002f3-1"></a>
<a name="index-atomic_005flist_005fconcat_002f3-2"></a>
<p>Creates an atom just like <code>atomic_list_concat/2</code>, but inserts
<var>Separator</var> between each pair of atoms. For example:
</p>
<div class="example">
<pre class="example">?- atomic_list_concat([gnu, gnat], ', ', A).
A = 'gnu, gnat'
</pre></div>
<p>YAP emulates the SWI-Prolog version of this predicate that can also be
used to split atoms by instantiating <var>Separator</var> and <var>Atom</var> as
shown below.
</p>
<div class="example">
<pre class="example">?- atomic_list_concat(L, -, 'gnu-gnat').
L = [gnu, gnat]
</pre></div>
</dd>
<dt><code>atom_length(+<var>A</var>,?<var>I</var>) [ISO]</code></dt>
<dd><a name="index-atom_005flength_002f2"></a>
<a name="index-atom_005flength_002f2-1"></a>
<a name="index-atom_005flength_002f2-2"></a>
<p>The predicate holds when the first argument is an atom, and the second
unifies with the number of characters forming that atom.
</p>
</dd>
<dt><code>atom_concat(?<var>A1</var>,?<var>A2</var>,?<var>A12</var>) [ISO]</code></dt>
<dd><a name="index-atom_005fconcat_002f3"></a>
<a name="index-atom_005fconcat_002f3-1"></a>
<a name="index-atom_005fconcat_002f3-2"></a>
<p>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 <var>A12</var>.
</p>
<p>If <var>A1</var> and <var>A2</var> are unbound, the built-in will find all the atoms
that concatenated give <var>A12</var>.
</p>
</dd>
<dt><code>number_chars(?<var>I</var>,?<var>L</var>) [ISO]</code></dt>
<dd><a name="index-number_005fchars_002f2"></a>
<a name="index-number_005fchars_002f2-1"></a>
<a name="index-number_005fchars_002f2-2"></a>
<p>The predicate holds when at least one of the arguments is ground
(otherwise, an error message will be displayed). The argument <var>I</var> must
be unifiable with a number, and the argument <var>L</var> with the list of the
characters of the external representation of <var>I</var>.
</p>
</dd>
<dt><code>number_codes(?<var>A</var>,?<var>L</var>) [ISO]</code></dt>
<dd><a name="index-number_005fcodes_002f2"></a>
<a name="index-number_005fcodes_002f2-1"></a>
<a name="index-number_005fcodes_002f2-2"></a>
<p>The predicate holds when at least one of the arguments is ground
(otherwise, an error message will be displayed). The argument <var>A</var>
will be unified with a number and <var>L</var> with the list of the ASCII
codes for the characters of the external representation of <var>A</var>.
</p>
</dd>
<dt><code>atom_number(?<var>Atom</var>,?<var>Number</var>)</code></dt>
<dd><a name="index-atom_005fnumber_002f2"></a>
<a name="index-atom_005fnumber_002f2-1"></a>
<a name="index-atom_005fnumber_002f2-2"></a>
<p>The predicate holds when at least one of the arguments is ground
(otherwise, an error message will be displayed). If the argument
<var>Atom</var> is an atom, <var>Number</var> must be the number corresponding
to the characters in <var>Atom</var>, otherwise the characters in
<var>Atom</var> must encode a number <var>Number</var>.
</p>
</dd>
<dt><code>number_atom(?<var>I</var>,?<var>L</var>)</code></dt>
<dd><a name="index-number_005fatom_002f2"></a>
<a name="index-number_005fatom_002f2-1"></a>
<a name="index-number_005fatom_002f2-2"></a>
<p>The predicate holds when at least one of the arguments is ground
(otherwise, an error message will be displayed). The argument <var>I</var> must
be unifiable with a number, and the argument <var>L</var> must be unifiable
with an atom representing the number.
</p>
</dd>
<dt><code>sub_atom(+<var>A</var>,?<var>Bef</var>, ?<var>Size</var>, ?<var>After</var>, ?<var>At_out</var>) [ISO]</code></dt>
<dd><a name="index-sub_005fatom_002f5"></a>
<a name="index-sub_005fatom_002f5-1"></a>
<a name="index-sub_005fatom_002f5-2"></a>
<p>True when <var>A</var> and <var>At_out</var> are atoms such that the name of
<var>At_out</var> has size <var>Size</var> and is a sub-string of the name of
<var>A</var>, such that <var>Bef</var> is the number of characters before and
<var>After</var> the number of characters afterwards.
</p>
<p>Note that <var>A</var> must always be known, but <var>At_out</var> can be unbound when
calling this built-in. If all the arguments for <code>sub_atom/5</code> but <var>A</var>
are unbound, the built-in will backtrack through all possible
sub-strings of <var>A</var>.
</p>
</dd>
</dl>
<hr>
<a name="Predicates-on-Characters"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Predicates-on-Atoms" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Comparing-Terms" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Predicates-on-Characters-1"></a>
<h2 class="section">6.6 Predicates on Characters</h2>
<p>The following predicates are used to manipulate characters:
</p>
<dl compact="compact">
<dt><code>char_code(?<var>A</var>,?<var>I</var>) [ISO]</code></dt>
<dd><a name="index-char_005fcode_002f2"></a>
<a name="index-char_005fcode_002f2-1"></a>
<a name="index-char_005fcode_002f2-2"></a>
<p>The built-in succeeds with <var>A</var> bound to character represented as an
atom, and <var>I</var> bound to the character code represented as an
integer. At least, one of either <var>A</var> or <var>I</var> must be bound before
the call.
</p>
</dd>
<dt><code>char_type(?<var>Char</var>, ?<var>Type</var>)</code></dt>
<dd><a name="index-char_005ftype_002f2"></a>
<a name="index-char_005ftype_002f2-1"></a>
<a name="index-char_005ftype_002f2-2"></a>
<p> Tests or generates alternative <var>Types</var> or <var>Chars</var>. The
character-types are inspired by the standard <code>C</code>
<code>&lt;ctype.h&gt;</code> primitives.
</p>
<dl compact="compact">
<dt><code>alnum</code></dt>
<dd><p> <var>Char</var> is a letter (upper- or lowercase) or digit.
</p>
</dd>
<dt><code>alpha</code></dt>
<dd><p> <var>Char</var> is a letter (upper- or lowercase).
</p>
</dd>
<dt><code>csym</code></dt>
<dd><p> <var>Char</var> is a letter (upper- or lowercase), digit or the underscore (_). These are valid C- and Prolog symbol characters.
</p>
</dd>
<dt><code>csymf</code></dt>
<dd><p> <var>Char</var> is a letter (upper- or lowercase) or the underscore (_). These are valid first characters for C- and Prolog symbols
</p>
</dd>
<dt><code>ascii</code></dt>
<dd><p> <var>Char</var> is a 7-bits ASCII character (0..127).
</p>
</dd>
<dt><code>white</code></dt>
<dd><p> <var>Char</var> is a space or tab. E.i. white space inside a line.
</p>
</dd>
<dt><code>cntrl</code></dt>
<dd><p> <var>Char</var> is an ASCII control-character (0..31).
</p>
</dd>
<dt><code>digit</code></dt>
<dd><p> <var>Char</var> is a digit.
</p>
</dd>
<dt><code>digit(<var>Weight</var>)</code></dt>
<dd><p> <var>Char</var> is a digit with value
<var>Weight</var>. I.e. <code>char_type(X, digit(6))</code> yields <code>X =
'6'</code>. Useful for parsing numbers.
</p>
</dd>
<dt><code>xdigit(<var>Weight</var>)</code></dt>
<dd><p> <var>Char</var> is a hexa-decimal digit with value <var>Weight</var>. I.e. char_type(a, xdigit(X) yields X = &rsquo;10&rsquo;. Useful for parsing numbers.
</p>
</dd>
<dt><code>graph</code></dt>
<dd><p> <var>Char</var> produces a visible mark on a page when printed. Note that the space is not included!
</p>
</dd>
<dt><code>lower</code></dt>
<dd><p> <var>Char</var> is a lower-case letter.
</p>
</dd>
<dt><code>lower(Upper)</code></dt>
<dd><p> <var>Char</var> is a lower-case version of <var>Upper</var>. Only true if
<var>Char</var> is lowercase and <var>Upper</var> uppercase.
</p>
</dd>
<dt><code>to_lower(Upper)</code></dt>
<dd><p> <var>Char</var> is a lower-case version of Upper. For non-letters, or letter without case, <var>Char</var> and Lower are the same. See also upcase_atom/2 and downcase_atom/2.
</p>
</dd>
<dt><code>upper</code></dt>
<dd><p> <var>Char</var> is an upper-case letter.
</p>
</dd>
<dt><code>upper(Lower)</code></dt>
<dd><p> <var>Char</var> is an upper-case version of Lower. Only true if <var>Char</var> is uppercase and Lower lowercase.
</p>
</dd>
<dt><code>to_upper(Lower)</code></dt>
<dd><p> <var>Char</var> is an upper-case version of Lower. For non-letters, or letter without case, <var>Char</var> and Lower are the same. See also upcase_atom/2 and downcase_atom/2.
</p>
</dd>
<dt><code>punct</code></dt>
<dd><p> <var>Char</var> is a punctuation character. This is a graph character that is not a letter or digit.
</p>
</dd>
<dt><code>space</code></dt>
<dd><p> <var>Char</var> is some form of layout character (tab, vertical-tab, newline, etc.).
</p>
</dd>
<dt><code>end_of_file</code></dt>
<dd><p> <var>Char</var> is -1.
</p>
</dd>
<dt><code>end_of_line</code></dt>
<dd><p> <var>Char</var> ends a line (ASCII: 10..13).
</p>
</dd>
<dt><code>newline</code></dt>
<dd><p> <var>Char</var> is a the newline character (10).
</p>
</dd>
<dt><code>period</code></dt>
<dd><p> <var>Char</var> counts as the end of a sentence (.,!,?).
</p>
</dd>
<dt><code>quote</code></dt>
<dd><p> <var>Char</var> is a quote-character (&quot;, &rsquo;, &lsquo;).
</p>
</dd>
<dt><code>paren(Close)</code></dt>
<dd><p> <var>Char</var> is an open-parenthesis and Close is the corresponding close-parenthesis.
</p></dd>
</dl>
</dd>
<dt><code>code_type(?<var>Code</var>, ?<var>Type</var>)</code></dt>
<dd><a name="index-code_005ftype_002f2"></a>
<a name="index-code_005ftype_002f2-1"></a>
<a name="index-code_005ftype_002f2-2"></a>
<p> As <code>char_type/2</code>, but uses character-codes rather than
one-character atoms. Please note that both predicates are as
flexible as possible. They handle either representation if the
argument is instantiated and only will instantiate with an integer
code or one-character atom depending of the version used. See also
the prolog-flag <code>double_quotes</code> and the built-in predicates
<code>atom_chars/2</code> and <code>atom_codes/2</code>.
</p>
</dd>
</dl>
<hr>
<a name="Comparing-Terms"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Predicates-on-Characters" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Arithmetic" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Comparing-Terms-1"></a>
<h2 class="section">6.7 Comparing Terms</h2>
<p>The following predicates are used to compare and order terms, using the
standard ordering:
</p>
<ul>
<li>
variables come before numbers, numbers come before atoms which in turn
come before compound terms, i.e.: variables @&lt; numbers @&lt; atoms @&lt;
compound terms.
</li><li>
Variables are roughly ordered by &quot;age&quot; (the &quot;oldest&quot; variable is put
first);
</li><li>
Floating point numbers are sorted in increasing order;
</li><li>
Rational numbers are sorted in increasing order;
</li><li>
Integers are sorted in increasing order;
</li><li>
Atoms are sorted in lexicographic order;
</li><li>
Compound terms are ordered first by arity of the main functor, then by
the name of the main functor, and finally by their arguments in
left-to-right order.
</li></ul>
<dl compact="compact">
<dt><code>compare(<var>C</var>,<var>X</var>,<var>Y</var>)</code></dt>
<dd><a name="index-compare_002f3"></a>
<a name="index-compare_002f3-1"></a>
<a name="index-compare_002f3-2"></a>
<p>As a result of comparing <var>X</var> and <var>Y</var>, <var>C</var> may take one of
the following values:
</p>
<ul>
<li>
<code>=</code> if <var>X</var> and <var>Y</var> are identical;
</li><li>
<code>&lt;</code> if <var>X</var> precedes <var>Y</var> in the defined order;
</li><li>
<code>&gt;</code> if <var>Y</var> precedes <var>X</var> in the defined order;
</li></ul>
</dd>
<dt><code><var>X</var> == <var>Y</var> [ISO]</code></dt>
<dd><a name="index-_003d_003d_002f2"></a>
<a name="index-_003d_003d_002f2-1"></a>
<a name="index-_003d_003d_002f2-2"></a>
<p>Succeeds if terms <var>X</var> and <var>Y</var> are strictly identical. The
difference between this predicate and <code>=/2</code> is that, if one of the
arguments is a free variable, it only succeeds when they have already
been unified.
</p>
<div class="example">
<pre class="example">?- X == Y.
</pre></div>
<p>fails, but,
</p><div class="example">
<pre class="example">?- X = Y, X == Y.
</pre></div>
<p>succeeds.
</p><div class="example">
<pre class="example">?- X == 2.
</pre></div>
<p>fails, but,
</p><div class="example">
<pre class="example">?- X = 2, X == 2.
</pre></div>
<p>succeeds.
</p>
</dd>
<dt><code><var>X</var> \== <var>Y</var> [ISO]</code></dt>
<dd><a name="index-_005c_003d_003d_002f2"></a>
<a name="index-_005c_003d_003d_002f2-1"></a>
<a name="index-_005c_003d_003d_002f2-2"></a>
<p>Terms <var>X</var> and <var>Y</var> are not strictly identical.
</p>
</dd>
<dt><code><var>X</var> @&lt; <var>Y</var> [ISO]</code></dt>
<dd><a name="index-_0040_003c_002f2"></a>
<a name="index-_0040_003c_002f2-1"></a>
<a name="index-_0040_003c_002f2-2"></a>
<p>Term <var>X</var> precedes term <var>Y</var> in the standard order.
</p>
</dd>
<dt><code><var>X</var> @=&lt; <var>Y</var> [ISO]</code></dt>
<dd><a name="index-_0040_003d_003c_002f2"></a>
<a name="index-_0040_003c_002f2-3"></a>
<a name="index-_0040_003c_002f2-4"></a>
<p>Term <var>X</var> does not follow term <var>Y</var> in the standard order.
</p>
</dd>
<dt><code><var>X</var> @&gt; <var>Y</var> [ISO]</code></dt>
<dd><a name="index-_0040_003e_002f2"></a>
<a name="index-_0040_003e_002f2-1"></a>
<a name="index-_0040_003e_002f2-2"></a>
<p>Term <var>X</var> follows term <var>Y</var> in the standard order.
</p>
</dd>
<dt><code><var>X</var> @&gt;= <var>Y</var> [ISO]</code></dt>
<dd><a name="index-_0040_003e_003d_002f2"></a>
<a name="index-_0040_003e_003d_002f2-1"></a>
<a name="index-_0040_003e_003d_002f2-2"></a>
<p>Term <var>X</var> does not precede term <var>Y</var> in the standard order.
</p>
</dd>
<dt><code>sort(+<var>L</var>,-<var>S</var>)</code></dt>
<dd><a name="index-sort_002f2"></a>
<a name="index-sort_002f2-1"></a>
<a name="index-sort_002f2-2"></a>
<p>Unifies <var>S</var> with the list obtained by sorting <var>L</var> and merging
identical (in the sense of <code>==</code>) elements.
</p>
</dd>
<dt><code>keysort(+<var>L</var>,<var>S</var>)</code></dt>
<dd><a name="index-keysort_002f2"></a>
<a name="index-keysort_002f2-1"></a>
<a name="index-keysort_002f2-2"></a>
<p>Assuming L is a list of the form <code><var>Key</var>-<var>Value</var></code>,
<code>keysort(+<var>L</var>,<var>S</var>)</code> unifies <var>S</var> with the list obtained
from <var>L</var>, by sorting its elements according to the value of
<var>Key</var>.
</p><div class="example">
<pre class="example">?- keysort([3-a,1-b,2-c,1-a,1-b],S).
</pre></div>
<p>would return:
</p><div class="example">
<pre class="example">S = [1-b,1-a,1-b,2-c,3-a]
</pre></div>
</dd>
<dt><code>predsort(+<var>Pred</var>, +<var>List</var>, -<var>Sorted</var>)</code></dt>
<dd><a name="index-predsort_002f3"></a>
<a name="index-predsort_002f3-1"></a>
<a name="index-predsort_002f3-2"></a>
<p>Sorts similar to sort/2, but determines the order of two terms by
calling <var>Pred</var>(-<var>Delta</var>, +<var>E1</var>, +<var>E2</var>) . This call must
unify <var>Delta</var> with one of <code>&lt;</code>, <code>&gt;</code> or <code>=</code>. If
built-in predicate compare/3 is used, the result is the same as
sort/2.
</p>
</dd>
<dt><code>length(?<var>L</var>,?<var>S</var>)</code></dt>
<dd><a name="index-length_002f2"></a>
<a name="index-length_002f2-1"></a>
<a name="index-length_002f2-2"></a>
<p>Unify the well-defined list <var>L</var> with its length. The procedure can
be used to find the length of a pre-defined list, or to build a list
of length <var>S</var>.
</p>
</dd>
</dl>
<hr>
<a name="Arithmetic"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Comparing-Terms" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Arithmetic-1"></a>
<h2 class="section">6.8 Arithmetic</h2>
<p>YAP now supports several different numeric types:
</p>
<dl compact="compact">
<dt><code>integers</code></dt>
<dd><p> When YAP is built using the GNU multiple precision arithmetic
library (GMP), integer arithmetic is unbounded, which means that
the size of integers is limited by available memory only. Without
GMP, SWI-Prolog integers have the same size as an address. The
type of integer support can be detected using the Prolog flags
bounded, min_integer and max_integer. As the use of GMP is
default, most of the following descriptions assume unbounded
integer arithmetic.
</p>
<p> Internally, SWI-Prolog has three integer representations. Small
integers (defined by the Prolog flag max_tagged_integer) are
encoded directly. Larger integers are represented as cell values
on the global stack. Integers that do not fit in 64-bit are
represented as serialised GNU MPZ structures on the global stack.
</p>
</dd>
<dt><code>number</code></dt>
<dd><p> Rational numbers (Q) are quotients of two integers. Rational
arithmetic is only provided if GMP is used (see above). Rational
numbers that are returned from is/2 are canonical, which means M
is positive and N and M have no common divisors. Rational numbers
are introduced in the computation using the rational/1,
rationalize/1 or the rdiv/2 (rational division) function.
</p>
</dd>
<dt><code>float</code></dt>
<dd><p> Floating point numbers are represented using the C-type double. On most today platforms these are 64-bit IEEE floating point numbers.
</p>
</dd>
</dl>
<p>Arithmetic functions that require integer arguments accept, in addition
to integers, rational numbers with denominator &lsquo;1&rsquo; and floating point
numbers that can be accurately converted to integers. If the required
argument is a float the argument is converted to float. Note that
conversion of integers to floating point numbers may raise an overflow
exception. In all other cases, arguments are converted to the same type
using the order integer to rational number to floating point number.
</p>
<p>Arithmetic expressions in YAP may use the following operators or
<i>evaluable predicates</i>:
</p>
<dl compact="compact">
<dt><code>+<var>X</var></code></dt>
<dd><p>The value of <var>X</var> itself.
</p>
</dd>
<dt><code>-<var>X</var> [ISO]</code></dt>
<dd><p>Symmetric value.
</p>
</dd>
<dt><code><var>X</var>+<var>Y</var> [ISO]</code></dt>
<dd><p>Sum.
</p>
</dd>
<dt><code><var>X</var>-<var>Y</var> [ISO]</code></dt>
<dd><p>Difference.
</p>
</dd>
<dt><code><var>X</var>*<var>Y</var> [ISO]</code></dt>
<dd><p>Product.
</p>
</dd>
<dt><code><var>X</var>/<var>Y</var> [ISO]</code></dt>
<dd><p>Quotient.
</p>
</dd>
<dt><code><var>X</var>//<var>Y</var> [ISO]</code></dt>
<dd><p>Integer quotient.
</p>
</dd>
<dt><code><var>X</var> mod <var>Y</var> [ISO]</code></dt>
<dd><p>Integer module operator, always positive.
</p>
</dd>
<dt><code><var>X</var> rem <var>Y</var> [ISO]</code></dt>
<dd><p>Integer remainder, similar to <code>mod</code> but always has the same sign
<code>X</code>.
</p>
</dd>
<dt><code><var>X</var> div <var>Y</var> [ISO]</code></dt>
<dd><p>Integer division, as if defined by <code>(<var>X</var> - <var>X</var> mod <var>Y</var>)
// <var>Y</var></code>.
</p>
</dd>
<dt><code>exp(<var>X</var>) [ISO]</code></dt>
<dd><p>Natural exponential.
</p>
</dd>
<dt><code>log(<var>X</var>) [ISO]</code></dt>
<dd><p>Natural logarithm.
</p>
</dd>
<dt><code>log10(<var>X</var>)</code></dt>
<dd><p>Decimal logarithm.
</p>
</dd>
<dt><code>sqrt(<var>X</var>) [ISO]</code></dt>
<dd><p>Square root.
</p>
</dd>
<dt><code>sin(<var>X</var>) [ISO]</code></dt>
<dd><p>Sine.
</p>
</dd>
<dt><code>cos(<var>X</var>) [ISO]</code></dt>
<dd><p>Cosine.
</p>
</dd>
<dt><code>tan(<var>X</var>)</code></dt>
<dd><p>Tangent.
</p>
</dd>
<dt><code>asin(<var>X</var>)</code></dt>
<dd><p>Arc sine.
</p>
</dd>
<dt><code>acos(<var>X</var>)</code></dt>
<dd><p>Arc cosine.
</p>
</dd>
<dt><code>atan(<var>X</var>) [ISO]</code></dt>
<dd><p>Arc tangent.
</p>
</dd>
<dt><code>atan(<var>X</var>,<var>Y</var>)</code></dt>
<dd><p>Four-quadrant arc tangent. Also available as <code>atan2/2</code>.
</p>
</dd>
<dt><code>sinh(<var>X</var>)</code></dt>
<dd><p>Hyperbolic sine.
</p>
</dd>
<dt><code>cosh(<var>X</var>)</code></dt>
<dd><p>Hyperbolic cosine.
</p>
</dd>
<dt><code>tanh(<var>X</var>)</code></dt>
<dd><p>Hyperbolic tangent.
</p>
</dd>
<dt><code>asinh(<var>X</var>)</code></dt>
<dd><p>Hyperbolic arc sine.
</p>
</dd>
<dt><code>acosh(<var>X</var>)</code></dt>
<dd><p>Hyperbolic arc cosine.
</p>
</dd>
<dt><code>atanh(<var>X</var>)</code></dt>
<dd><p>Hyperbolic arc tangent.
</p>
</dd>
<dt><code>lgamma(<var>X</var>)</code></dt>
<dd><p>Logarithm of gamma function.
</p>
</dd>
<dt><code>erf(<var>X</var>)</code></dt>
<dd><p>Gaussian error function.
</p>
</dd>
<dt><code>erfc(<var>X</var>)</code></dt>
<dd><p>Complementary gaussian error function.
</p>
</dd>
<dt><code>random(<var>X</var>) [ISO]</code></dt>
<dd><p>An integer random number between 0 and <var>X</var>.
</p>
<p>In <code>iso</code> language mode the argument must be a floating
point-number, the result is an integer and it the float is equidistant
it is rounded up, that is, to the least integer greater than <var>X</var>.
</p>
</dd>
<dt><code>integer(<var>X</var>)</code></dt>
<dd><p>If <var>X</var> evaluates to a float, the integer between the value of <var>X</var>
and 0 closest to the value of <var>X</var>, else if <var>X</var> evaluates to an
integer, the value of <var>X</var>.
</p>
</dd>
<dt><code>float(<var>X</var>) [ISO]</code></dt>
<dd><p>If <var>X</var> evaluates to an integer, the corresponding float, else the float
itself.
</p>
</dd>
<dt><code>float_fractional_part(<var>X</var>) [ISO]</code></dt>
<dd><p>The fractional part of the floating point number <var>X</var>, or <code>0.0</code>
if <var>X</var> is an integer. In the <code>iso</code> language mode,
<var>X</var> must be an integer.
</p>
</dd>
<dt><code>float_integer_part(<var>X</var>) [ISO]</code></dt>
<dd><p>The float giving the integer part of the floating point number <var>X</var>,
or <var>X</var> if <var>X</var> is an integer. In the <code>iso</code> language mode,
<var>X</var> must be an integer.
</p>
</dd>
<dt><code>abs(<var>X</var>) [ISO]</code></dt>
<dd><p>The absolute value of <var>X</var>.
</p>
</dd>
<dt><code>ceiling(<var>X</var>) [ISO]</code></dt>
<dd><p>The integer that is the smallest integral value not smaller than <var>X</var>.
</p>
<p>In <code>iso</code> language mode the argument must be a floating
point-number and the result is an integer.
</p>
</dd>
<dt><code>floor(<var>X</var>) [ISO]</code></dt>
<dd><p>The integer that is the greatest integral value not greater than <var>X</var>.
</p>
<p>In <code>iso</code> language mode the argument must be a floating
point-number and the result is an integer.
</p>
</dd>
<dt><code>round(<var>X</var>) [ISO]</code></dt>
<dd><p>The nearest integral value to <var>X</var>. If <var>X</var> is
equidistant to two integers, it will be rounded to the closest even
integral value.
</p>
<p>In <code>iso</code> language mode the argument must be a floating
point-number, the result is an integer and it the float is equidistant
it is rounded up, that is, to the least integer greater than <var>X</var>.
</p>
</dd>
<dt><code>sign(<var>X</var>) [ISO]</code></dt>
<dd><p>Return 1 if the <var>X</var> evaluates to a positive integer, 0 it if
evaluates to 0, and -1 if it evaluates to a negative integer. If <var>X</var>
evaluates to a floating-point number return 1.0 for a positive <var>X</var>,
0.0 for 0.0, and -1.0 otherwise.
</p>
</dd>
<dt><code>truncate(<var>X</var>) [ISO]</code></dt>
<dd><p>The integral value between <var>X</var> and 0 closest to
<var>X</var>.
</p>
</dd>
<dt><code>rational(<var>X</var>)</code></dt>
<dd><p>Convert the expression <var>X</var> to a rational number or integer. The
function returns the input on integers and rational numbers. For
floating point numbers, the returned rational number exactly represents
the float. As floats cannot exactly represent all decimal numbers the
results may be surprising. In the examples below, doubles can represent
<code>0.25</code> and the result is as expected, in contrast to the result of
<code>rational(0.1)</code>. The function <code>rationalize/1</code> gives a more
intuitive result.
</p>
<div class="example">
<pre class="example">?- A is rational(0.25).
A is 1 rdiv 4
?- A is rational(0.1).
A = 3602879701896397 rdiv 36028797018963968
</pre></div>
</dd>
<dt><code>rationalize(<var>X</var>)</code></dt>
<dd><p>Convert the Expr to a rational number or integer. The function is
similar to <code>rational/1</code>, but the result is only accurate within the
rounding error of floating point numbers, generally producing a much
smaller denominator.
</p>
<div class="example">
<pre class="example">?- A is rationalize(0.25).
A = 1 rdiv 4
?- A is rationalize(0.1).
A = 1 rdiv 10
</pre></div>
</dd>
<dt><code>max(<var>X</var>,<var>Y</var>)</code></dt>
<dd><p>The greater value of <var>X</var> and <var>Y</var>.
</p>
</dd>
<dt><code>min(<var>X</var>,<var>Y</var>)</code></dt>
<dd><p>The lesser value of <var>X</var> and <var>Y</var>.
</p>
</dd>
<dt><code><var>X</var> ^ <var>Y</var></code></dt>
<dd><p><var>X</var> raised to the power of <var>Y</var>, (from the C-Prolog syntax).
</p>
</dd>
<dt><code>exp(<var>X</var>,<var>Y</var>)</code></dt>
<dd><p><var>X</var> raised to the power of <var>Y</var>, (from the Quintus Prolog syntax).
</p>
</dd>
<dt><code><var>X</var> ** <var>Y</var> [ISO]</code></dt>
<dd><p><var>X</var> raised to the power of <var>Y</var> (from ISO).
</p>
</dd>
<dt><code><var>X</var> /\ <var>Y</var> [ISO]</code></dt>
<dd><p>Integer bitwise conjunction.
</p>
</dd>
<dt><code><var>X</var> \/ <var>Y</var> [ISO]</code></dt>
<dd><p>Integer bitwise disjunction.
</p>
</dd>
<dt><code><var>X</var> # <var>Y</var></code></dt>
<dt><code><var>X</var> &gt;&lt; <var>Y</var></code></dt>
<dt><code>xor(<var>X</var> , <var>Y</var>)</code></dt>
<dd><p>Integer bitwise exclusive disjunction.
</p>
</dd>
<dt><code><var>X</var> &lt;&lt; <var>Y</var></code></dt>
<dd><p>Integer bitwise left logical shift of <var>X</var> by <var>Y</var> places.
</p>
</dd>
<dt><code><var>X</var> &gt;&gt; <var>Y</var> [ISO]</code></dt>
<dd><p>Integer bitwise right logical shift of <var>X</var> by <var>Y</var> places.
</p>
</dd>
<dt><code>\ <var>X</var> [ISO]</code></dt>
<dd><p>Integer bitwise negation.
</p>
</dd>
<dt><code>gcd(<var>X</var>,<var>Y</var>)</code></dt>
<dd><p>The greatest common divisor of the two integers <var>X</var> and <var>Y</var>.
</p>
</dd>
<dt><code>msb(<var>X</var>)</code></dt>
<dd><p>The most significant bit of the non-negative integer <var>X</var>.
</p>
</dd>
<dt><code>lsb(<var>X</var>)</code></dt>
<dd><p>The least significant bit of the non-negative integer <var>X</var>.
</p>
</dd>
<dt><code>popcount(<var>X</var>)</code></dt>
<dd><p>The number of bits set to <code>1</code> in the binary representation of the
non-negative integer <var>X</var>.
</p>
</dd>
<dt><code>[<var>X</var>]</code></dt>
<dd><p>Evaluates to <var>X</var> for expression <var>X</var>. Useful because character
strings in Prolog are lists of character codes.
</p>
<div class="example">
<pre class="example">X is Y*10+C-&quot;0&quot;
</pre></div>
<p>is the same as
</p><div class="example">
<pre class="example">X is Y*10+C-[48].
</pre></div>
<p>which would be evaluated as:
</p><div class="example">
<pre class="example">X is Y*10+C-48.
</pre></div>
</dd>
</dl>
<p>Besides numbers and the arithmetic operators described above, certain
atoms have a special meaning when present in arithmetic expressions:
</p>
<dl compact="compact">
<dt><code>pi</code></dt>
<dd><p>The value of <em>pi</em>, the ratio of a circle&rsquo;s circumference to its
diameter.
</p>
</dd>
<dt><code>e</code></dt>
<dd><p>The base of the natural logarithms.
</p>
</dd>
<dt><code>epsilon</code></dt>
<dd><p>The difference between the float <code>1.0</code> and the first larger floating point
number.
</p>
</dd>
<dt><code>inf</code></dt>
<dd><p>Infinity according to the IEEE Floating-Point standard. Note that
evaluating this term will generate a domain error in the <code>iso</code>
language mode.
</p>
</dd>
<dt><code>nan</code></dt>
<dd><p>Not-a-number according to the IEEE Floating-Point standard. Note that
evaluating this term will generate a domain error in the <code>iso</code>
language mode.
</p>
</dd>
<dt><code>cputime</code></dt>
<dd><p>CPU time in seconds, since YAP was invoked.
</p>
</dd>
<dt><code>heapused</code></dt>
<dd><p>Heap space used, in bytes.
</p>
</dd>
<dt><code>local</code></dt>
<dd><p>Local stack in use, in bytes.
</p>
</dd>
<dt><code>global</code></dt>
<dd><p>Global stack in use, in bytes.
</p>
</dd>
<dt><code>random</code></dt>
<dd><p>A &quot;random&quot; floating point number between 0 and 1.
</p>
</dd>
</dl>
<p>The primitive YAP predicates involving arithmetic expressions are:
</p>
<dl compact="compact">
<dt><code><var>X</var> is +<var>Y</var> [2]</code></dt>
<dd><a name="index-is_002f2"></a>
<a name="index-is_002f2-1"></a>
<a name="index-is_002f2-2"></a>
<p>This predicate succeeds iff the result of evaluating the expression
<var>Y</var> unifies with <var>X</var>. This is the predicate normally used to
perform evaluation of arithmetic expressions:
</p>
<div class="example">
<pre class="example">X is 2+3*4
</pre></div>
<p>succeeds with <code>X = 14</code>.
</p>
</dd>
<dt><code>+<var>X</var> &lt; +<var>Y</var> [ISO]</code></dt>
<dd><a name="index-_003c_002f2"></a>
<a name="index-_003c_002f2-1"></a>
<a name="index-_003c_002f2-2"></a>
<p>The value of the expression <var>X</var> is less than the value of expression
<var>Y</var>.
</p>
</dd>
<dt><code>+<var>X</var> =&lt; +<var>Y</var> [ISO]</code></dt>
<dd><a name="index-_003d_003c_002f2"></a>
<a name="index-_003d_003c_002f2-1"></a>
<a name="index-_003d_003c_002f2-2"></a>
<p>The value of the expression <var>X</var> is less than or equal to the value
of expression <var>Y</var>.
</p>
</dd>
<dt><code>+<var>X</var> &gt; +<var>Y</var> [ISO]</code></dt>
<dd><a name="index-_003e_002f2"></a>
<a name="index-_003e_002f2-1"></a>
<a name="index-_003e_002f2-2"></a>
<p>The value of the expression <var>X</var> is greater than the value of
expression <var>Y</var>.
</p>
</dd>
<dt><code>+<var>X</var> &gt;= +<var>Y</var> [ISO]</code></dt>
<dd><a name="index-_003e_003d_002f2"></a>
<a name="index-_003e_003d_002f2-1"></a>
<a name="index-_003e_003d_002f2-2"></a>
<p>The value of the expression <var>X</var> is greater than or equal to the
value of expression <var>Y</var>.
</p>
</dd>
<dt><code>+<var>X</var> =:= +<var>Y</var> [ISO]</code></dt>
<dd><a name="index-_003d_003a_003d_002f2"></a>
<a name="index-_003d_003a_003d_002f2-1"></a>
<a name="index-_003d_003a_003d_002f2-2"></a>
<p>The value of the expression <var>X</var> is equal to the value of expression
<var>Y</var>.
</p>
</dd>
<dt><code>+<var>X</var> =\= +<var>Y</var> [ISO]</code></dt>
<dd><a name="index-_003d_005c_003d_002f2"></a>
<a name="index-_003d_005c_003d_002f2-1"></a>
<a name="index-_003d_005c_003d_002f2-2"></a>
<p>The value of the expression <var>X</var> is different from the value of
expression <var>Y</var>.
</p>
</dd>
<dt><code>srandom(+<var>X</var>)</code></dt>
<dd><a name="index-srandom_002f1"></a>
<a name="index-srandom_002f1-1"></a>
<a name="index-srandom_002f1-2"></a>
<p>Use the argument <var>X</var> as a new seed for YAP&rsquo;s random number
generator. The argument should be an integer, but floats are acceptable.
</p></dd>
</dl>
<p><strong>Notes:</strong>
</p>
<ul>
<li>
Since YAP4, YAP <em>does not</em> convert automatically between integers
and floats.
</li><li>
arguments to trigonometric functions are expressed in radians.
</li><li>
if a (non-instantiated) variable occurs in an arithmetic expression YAP
will generate an exception. If no error handler is available, execution
will be thrown back to the top-level.
</li></ul>
<p>The following predicates provide counting:
</p>
<dl compact="compact">
<dt><code>between(+<var>Low</var>, +<var>High</var>, ?<var>Value</var>)</code></dt>
<dd><a name="index-between_002f3"></a>
<a name="index-between_002f3-1"></a>
<a name="index-between_002f3-2"></a>
<p> <var>Low</var> and <var>High</var> are integers, <var>High</var> &gt;=<var>Low</var>. If
<var>Value</var> is an integer, <var>Low</var> =&lt;<var>Value</var>
=&lt;<var>High</var>. When <var>Value</var> is a variable it is successively
bound to all integers between <var>Low</var> and <var>High</var>. If
<var>High</var> is inf or infinite <code>between/3</code> is true iff
<var>Value</var> &gt;= <var>Low</var>, a feature that is particularly interesting
for generating integers from a certain value.
</p>
</dd>
<dt><code>succ(?<var>Int1</var>, ?<var>Int2</var>)</code></dt>
<dd><a name="index-succ_002f3"></a>
<a name="index-succ_002f3-1"></a>
<a name="index-succ_002f3-2"></a>
<p> True if <var>Int2</var> = <var>Int1</var> + 1 and <var>Int1</var> &gt;= 0. At least
one of the arguments must be instantiated to a natural number. This
predicate raises the domain-error not_less_than_zero if called with
a negative integer. E.g. <code>succ(X, 0)</code> fails silently and succ(X, -1)
raises a domain-error. The behaviour to deal with natural numbers
only was defined by Richard O&rsquo;Keefe to support the common
count-down-to-zero in a natural way.
</p>
</dd>
<dt><code>plus(?<var>Int1</var>, ?<var>Int2</var>, ?<var>Int3</var>)</code></dt>
<dd><a name="index-plus_002f3"></a>
<a name="index-plus_002f3-1"></a>
<a name="index-plus_002f3-2"></a>
<p> True if <var>Int3</var> = <var>Int1</var> + <var>Int2</var>. At least two of the
three arguments must be instantiated to integers.
</p></dd>
</dl>
<hr>
<a name="I_002fO"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Arithmetic" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Streams-and-Files" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="I_002fO-Predicates"></a>
<h2 class="section">6.9 I/O Predicates</h2>
<p>Some of the I/O predicates described below will in certain conditions
provide error messages and abort only if the file_errors flag is set.
If this flag is cleared the same predicates will just fail. Details on
setting and clearing this flag are given under 7.7.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Input/Output
</pre></th></tr><tr><td align="left" valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> C-Prolog Compatible File Handling
</td></tr>
<tr><td align="left" valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Input/Output of terms
</td></tr>
<tr><td align="left" valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Input/Output of Characters
</td></tr>
<tr><td align="left" valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Input/Output using Streams
</td></tr>
<tr><td align="left" valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> C-Prolog compatible Character I/O to terminal
</td></tr>
<tr><td align="left" valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Controlling your Input/Output
</td></tr>
<tr><td align="left" valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Using Sockets from YAP
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
</pre></th></tr></table>
<hr>
<a name="Streams-and-Files"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog-File-Handling" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Handling-Streams-and-Files-1"></a>
<h3 class="subsection">6.9.1 Handling Streams and Files</h3>
<dl compact="compact">
<dt><code>open(+<var>F</var>,+<var>M</var>,-<var>S</var>) [ISO]</code></dt>
<dd><a name="index-open_002f3"></a>
<a name="index-open_002f3-1"></a>
<a name="index-open_002f3-2"></a>
<p>Opens the file with name <var>F</var> in mode <var>M</var> (&rsquo;read&rsquo;, &rsquo;write&rsquo; or
&rsquo;append&rsquo;), returning <var>S</var> unified with the stream name.
</p>
<p>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: <code>user_input</code> for reading, <code>user_output</code> for writing
and <code>user_error</code> for writing. If there is no ambiguity, the atoms
<code>user_input</code> and <code>user_output</code> may be referred to as <code>user</code>.
</p>
<p>The <code>file_errors</code> flag controls whether errors are reported when in
mode &rsquo;read&rsquo; or &rsquo;append&rsquo; the file <var>F</var> does not exist or is not
readable, and whether in mode &rsquo;write&rsquo; or &rsquo;append&rsquo; the file is not
writable.
</p>
</dd>
<dt><code>open(+<var>F</var>,+<var>M</var>,-<var>S</var>,+<var>Opts</var>) [ISO]</code></dt>
<dd><a name="index-open_002f4"></a>
<a name="index-open_002f4-1"></a>
<a name="index-open_002f4-2"></a>
<p>Opens the file with name <var>F</var> in mode <var>M</var> (&rsquo;read&rsquo;, &rsquo;write&rsquo; or
&rsquo;append&rsquo;), returning <var>S</var> unified with the stream name, and following
these options:
</p>
<dl compact="compact">
<dt><code>type(+<var>T</var>) [ISO]</code></dt>
<dd><p>Specify whether the stream is a <code>text</code> stream (default), or a
<code>binary</code> stream.
</p>
</dd>
<dt><code>reposition(+<var>Bool</var>) [ISO]</code></dt>
<dd><p>Specify whether it is possible to reposition the stream (<code>true</code>), or
not (<code>false</code>). By default, YAP enables repositioning for all
files, except terminal files and sockets.
</p>
</dd>
<dt><code>eof_action(+<var>Action</var>) [ISO]</code></dt>
<dd><p>Specify the action to take if attempting to input characters from a
stream where we have previously found an <code>end_of_file</code>. The possible
actions are <code>error</code>, that raises an error, <code>reset</code>, that tries to
reset the stream and is used for <code>tty</code> type files, and <code>eof_code</code>,
which generates a new <code>end_of_file</code> (default for non-tty files).
</p>
</dd>
<dt><code>alias(+<var>Name</var>) [ISO]</code></dt>
<dd><p>Specify an alias to the stream. The alias <tt>Name</tt> must be an atom. The
alias can be used instead of the stream descriptor for every operation
concerning the stream.
</p>
<p>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 <code>stream_property/2</code>
</p>
</dd>
<dt><code>bom(+<var>Bool</var>)</code></dt>
<dd><p>If present and <code>true</code>, a BOM (<em>Byte Order Mark</em>) was
detected while opening the file for reading or a BOM was written while
opening the stream. See <a href="#BOM">BOM: Byte Order Mark</a> for details.
</p>
</dd>
<dt><code>encoding(+<var>Encoding</var>)</code></dt>
<dd><p>Set the encoding used for text. See <a href="#Encoding">Wide Character Support</a> for an overview of
wide character and encoding issues.
</p>
</dd>
<dt><code>representation_errors(+<var>Mode</var>)</code></dt>
<dd><p>Change the behaviour when writing characters to the stream that cannot
be represented by the encoding. The behaviour is one of <code>error</code>
(throw and I/O error exception), <code>prolog</code> (write <code>\u...\</code>
escape code or <code>xml</code> (write <code>&amp;#...;</code> XML character entity).
The initial mode is <code>prolog</code> for the user streams and
<code>error</code> for all other streams. See also <a href="#Encoding">Wide Character Support</a>.
</p>
</dd>
<dt><code>expand_filename(+<var>Mode</var>)</code></dt>
<dd><p>If <var>Mode</var> is <code>true</code> then do filename expansion, then ask Prolog
to do file name expansion before actually trying to opening the file:
this includes processing <code>~</code> characters and processing <code>$</code>
environment variables at the beginning of the file. Otherwise, just try
to open the file using the given name.
</p>
<p>The default behavior is given by the Prolog flag
<code>open_expands_filename</code>.
</p>
</dd>
</dl>
</dd>
<dt><code>close(+<var>S</var>) [ISO]</code></dt>
<dd><a name="index-close_002f1"></a>
<a name="index-close_002f1-1"></a>
<a name="index-close_002f1-2"></a>
<p>Closes the stream <var>S</var>. If <var>S</var> does not stand for a stream
currently opened an error is reported. The streams <code>user_input</code>,
<code>user_output</code>, and <code>user_error</code> can never be closed.
</p>
</dd>
<dt><code>close(+<var>S</var>,+<var>O</var>) [ISO]</code></dt>
<dd><a name="index-close_002f2"></a>
<a name="index-close_002f2-1"></a>
<a name="index-close_002f2-2"></a>
<p>Closes the stream <var>S</var>, following options <var>O</var>.
</p>
<p>The only valid options are <code>force(true)</code> and <code>force(false)</code>.
YAP currently ignores these options.
</p>
</dd>
<dt><code>time_file(+<var>File</var>,-<var>Time</var>)</code></dt>
<dd><a name="index-time_005ffile_002f2"></a>
<a name="index-time_005ffile_002f2-1"></a>
<a name="index-time_005ffile_002f2-2"></a>
<p>Unify the last modification time of <var>File</var> with
<var>Time</var>. <var>Time</var> is a floating point number expressing the seconds
elapsed since Jan 1, 1970.
</p>
</dd>
<dt><code>absolute_file_name(+<var>Name</var>,+<var>Options</var>, -<var>FullPath</var>)</code></dt>
<dt><code>absolute_file_name(+<var>Name</var>, -<var>FullPath</var>,+<var>Options</var>)</code></dt>
<dd><a name="index-absolute_005ffile_005fname_002f3"></a>
<a name="index-absolute_005ffile_005fname_002f3-1"></a>
<a name="index-absolute_005ffile_005fname_002f3-2"></a>
<p>Converts the given file specification into an absolute path.
<var>Option</var> is a list of options to guide the conversion:
</p>
<dl compact="compact">
<dt><code>extensions(+<var>ListOfExtensions</var>)</code></dt>
<dd><p>List of file-extensions to try. Default is &lsquo;<samp>''</samp>&rsquo;. For each
extension, <code>absolute_file_name/3</code> will first add the extension and then
verify the conditions imposed by the other options. If the condition
fails, the next extension of the list is tried. Extensions may be
specified both as <code>.ext</code> or plain <code>ext</code>.
</p>
</dd>
<dt><code>relative_to(+<var>FileOrDir</var>)</code></dt>
<dd><p>Resolve the path relative to the given directory or directory the
holding the given file. Without this option, paths are resolved
relative to the working directory (see <code>working_directory/2</code>) or,
if <var>Spec</var> is atomic and <code>absolute_file_name/[2,3]</code> is executed
in a directive, it uses the current source-file as reference.
</p>
</dd>
<dt><code>access(+<var>Mode</var>)</code></dt>
<dd><p>Imposes the condition access_file(<var>File</var>, <var>Mode</var>). <var>Mode</var>
is on of <code>read</code>, <code>write</code>, <code>append</code>, <code>exist</code> or
<code>none</code> (default).
See also <code>access_file/2</code>.
</p>
</dd>
<dt><code>file_type(+<var>Type</var>)</code></dt>
<dd><p>Defines extensions. Current mapping: <code>txt</code> implies <code>['']</code>,
<code>prolog</code> implies <code>['.pl', '']</code>, <code>executable</code> implies
<code>['.so', '']</code>, <code>qlf</code> implies <code>['.qlf', '']</code> and
<code>directory</code> implies <code>['']</code>. The file-type <code>source</code>
is an alias for <code>prolog</code> for compatibility to SICStus Prolog.
See also <code>prolog_file_type/2</code>. Notice also that this predicate only
returns non-directories, unless the option <code>file_type(directory)</code> is
specified, or unless <code>access(none)</code>.
</p>
</dd>
<dt><code>file_errors(<code>fail</code>/<code>error</code>)</code></dt>
<dd><p>If <code>error</code> (default), throw and <code>existence_error</code> exception
if the file cannot be found. If <code>fail</code>, stay silent.
</p>
</dd>
<dt><code>solutions(<code>first</code>/<code>all</code>)</code></dt>
<dd><p>If <code>first</code> (default), the predicates leaves no choice-point.
Otherwise a choice-point will be left and backtracking may yield
more solutions.
</p>
</dd>
</dl>
<p>Compatibility considerations to common argument-order in ISO as well
as SICStus <code>absolute_file_name/3</code> forced us to be flexible here.
If the last argument is a list and the 2nd not, the arguments are
swapped, making the call <code>absolute_file_name</code>(+<var>Spec</var>, -<var>Path</var>,
+<var>Options</var>) valid as well.
</p>
</dd>
<dt><code>absolute_file_name(+<var>Name</var>,-<var>FullPath</var>)</code></dt>
<dd><a name="index-absolute_005ffile_005fname_002f2"></a>
<a name="index-absolute_005ffile_005fname_002f2-1"></a>
<a name="index-absolute_005ffile_005fname_002f2-2"></a>
<p>Give the path a full path <var>FullPath</var> YAP would use to consult a file
named <var>Name</var>. Unify <var>FullPath</var> with <code>user</code> if the file
name is <code>user</code>.
</p>
</dd>
<dt><code>file_base_name(+<var>Name</var>,-<var>FileName</var>)</code></dt>
<dd><a name="index-file_005fbase_005fname_002f2"></a>
<a name="index-file_005fbase_005fname_002f2-1"></a>
<a name="index-file_005fbase_005fname_002f2-2"></a>
<p>Give the path a full path <var>FullPath</var> extract the <var>FileName</var>.
</p>
</dd>
<dt><code>file_name_extension(?<var>Base</var>,?<var>Extension</var>, ?<var>Name</var>)</code></dt>
<dd><a name="index-file_005fname_005fextension_002f3"></a>
<a name="index-file_005fname_005fextension_002f3-1"></a>
<a name="index-file_005fname_005fextension_002f3-2"></a>
<p>This predicate is used to add, remove or test filename extensions. The
main reason for its introduction is to deal with different filename
properties in a portable manner. If the file system is
case-insensitive, testing for an extension will be done
case-insensitive too. <var>Extension</var> may be specified with or
without a leading dot (.). If an <var>Extension</var> is generated, it
will not have a leading dot.
</p>
</dd>
<dt><code>current_stream(<var>F</var>,<var>M</var>,<var>S</var>)</code></dt>
<dd><a name="index-current_005fstream_002f3"></a>
<a name="index-current_005fstream_002f3-1"></a>
<a name="index-current_005fstream_002f3-2"></a>
<p>Defines the relation: The stream <var>S</var> is opened on the file <var>F</var>
in mode <var>M</var>. It might be used to obtain all open streams (by
backtracking) or to access the stream for a file <var>F</var> in mode
<var>M</var>, or to find properties for a stream <var>S</var>.
</p>
</dd>
<dt><code>is_stream(<var>S</var>)</code></dt>
<dd><a name="index-is_005fstream_002f1"></a>
<a name="index-is_005fstream_002f1-1"></a>
<a name="index-is_005fstream_002f1-2"></a>
<p>Succeeds if <var>S</var> is a currently open stream.
</p>
</dd>
<dt><code>flush_output [ISO]</code></dt>
<dd><a name="index-flush_005foutput_002f0"></a>
<a name="index-flush_005foutput_002f0-1"></a>
<a name="index-flush_005foutput_002f0-2"></a>
<p>Send out all data in the output buffer of the current output stream.
</p>
</dd>
<dt><code>flush_output(+<var>S</var>) [ISO]</code></dt>
<dd><a name="index-flush_005foutput_002f1"></a>
<a name="index-flush_005foutput_002f1-1"></a>
<a name="index-flush_005foutput_002f1-2"></a>
<p>Send all data in the output buffer for stream <var>S</var>.
</p>
</dd>
<dt><code>set_input(+<var>S</var>) [ISO]</code></dt>
<dd><a name="index-set_005finput_002f1"></a>
<a name="index-set_005finput_002f1-1"></a>
<a name="index-set_005finput_002f1-2"></a>
<p>Set stream <var>S</var> as the current input stream. Predicates like <code>read/1</code>
and <code>get/1</code> will start using stream <var>S</var>.
</p>
</dd>
<dt><code>set_output(+<var>S</var>) [ISO]</code></dt>
<dd><a name="index-set_005foutput_002f1"></a>
<a name="index-set_005foutput_002f1-1"></a>
<a name="index-set_005foutput_002f1-2"></a>
<p>Set stream <var>S</var> as the current output stream. Predicates like
<code>write/1</code> and <code>put/1</code> will start using stream <var>S</var>.
</p>
</dd>
<dt><code>stream_select(+<var>STREAMS</var>,+<var>TIMEOUT</var>,-<var>READSTREAMS</var>)</code></dt>
<dd><a name="index-stream_005fselect_002f3"></a>
<a name="index-stream_005fselect_002f3-1"></a>
<a name="index-stream_005fselect_002f3-2"></a>
<p>Given a list of open <var>STREAMS</var> opened in read mode and a <var>TIMEOUT</var>
return a list of streams who are now available for reading.
</p>
<p>If the <var>TIMEOUT</var> is instantiated to <code>off</code>,
<code>stream_select/3</code> will wait indefinitely for a stream to become
open. Otherwise the timeout must be of the form <code>SECS:USECS</code> where
<code>SECS</code> is an integer gives the number of seconds to wait for a timeout
and <code>USECS</code> adds the number of micro-seconds.
</p>
<p>This built-in is only defined if the system call <code>select</code> is
available in the system.
</p>
</dd>
<dt><code>current_input(-<var>S</var>) [ISO]</code></dt>
<dd><a name="index-current_005finput_002f1"></a>
<a name="index-current_005finput_002f1-1"></a>
<a name="index-current_005finput_002f1-2"></a>
<p>Unify <var>S</var> with the current input stream.
</p>
</dd>
<dt><code>current_output(-<var>S</var>) [ISO]</code></dt>
<dd><a name="index-current_005foutput_002f1"></a>
<a name="index-current_005foutput_002f1-1"></a>
<a name="index-current_005foutput_002f1-2"></a>
<p>Unify <var>S</var> with the current output stream.
</p>
</dd>
<dt><code>at_end_of_stream [ISO]</code></dt>
<dd><a name="index-at_005fend_005fof_005fstream_002f0"></a>
<a name="index-at_005fend_005fof_005fstream_002f0-1"></a>
<a name="index-at_005fend_005fof_005fstream_002f0-2"></a>
<p>Succeed if the current stream has stream position end-of-stream or
past-end-of-stream.
</p>
</dd>
<dt><code>at_end_of_stream(+<var>S</var>) [ISO]</code></dt>
<dd><a name="index-at_005fend_005fof_005fstream_002f1"></a>
<a name="index-at_005fend_005fof_005fstream_002f1-1"></a>
<a name="index-at_005fend_005fof_005fstream_002f1-2"></a>
<p>Succeed if the stream <var>S</var> has stream position end-of-stream or
past-end-of-stream. Note that <var>S</var> must be a readable stream.
</p>
</dd>
<dt><code>set_stream_position(+<var>S</var>, +<var>POS</var>) [ISO]</code></dt>
<dd><a name="index-set_005fstream_005fposition_002f2"></a>
<a name="index-set_005fstream_005fposition_002f2-1"></a>
<a name="index-set_005fstream_005fposition_002f2-2"></a>
<p>Given a stream position <var>POS</var> for a stream <var>S</var>, set the current
stream position for <var>S</var> to be <var>POS</var>.
</p>
</dd>
<dt><code>stream_property(?<var>Stream</var>,?<var>Prop</var>) [ISO]</code></dt>
<dd><a name="index-stream_005fproperty_002f2"></a>
<a name="index-stream_005fproperty_002f2-1"></a>
<a name="index-stream_005fproperty_002f2-2"></a>
<p>Obtain the properties for the open streams. If the first argument is
unbound, the procedure will backtrack through all open
streams. Otherwise, the first argument must be a stream term (you may
use <code>current_stream</code> to obtain a current stream given a file name).
</p>
<p>The following properties are recognized:
</p>
<dl compact="compact">
<dt><code>file_name(<var>P</var>)</code></dt>
<dd><p>An atom giving the file name for the current stream. The file names are
<code>user_input</code>, <code>user_output</code>, and <code>user_error</code> for the
standard streams.
</p>
</dd>
<dt><code>mode(<var>P</var>)</code></dt>
<dd><p>The mode used to open the file. It may be one of <code>append</code>,
<code>read</code>, or <code>write</code>.
</p>
</dd>
<dt><code>input</code></dt>
<dd><p>The stream is readable.
</p>
</dd>
<dt><code>output</code></dt>
<dd><p>The stream is writable.
</p>
</dd>
<dt><code>alias(<var>A</var>)</code></dt>
<dd><p>ISO-Prolog primitive for stream aliases. <tt>YAP</tt> returns one of the
existing aliases for the stream.
</p>
</dd>
<dt><code>position(<var>P</var>)</code></dt>
<dd><p>A term describing the position in the stream.
</p>
</dd>
<dt><code>end_of_stream(<var>E</var>)</code></dt>
<dd><p>Whether the stream is <code>at</code> the end of stream, or it has found the
end of stream and is <code>past</code>, or whether it has <code>not</code> yet
reached the end of stream.
</p>
</dd>
<dt><code>eof_action(<var>A</var>)</code></dt>
<dd><p>The action to take when trying to read after reaching the end of
stream. The action may be one of <code>error</code>, generate an error,
<code>eof_code</code>, return character code <code>-1</code>, or <code>reset</code> the
stream.
</p>
</dd>
<dt><code>reposition(<var>B</var>)</code></dt>
<dd><p>Whether the stream can be repositioned or not, that is, whether it is
seekable.
</p>
</dd>
<dt><code>type(<var>T</var>)</code></dt>
<dd><p>Whether the stream is a <code>text</code> stream or a <code>binary</code> stream.
</p>
</dd>
<dt><code>bom(+<var>Bool</var>)</code></dt>
<dd><p>If present and <code>true</code>, a BOM (<em>Byte Order Mark</em>) was
detected while opening the file for reading or a BOM was written while
opening the stream. See <a href="#BOM">BOM: Byte Order Mark</a> for details.
</p>
</dd>
<dt><code>encoding(+<var>Encoding</var>)</code></dt>
<dd><p>Query the encoding used for text. See <a href="#Encoding">Wide Character Support</a> for an
overview of wide character and encoding issues in YAP.
</p>
</dd>
<dt><code>representation_errors(+<var>Mode</var>)</code></dt>
<dd><p>Behaviour when writing characters to the stream that cannot be
represented by the encoding. The behaviour is one of <code>error</code>
(throw and I/O error exception), <code>prolog</code> (write <code>\u...\</code>
escape code or <code>xml</code> (write <code>&amp;#...;</code> XML character entity).
The initial mode is <code>prolog</code> for the user streams and
<code>error</code> for all other streams. See also <a href="#Encoding">Wide Character Support</a> and
<code>open/4</code>.
</p>
</dd>
</dl>
</dd>
<dt><code>current_line_number(-<var>LineNumber</var>)</code></dt>
<dd><a name="index-current_005fline_005fnumber_002f1"></a>
<a name="index-current_005fline_005fnumber_002f1-1"></a>
<a name="index-current_005fline_005fnumber_002f1-2"></a>
<p>Unify <var>LineNumber</var> with the line number for the current stream.
</p>
</dd>
<dt><code>current_line_number(+<var>Stream</var>,-<var>LineNumber</var>)</code></dt>
<dd><a name="index-current_005fline_005fnumber_002f2"></a>
<a name="index-current_005fline_005fnumber_002f2-1"></a>
<a name="index-current_005fline_005fnumber_002f2-2"></a>
<p>Unify <var>LineNumber</var> with the line number for the <var>Stream</var>.
</p>
</dd>
<dt><code>line_count(+<var>Stream</var>,-<var>LineNumber</var>)</code></dt>
<dd><a name="index-line_005fcount_002f2"></a>
<a name="index-line_005fcount_002f2-1"></a>
<a name="index-line_005fcount_002f2-2"></a>
<p>Unify <var>LineNumber</var> with the line number for the <var>Stream</var>.
</p>
</dd>
<dt><code>character_count(+<var>Stream</var>,-<var>CharacterCount</var>)</code></dt>
<dd><a name="index-character_005fcount_002f2"></a>
<a name="index-character_005fcount_002f2-1"></a>
<a name="index-character_005fcount_002f2-2"></a>
<p>Unify <var>CharacterCount</var> with the number of characters written to or
read to <var>Stream</var>.
</p>
</dd>
<dt><code>line_position(+<var>Stream</var>,-<var>LinePosition</var>)</code></dt>
<dd><a name="index-line_005fposition_002f2"></a>
<a name="index-line_005fposition_002f2-1"></a>
<a name="index-line_005fposition_002f2-2"></a>
<p>Unify <var>LinePosition</var> with the position on current text stream
<var>Stream</var>.
</p>
</dd>
<dt><code>stream_position(+<var>Stream</var>,-<var>StreamPosition</var>)</code></dt>
<dd><a name="index-stream_005fposition_002f2"></a>
<a name="index-stream_005fposition_002f2-1"></a>
<a name="index-stream_005fposition_002f2-2"></a>
<p>Unify <var>StreamPosition</var> with the packaged information of position on
current stream <var>Stream</var>. Use <code>stream_position_data/3</code> to
retrieve information on character or line count.
</p>
</dd>
<dt><code>stream_position_data(+<var>Field</var>,+<var>StreamPosition</var>,-<var>Info</var>)</code></dt>
<dd><a name="index-stream_005fposition_005fdata_002f3"></a>
<a name="index-stream_005fposition_005fdata_002f3-1"></a>
<a name="index-stream_005fposition_005fdata_002f3-2"></a>
<p>Given the packaged stream position term <var>StreamPosition</var>, unify
<var>Info</var> with <var>Field</var> <code>line_count</code>, <code>byte_count</code>, or
<code>char_count</code>.
</p>
</dd>
</dl>
<hr>
<a name="C_002dProlog-File-Handling"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Streams-and-Files" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO-of-Terms" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Handling-Streams-and-Files"></a>
<h3 class="subsection">6.9.2 Handling Streams and Files</h3>
<dl compact="compact">
<dt><code>tell(+<var>S</var>)</code></dt>
<dd><a name="index-tell_002f1"></a>
<a name="index-tell_002f1-1"></a>
<a name="index-tell_002f1-2"></a>
<p>If <var>S</var> is a currently opened stream for output, it becomes the
current output stream. If <var>S</var> is an atom it is taken to be a
filename. If there is no output stream currently associated with it,
then it is opened for output, and the new output stream created becomes
the current output stream. If it is not possible to open the file, an
error occurs. If there is a single opened output stream currently
associated with the file, then it becomes the current output stream; if
there are more than one in that condition, one of them is chosen.
</p>
<p>Whenever <var>S</var> is a stream not currently opened for output, an error
may be reported, depending on the state of the file_errors flag. The
predicate just fails, if <var>S</var> is neither a stream nor an atom.
</p>
</dd>
<dt><code>telling(-<var>S</var>)</code></dt>
<dd><a name="index-telling_002f1"></a>
<a name="index-telling_002f1-1"></a>
<a name="index-telling_002f1-2"></a>
<p>The current output stream is unified with <var>S</var>.
</p>
</dd>
<dt><code>told</code></dt>
<dd><a name="index-told_002f0"></a>
<a name="index-told_002f0-1"></a>
<a name="index-told_002f0-2"></a>
<p>Closes the current output stream, and the user&rsquo;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.
</p>
</dd>
<dt><code>see(+<var>S</var>)</code></dt>
<dd><a name="index-see_002f1"></a>
<a name="index-see_002f1-1"></a>
<a name="index-see_002f1-2"></a>
<p>If <var>S</var> is a currently opened input stream then it is assumed to be
the current input stream. If <var>S</var> 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.
</p>
<p>When <var>S</var> is a stream not currently opened for input, an error may be
reported, depending on the state of the <code>file_errors</code> flag. If
<var>S</var> is neither a stream nor an atom the predicates just fails.
</p>
</dd>
<dt><code>seeing(-<var>S</var>)</code></dt>
<dd><a name="index-seeing_002f1"></a>
<a name="index-seeing_002f1-1"></a>
<a name="index-seeing_002f1-2"></a>
<p>The current input stream is unified with <var>S</var>.
</p>
</dd>
<dt><code>seen</code></dt>
<dd><a name="index-seen_002f0"></a>
<a name="index-seen_002f0-1"></a>
<a name="index-seen_002f0-2"></a>
<p>Closes the current input stream (see 6.7.).
</p>
</dd>
</dl>
<hr>
<a name="I_002fO-of-Terms"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog-File-Handling" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO-of-Characters" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Handling-Input_002fOutput-of-Terms"></a>
<h3 class="subsection">6.9.3 Handling Input/Output of Terms</h3>
<dl compact="compact">
<dt><code>read(-<var>T</var>) [ISO]</code></dt>
<dd><a name="index-read_002f1"></a>
<a name="index-read_002f1-1"></a>
<a name="index-read_002f1-2"></a>
<p>Reads the next term from the current input stream, and unifies it with
<var>T</var>. The term must be followed by a dot (&rsquo;.&rsquo;) and any blank-character
as previously defined. The syntax of the term must match the current
declarations for operators (see op). If the end-of-stream is reached,
<var>T</var> is unified with the atom <code>end_of_file</code>. Further reads from of
the same stream may cause an error failure (see <code>open/3</code>).
</p>
</dd>
<dt><code>read_term(-<var>T</var>,+<var>Options</var>) [ISO]</code></dt>
<dd><a name="index-read_005fterm_002f2"></a>
<a name="index-read_005fterm_002f2-1"></a>
<a name="index-read_005fterm_002f2-2"></a>
<p>Reads term <var>T</var> from the current input stream with execution
controlled by the following options:
</p>
<dl compact="compact">
<dt><code>term_position(-<var>Position</var>)</code></dt>
<dd><a name="index-term_005fposition_002f1-_0028read_005fterm_002f2-option_0029"></a>
<p>Unify <var>Position</var> with a term describing the position of the stream
at the start of parse. Use <code>stream_position_data/3</code> to obtain extra
information.
</p>
</dd>
<dt><code>singletons(-<var>Names</var>)</code></dt>
<dd><a name="index-singletons_002f1-_0028read_005fterm_002f2-option_0029"></a>
<p>Unify <var>Names</var> with a list of the form <var>Name=Var</var>, where
<var>Name</var> is the name of a non-anonymous singleton variable in the
original term, and <code>Var</code> is the variable&rsquo;s representation in
YAP.
</p>
</dd>
<dt><code>syntax_errors(+<var>Val</var>)</code></dt>
<dd><a name="index-syntax_005ferrors_002f1-_0028read_005fterm_002f2-option_0029"></a>
<p>Control action to be taken after syntax errors. See <code>yap_flag/2</code>
for detailed information.
</p>
</dd>
<dt><code>variable_names(-<var>Names</var>)</code></dt>
<dd><a name="index-variable_005fnames_002f1-_0028read_005fterm_002f2-option_0029"></a>
<p>Unify <var>Names</var> with a list of the form <var>Name=Var</var>, where <var>Name</var> is
the name of a non-anonymous variable in the original term, and <var>Var</var>
is the variable&rsquo;s representation in YAP.
</p>
</dd>
<dt><code>variables(-<var>Names</var>)</code></dt>
<dd><a name="index-variables_002f1-_0028read_005fterm_002f2-option_0029"></a>
<p>Unify <var>Names</var> with a list of the variables in term <var>T</var>.
</p>
</dd>
</dl>
</dd>
<dt><code>char_conversion(+<var>IN</var>,+<var>OUT</var>) [ISO]</code></dt>
<dd><a name="index-char_005fconversion_002f2"></a>
<a name="index-char_005fconversion_002f2-1"></a>
<a name="index-char_005fconversion_002f2-2"></a>
<p>While reading terms convert unquoted occurrences of the character
<var>IN</var> to the character <var>OUT</var>. Both <var>IN</var> and <var>OUT</var> must be
bound to single characters atoms.
</p>
<p>Character conversion only works if the flag <code>char_conversion</code> is
on. This is default in the <code>iso</code> and <code>sicstus</code> language
modes. As an example, character conversion can be used for instance to
convert characters from the ISO-LATIN-1 character set to ASCII.
</p>
<p>If <var>IN</var> is the same character as <var>OUT</var>, <code>char_conversion/2</code>
will remove this conversion from the table.
</p>
</dd>
<dt><code>current_char_conversion(?<var>IN</var>,?<var>OUT</var>) [ISO]</code></dt>
<dd><a name="index-current_005fchar_005fconversion_002f2"></a>
<a name="index-current_005fchar_005fconversion_002f2-1"></a>
<a name="index-current_005fchar_005fconversion_002f2-2"></a>
<p>If <var>IN</var> is unbound give all current character
translations. Otherwise, give the translation for <var>IN</var>, if one
exists.
</p>
</dd>
<dt><code>write(<var>T</var>) [ISO]</code></dt>
<dd><a name="index-write_002f1"></a>
<a name="index-write_002f1-1"></a>
<a name="index-write_002f1-2"></a>
<p>The term <var>T</var> is written to the current output stream according to
the operator declarations in force.
</p>
</dd>
<dt><code>writeln(<var>T</var>) [ISO]</code></dt>
<dd><a name="index-writeln_002f1"></a>
<a name="index-writeln_002f1-1"></a>
<a name="index-writeln_002f1-2"></a>
<p>Same as <code>write/1</code> followed by <code>nl/0</code>.
</p>
</dd>
<dt><code>display(+<var>T</var>)</code></dt>
<dd><a name="index-display_002f1"></a>
<a name="index-display_002f1-1"></a>
<a name="index-display_002f1-2"></a>
<p>Displays term <var>T</var> on the current output stream. All Prolog terms are
written in standard parenthesized prefix notation.
</p>
</dd>
<dt><code>write_canonical(+<var>T</var>) [ISO]</code></dt>
<dd><a name="index-display_002f1-3"></a>
<a name="index-display_002f1-4"></a>
<a name="index-display_002f1-5"></a>
<p>Displays term <var>T</var> on the current output stream. Atoms are quoted
when necessary, and operators are ignored, that is, the term is written
in standard parenthesized prefix notation.
</p>
</dd>
<dt><code>write_term(+<var>T</var>, +<var>Opts</var>) [ISO]</code></dt>
<dd><a name="index-write_005fterm_002f2"></a>
<a name="index-write_005fterm_002f2-1"></a>
<a name="index-write_005fterm_002f2-2"></a>
<p>Displays term <var>T</var> on the current output stream, according to the
following options:
</p>
<dl compact="compact">
<dt><code>quoted(+<var>Bool</var>) [ISO]</code></dt>
<dd><p>If <code>true</code>, quote atoms if this would be necessary for the atom to
be recognized as an atom by YAP&rsquo;s parser. The default value is
<code>false</code>.
</p>
</dd>
<dt><code>ignore_ops(+<var>Bool</var>) [ISO]</code></dt>
<dd><p>If <code>true</code>, ignore operator declarations when writing the term. The
default value is <code>false</code>.
</p>
</dd>
<dt><code>numbervars(+<var>Bool</var>) [ISO]</code></dt>
<dd><p>If <code>true</code>, output terms of the form
<code>'$VAR'(N)</code>, where <var>N</var> is an integer, as a sequence of capital
letters. The default value is <code>false</code>.
</p>
</dd>
<dt><code>portrayed(+<var>Bool</var>)</code></dt>
<dd><p>If <code>true</code>, use <tt>portray/1</tt> to portray bound terms. The default
value is <code>false</code>.
</p>
</dd>
<dt><code>portray(+<var>Bool</var>)</code></dt>
<dd><p>If <code>true</code>, use <tt>portray/1</tt> to portray bound terms. The default
value is <code>false</code>.
</p>
</dd>
<dt><code>max_depth(+<var>Depth</var>)</code></dt>
<dd><p>If <code>Depth</code> is a positive integer, use <tt>Depth</tt> as
the maximum depth to portray a term. The default is <code>0</code>, that is,
unlimited depth.
</p>
</dd>
<dt><code>priority(+<var>Piority</var>)</code></dt>
<dd><p>If <code>Priority</code> is a positive integer smaller than <code>1200</code>,
give the context priority. The default is <code>1200</code>.
</p>
</dd>
<dt><code>cycles(+<var>Bool</var>)</code></dt>
<dd><p>Do not loop in rational trees (default).
</p></dd>
</dl>
</dd>
<dt><code>writeq(<var>T</var>) [ISO]</code></dt>
<dd><a name="index-writeq_002f1"></a>
<a name="index-writeq_002f1-1"></a>
<a name="index-writeq_002f1-2"></a>
<p> Writes the term <var>T</var>, quoting names to make the result acceptable to
the predicate &rsquo;read&rsquo; whenever necessary.
</p>
</dd>
<dt><code>print(<var>T</var>)</code></dt>
<dd><a name="index-print_002f1"></a>
<a name="index-print_002f1-1"></a>
<a name="index-print_002f1-2"></a>
<p>Prints the term <var>T</var> to the current output stream using <code>write/1</code>
unless T is bound and a call to the user-defined predicate
<code>portray/1</code> succeeds. To do pretty printing of terms the user should
define suitable clauses for <code>portray/1</code> and use <code>print/1</code>.
</p>
</dd>
<dt><code>format(+<var>T</var>,+<var>L</var>)</code></dt>
<dd><a name="index-format_002f2"></a>
<a name="index-format_002f2-1"></a>
<a name="index-format_002f2-2"></a>
<p>Print formatted output to the current output stream. The arguments in
list <var>L</var> are output according to the string or atom <var>T</var>.
</p>
<p>A control sequence is introduced by a <code>w</code>. The following control
sequences are available in YAP:
</p>
<dl compact="compact">
<dt><code>'~~'</code></dt>
<dd><p>Print a single tilde.
</p>
</dd>
<dt><code>'~a'</code></dt>
<dd><p>The next argument must be an atom, that will be printed as if by <code>write</code>.
</p>
</dd>
<dt><code>'~Nc'</code></dt>
<dd><p>The next argument must be an integer, that will be printed as a
character code. The number <var>N</var> is the number of times to print the
character (default 1).
</p>
</dd>
<dt><code>'~Ne'</code></dt>
<dt><code>'~NE'</code></dt>
<dt><code>'~Nf'</code></dt>
<dt><code>'~Ng'</code></dt>
<dt><code>'~NG'</code></dt>
<dd><p>The next argument must be a floating point number. The float <var>F</var>, the number
<var>N</var> and the control code <code>c</code> will be passed to <code>printf</code> as:
</p>
<div class="example">
<pre class="example"> printf(&quot;%s.Nc&quot;, F)
</pre></div>
<p>As an example:
</p>
<div class="example">
<pre class="example">?- format(&quot;~8e, ~8E, ~8f, ~8g, ~8G~w&quot;,
[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
</pre></div>
</dd>
<dt><code>'~Nd'</code></dt>
<dd><p>The next argument must be an integer, and <var>N</var> is the number of digits
after the decimal point. If <var>N</var> is <code>0</code> no decimal points will be
printed. The default is <var>N = 0</var>.
</p>
<div class="example">
<pre class="example">?- format(&quot;~2d, ~d&quot;,[15000, 15000]).
150.00, 15000
</pre></div>
</dd>
<dt><code>'~ND'</code></dt>
<dd><p>Identical to <code>'~Nd'</code>, except that commas are used to separate groups
of three digits.
</p>
<div class="example">
<pre class="example">?- format(&quot;~2D, ~D&quot;,[150000, 150000]).
1,500.00, 150,000
</pre></div>
</dd>
<dt><code>'~i'</code></dt>
<dd><p>Ignore the next argument in the list of arguments:
</p>
<div class="example">
<pre class="example">?- format('The ~i met the boregrove',[mimsy]).
The met the boregrove
</pre></div>
</dd>
<dt><code>'~k'</code></dt>
<dd><p>Print the next argument with <code>write_canonical</code>:
</p>
<div class="example">
<pre class="example">?- format(&quot;Good night ~k&quot;,a+[1,2]).
Good night +(a,[1,2])
</pre></div>
</dd>
<dt><code>'~Nn'</code></dt>
<dd><p>Print <var>N</var> newlines (where <var>N</var> defaults to 1).
</p>
</dd>
<dt><code>'~NN'</code></dt>
<dd><p>Print <var>N</var> newlines if at the beginning of the line (where <var>N</var>
defaults to 1).
</p>
</dd>
<dt><code>'~Nr'</code></dt>
<dd><p>The next argument must be an integer, and <var>N</var> is interpreted as a
radix, such that <code>2 &lt;= N &lt;= 36</code> (the default is 8).
</p>
<div class="example">
<pre class="example">?- format(&quot;~2r, 0x~16r, ~r&quot;,
[150000, 150000, 150000]).
100100100111110000, 0x249f0, 444760
</pre></div>
<p>Note that the letters <code>a-z</code> denote digits larger than 9.
</p>
</dd>
<dt><code>'~NR'</code></dt>
<dd><p>Similar to &rsquo;~NR&rsquo;. The next argument must be an integer, and <var>N</var> is
interpreted as a radix, such that <code>2 &lt;= N &lt;= 36</code> (the default is 8).
</p>
<div class="example">
<pre class="example">?- format(&quot;~2r, 0x~16r, ~r&quot;,
[150000, 150000, 150000]).
100100100111110000, 0x249F0, 444760
</pre></div>
<p>The only difference is that letters <code>A-Z</code> denote digits larger than 9.
</p>
</dd>
<dt><code>'~p'</code></dt>
<dd><p>Print the next argument with <code>print/1</code>:
</p>
<div class="example">
<pre class="example">?- format(&quot;Good night ~p&quot;,a+[1,2]).
Good night a+[1,2]
</pre></div>
</dd>
<dt><code>'~q'</code></dt>
<dd><p>Print the next argument with <code>writeq/1</code>:
</p>
<div class="example">
<pre class="example">?- format(&quot;Good night ~q&quot;,'Hello'+[1,2]).
Good night 'Hello'+[1,2]
</pre></div>
</dd>
<dt><code>'~Ns'</code></dt>
<dd><p>The next argument must be a list of character codes. The system then
outputs their representation as a string, where <var>N</var> is the maximum
number of characters for the string (<var>N</var> defaults to the length of the
string).
</p>
<div class="example">
<pre class="example">?- format(&quot;The ~s are ~4s&quot;,[&quot;woods&quot;,&quot;lovely&quot;]).
The woods are love
</pre></div>
</dd>
<dt><code>'~w'</code></dt>
<dd><p>Print the next argument with <code>write/1</code>:
</p>
<div class="example">
<pre class="example">?- format(&quot;Good night ~w&quot;,'Hello'+[1,2]).
Good night Hello+[1,2]
</pre></div>
</dd>
</dl>
<p>The number of arguments, <code>N</code>, may be given as an integer, or it
may be given as an extra argument. The next example shows a small
procedure to write a variable number of <code>a</code> characters:
</p>
<div class="example">
<pre class="example">write_many_as(N) :-
format(&quot;~*c&quot;,[N,0'a]).
</pre></div>
<p>The <code>format/2</code> built-in also allows for formatted output. One can
specify column boundaries and fill the intermediate space by a padding
character:
</p>
<dl compact="compact">
<dt><code>'~N|'</code></dt>
<dd><p>Set a column boundary at position <var>N</var>, where <var>N</var> defaults to the
current position.
</p>
</dd>
<dt><code>'~N+'</code></dt>
<dd><p>Set a column boundary at <var>N</var> characters past the current position, where
<var>N</var> defaults to <code>8</code>.
</p>
</dd>
<dt><code>'~Nt'</code></dt>
<dd><p>Set padding for a column, where <var>N</var> is the fill code (default is
&lt;SPC&gt;).
</p>
</dd>
</dl>
<p>The next example shows how to align columns and padding. We first show
left-alignment:
</p>
<div class="example">
<pre class="example">
<code>
?- format(&quot;~n*Hello~16+*~n&quot;,[]).
*Hello *
</code>
</pre></div>
<p>Note that we reserve 16 characters for the column.
</p>
<p>The following example shows how to do right-alignment:
</p>
<div class="example">
<pre class="example"><code>
?- format(&quot;*~tHello~16+*~n&quot;,[]).
* Hello*
</code>
</pre></div>
<p>The <code>~t</code> escape sequence forces filling before <code>Hello</code>.
</p>
<p>We next show how to do centering:
</p>
<div class="example">
<pre class="example"><code>
?- format(&quot;*~tHello~t~16+*~n&quot;,[]).
* Hello *
</code>
</pre></div>
<p>The two <code>~t</code> escape sequence force filling both before and after
<code>Hello</code>. Space is then evenly divided between the right and the
left sides.
</p>
</dd>
<dt><code>format(+<var>T</var>)</code></dt>
<dd><a name="index-format_002f1"></a>
<a name="index-format_002f1-1"></a>
<a name="index-format_002f1-2"></a>
<p>Print formatted output to the current output stream.
</p>
</dd>
<dt><code>format(+<var>S</var>,+<var>T</var>,+<var>L</var>)</code></dt>
<dd><a name="index-format_002f3"></a>
<a name="index-format_002f3-1"></a>
<a name="index-format_002f3-2"></a>
<p>Print formatted output to stream <var>S</var>.
</p>
</dd>
<dt><code>with_output_to(+<var>Ouput</var>,:<var>Goal</var>)</code></dt>
<dd><a name="index-with_005foutput_005fto_002f2"></a>
<a name="index-with_005foutput_005fto_002f2-1"></a>
<a name="index-with_005foutput_005fto_002f2-2"></a>
<p>Run <var>Goal</var> as <code>once/1</code>, while characters written to the current
output are sent to <var>Output</var>. The predicate is SWI-Prolog
specific.
</p>
<p>Applications should generally avoid creating atoms by breaking and
concatenating other atoms as the creation of large numbers of
intermediate atoms generally leads to poor performance, even more so in
multi-threaded applications. This predicate supports creating
difference-lists from character data efficiently. The example below
defines the DCG rule <code>term/3</code> to insert a term in the output:
</p>
<div class="example">
<pre class="example"> term(Term, In, Tail) :-
with_output_to(codes(In, Tail), write(Term)).
?- phrase(term(hello), X).
X = [104, 101, 108, 108, 111]
</pre></div>
<dl compact="compact">
<dt><code>A Stream handle or alias</code></dt>
<dd><p> Temporary switch current output to the given stream. Redirection using with_output_to/2 guarantees the original output is restored, also if Goal fails or raises an exception. See also call_cleanup/2.
</p></dd>
<dt><code>atom(-<var>Atom</var>)</code></dt>
<dd><p> Create an atom from the emitted characters. Please note the remark above.
</p></dd>
<dt><code>string(-<var>String</var>)</code></dt>
<dd><p> Create a string-object (not supported in YAP).
</p></dd>
<dt><code>codes(-<var>Codes</var>)</code></dt>
<dd><p> Create a list of character codes from the emitted characters, similar to atom_codes/2.
</p></dd>
<dt><code>codes(-<var>Codes</var>, -<var>Tail</var>)</code></dt>
<dd><p> Create a list of character codes as a difference-list.
</p></dd>
<dt><code>chars(-<var>Chars</var>)</code></dt>
<dd><p> Create a list of one-character-atoms codes from the emitted characters, similar to atom_chars/2.
</p></dd>
<dt><code>chars(-<var>Chars</var>, -<var>Tail</var>)</code></dt>
<dd><p> Create a list of one-character-atoms as a difference-list.
</p></dd>
</dl>
</dd>
</dl>
<hr>
<a name="I_002fO-of-Characters"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO-of-Terms" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO-for-Streams" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Handling-Input_002fOutput-of-Characters"></a>
<h3 class="subsection">6.9.4 Handling Input/Output of Characters</h3>
<dl compact="compact">
<dt><code>put(+<var>N</var>)</code></dt>
<dd><a name="index-put_002f1"></a>
<a name="index-put_002f1-1"></a>
<a name="index-put_002f1-2"></a>
<p>Outputs to the current output stream the character whose ASCII code is
<var>N</var>. The character <var>N</var> 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.
</p>
</dd>
<dt><code>put_byte(+<var>N</var>) [ISO]</code></dt>
<dd><a name="index-put_005fbyte_002f1"></a>
<a name="index-put_005fbyte_002f1-1"></a>
<a name="index-put_005fbyte_002f1-2"></a>
<p>Outputs to the current output stream the character whose code is
<var>N</var>. The current output stream must be a binary stream.
</p>
</dd>
<dt><code>put_char(+<var>N</var>) [ISO]</code></dt>
<dd><a name="index-put_005fchar_002f1"></a>
<a name="index-put_005fchar_002f1-1"></a>
<a name="index-put_005fchar_002f1-2"></a>
<p>Outputs to the current output stream the character who is used to build
the representation of atom <code>A</code>. The current output stream must be a
text stream.
</p>
</dd>
<dt><code>put_code(+<var>N</var>) [ISO]</code></dt>
<dd><a name="index-put_005fcode_002f1"></a>
<a name="index-put_005fcode_002f1-1"></a>
<a name="index-put_005fcode_002f1-2"></a>
<p>Outputs to the current output stream the character whose ASCII code is
<var>N</var>. The current output stream must be a text stream. The character
<var>N</var> 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.
</p>
</dd>
<dt><code>get(-<var>C</var>)</code></dt>
<dd><a name="index-get_002f1"></a>
<a name="index-get_002f1-1"></a>
<a name="index-get_002f1-2"></a>
<p>The next non-blank character from the current input stream is unified
with <var>C</var>. Blank characters are the ones whose ASCII codes are not
greater than 32. If there are no more non-blank characters in the
stream, <var>C</var> is unified with -1. If <code>end_of_stream</code> has already
been reached in the previous reading, this call will give an error message.
</p>
</dd>
<dt><code>get0(-<var>C</var>)</code></dt>
<dd><a name="index-get0_002f1"></a>
<a name="index-get0_002f1-1"></a>
<a name="index-get0_002f1-2"></a>
<p>The next character from the current input stream is consumed, and then
unified with <var>C</var>. There are no restrictions on the possible
values of the ASCII code for the character, but the character will be
internally converted by YAP.
</p>
</dd>
<dt><code>get_byte(-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-get_005fbyte_002f1"></a>
<a name="index-get_005fbyte_002f1-1"></a>
<a name="index-get_005fbyte_002f1-2"></a>
<p>If <var>C</var> 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 <var>C</var>.
</p>
</dd>
<dt><code>get_char(-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-get_005fchar_002f1"></a>
<a name="index-get_005fchar_002f1-1"></a>
<a name="index-get_005fchar_002f1-2"></a>
<p>If <var>C</var> 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 <var>C</var>.
</p>
</dd>
<dt><code>get_code(-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-get_005fcode_002f1"></a>
<a name="index-get_005fcode_002f1-1"></a>
<a name="index-get_005fcode_002f1-2"></a>
<p>If <var>C</var> 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 <var>C</var>.
</p>
</dd>
<dt><code>peek_byte(-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-peek_005fbyte_002f1"></a>
<a name="index-peek_005fbyte_002f1-1"></a>
<a name="index-peek_005fbyte_002f1-2"></a>
<p>If <var>C</var> 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 <var>C</var>, while leaving the current stream position unaltered.
</p>
</dd>
<dt><code>peek_char(-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-peek_005fchar_002f1"></a>
<a name="index-peek_005fchar_002f1-1"></a>
<a name="index-peek_005fchar_002f1-2"></a>
<p>If <var>C</var> 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 <var>C</var>, while
leaving the current stream position unaltered.
</p>
</dd>
<dt><code>peek_code(-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-peek_005fcode_002f1"></a>
<a name="index-peek_005fcode_002f1-1"></a>
<a name="index-peek_005fcode_002f1-2"></a>
<p>If <var>C</var> 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 <var>C</var>, while
leaving the current stream position unaltered.
</p>
</dd>
<dt><code>skip(+<var>N</var>)</code></dt>
<dd><a name="index-skip_002f1"></a>
<a name="index-skip_002f1-1"></a>
<a name="index-skip_002f1-2"></a>
<p>Skips input characters until the next occurrence of the character with
ASCII code <var>N</var>. The argument to this predicate can take the same forms
as those for <code>put</code> (see 6.11).
</p>
</dd>
<dt><code>tab(+<var>N</var>)</code></dt>
<dd><a name="index-tab_002f1"></a>
<a name="index-tab_002f1-1"></a>
<a name="index-tab_002f1-2"></a>
<p>Outputs <var>N</var> spaces to the current output stream.
</p>
</dd>
<dt><code>nl [ISO]</code></dt>
<dd><a name="index-nl_002f0"></a>
<a name="index-nl_002f0-1"></a>
<a name="index-nl_002f0-2"></a>
<p>Outputs a new line to the current output stream.
</p>
</dd>
</dl>
<hr>
<a name="I_002fO-for-Streams"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO-of-Characters" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog-to-Terminal" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Input_002fOutput-Predicates-applied-to-Streams"></a>
<h3 class="subsection">6.9.5 Input/Output Predicates applied to Streams</h3>
<dl compact="compact">
<dt><code>read(+<var>S</var>,-<var>T</var>) [ISO]</code></dt>
<dd><a name="index-read_002f2"></a>
<a name="index-read_002f2-1"></a>
<a name="index-read_002f2-2"></a>
<p>Reads term <var>T</var> from the stream <var>S</var> instead of from the current input
stream.
</p>
</dd>
<dt><code>read_term(+<var>S</var>,-<var>T</var>,+<var>Options</var>) [ISO]</code></dt>
<dd><a name="index-read_005fterm_002f3"></a>
<a name="index-read_005fterm_002f3-1"></a>
<a name="index-read_005fterm_002f3-2"></a>
<p>Reads term <var>T</var> from stream <var>S</var> with execution controlled by the
same options as <code>read_term/2</code>.
</p>
</dd>
<dt><code>write(+<var>S</var>,<var>T</var>) [ISO]</code></dt>
<dd><a name="index-write_002f2"></a>
<a name="index-write_002f2-1"></a>
<a name="index-write_002f2-2"></a>
<p>Writes term <var>T</var> to stream <var>S</var> instead of to the current output
stream.
</p>
</dd>
<dt><code>write_canonical(+<var>S</var>,+<var>T</var>) [ISO]</code></dt>
<dd><a name="index-write_005fcanonical_002f2"></a>
<a name="index-write_005fcanonical_002f2-1"></a>
<a name="index-write_005fcanonical_002f2-2"></a>
<p>Displays term <var>T</var> on the stream <var>S</var>. Atoms are quoted when
necessary, and operators are ignored.
</p>
</dd>
<dt><code>write_canonical(+<var>T</var>) [ISO]</code></dt>
<dd><a name="index-write_005fcanonical_002f1"></a>
<a name="index-write_005fcanonical_002f1-1"></a>
<a name="index-write_005fcanonical_002f1-2"></a>
<p>Displays term <var>T</var>. Atoms are quoted when necessary, and operators
are ignored.
</p>
</dd>
<dt><code>write_term(+<var>S</var>, +<var>T</var>, +<var>Opts</var>) [ISO]</code></dt>
<dd><a name="index-write_005fterm_002f3"></a>
<a name="index-write_005fterm_002f3-1"></a>
<a name="index-write_005fterm_002f3-2"></a>
<p>Displays term <var>T</var> on the current output stream, according to the same
options used by <code>write_term/3</code>.
</p>
</dd>
<dt><code>writeq(+<var>S</var>,<var>T</var>) [ISO]</code></dt>
<dd><a name="index-writeq_002f2"></a>
<a name="index-writeq_002f2-1"></a>
<a name="index-writeq_002f2-2"></a>
<p>As <code>writeq/1</code>, but the output is sent to the stream <var>S</var>.
</p>
</dd>
<dt><code>display(+<var>S</var>,<var>T</var>)</code></dt>
<dd><a name="index-display_002f2"></a>
<a name="index-display_002f2-1"></a>
<a name="index-display_002f2-2"></a>
<p>Like <code>display/1</code>, but using stream <var>S</var> to display the term.
</p>
</dd>
<dt><code>print(+<var>S</var>,<var>T</var>)</code></dt>
<dd><a name="index-print_002f2"></a>
<a name="index-print_002f2-1"></a>
<a name="index-print_002f2-2"></a>
<p>Prints term <var>T</var> to the stream <var>S</var> instead of to the current output
stream.
</p>
</dd>
<dt><code>put(+<var>S</var>,+<var>N</var>)</code></dt>
<dd><a name="index-put_002f2"></a>
<a name="index-put_002f2-1"></a>
<a name="index-put_002f2-2"></a>
<p>As <code>put(N)</code>, but to stream <var>S</var>.
</p>
</dd>
<dt><code>put_byte(+<var>S</var>,+<var>N</var>) [ISO]</code></dt>
<dd><a name="index-put_005fbyte_002f2"></a>
<a name="index-put_005fbyte_002f2-1"></a>
<a name="index-put_005fbyte_002f2-2"></a>
<p>As <code>put_byte(N)</code>, but to binary stream <var>S</var>.
</p>
</dd>
<dt><code>put_char(+<var>S</var>,+<var>A</var>) [ISO]</code></dt>
<dd><a name="index-put_005fchar_002f2"></a>
<a name="index-put_005fchar_002f2-1"></a>
<a name="index-put_005fchar_002f2-2"></a>
<p>As <code>put_char(A)</code>, but to text stream <var>S</var>.
</p>
</dd>
<dt><code>put_code(+<var>S</var>,+<var>N</var>) [ISO]</code></dt>
<dd><a name="index-put_005fcode_002f2"></a>
<a name="index-put_005fcode_002f2-1"></a>
<a name="index-put_005fcode_002f2-2"></a>
<p>As <code>put_code(N)</code>, but to text stream <var>S</var>.
</p>
</dd>
<dt><code>get(+<var>S</var>,-<var>C</var>)</code></dt>
<dd><a name="index-get_002f2"></a>
<a name="index-get_002f2-1"></a>
<a name="index-get_002f2-2"></a>
<p>The same as <code>get(C)</code>, but from stream <var>S</var>.
</p>
</dd>
<dt><code>get0(+<var>S</var>,-<var>C</var>)</code></dt>
<dd><a name="index-get0_002f2"></a>
<a name="index-get0_002f2-1"></a>
<a name="index-get0_002f2-2"></a>
<p>The same as <code>get0(C)</code>, but from stream <var>S</var>.
</p>
</dd>
<dt><code>get_byte(+<var>S</var>,-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-get_005fbyte_002f2"></a>
<a name="index-get_005fbyte_002f2-1"></a>
<a name="index-get_005fbyte_002f2-2"></a>
<p>If <var>C</var> is unbound, or is a character code, and the stream <var>S</var> is a
binary stream, read the next byte from that stream and unify its
code with <var>C</var>.
</p>
</dd>
<dt><code>get_char(+<var>S</var>,-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-get_005fchar_002f2"></a>
<a name="index-get_005fchar_002f2-1"></a>
<a name="index-get_005fchar_002f2-2"></a>
<p>If <var>C</var> is unbound, or is an atom representation of a character, and
the stream <var>S</var> is a text stream, read the next character from that
stream and unify its representation as an atom with <var>C</var>.
</p>
</dd>
<dt><code>get_code(+<var>S</var>,-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-get_005fcode_002f2"></a>
<a name="index-get_005fcode_002f2-1"></a>
<a name="index-get_005fcode_002f2-2"></a>
<p>If <var>C</var> is unbound, or is a character code, and the stream <var>S</var> is a
text stream, read the next character from that stream and unify its
code with <var>C</var>.
</p>
</dd>
<dt><code>peek_byte(+<var>S</var>,-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-peek_005fbyte_002f2"></a>
<a name="index-peek_005fbyte_002f2-1"></a>
<a name="index-peek_005fbyte_002f2-2"></a>
<p>If <var>C</var> is unbound, or is a character code, and <var>S</var> is a binary
stream, read the next byte from the current stream and unify its code
with <var>C</var>, while leaving the current stream position unaltered.
</p>
</dd>
<dt><code>peek_char(+<var>S</var>,-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-peek_005fchar_002f2"></a>
<a name="index-peek_005fchar_002f2-1"></a>
<a name="index-peek_005fchar_002f2-2"></a>
<p>If <var>C</var> is unbound, or is an atom representation of a character, and
the stream <var>S</var> is a text stream, read the next character from that
stream and unify its representation as an atom with <var>C</var>, while leaving
the current stream position unaltered.
</p>
</dd>
<dt><code>peek_code(+<var>S</var>,-<var>C</var>) [ISO]</code></dt>
<dd><a name="index-peek_005fcode_002f2"></a>
<a name="index-peek_005fcode_002f2-1"></a>
<a name="index-peek_005fcode_002f2-2"></a>
<p>If <var>C</var> is unbound, or is an atom representation of a character, and
the stream <var>S</var> is a text stream, read the next character from that
stream and unify its representation as an atom with <var>C</var>, while leaving
the current stream position unaltered.
</p>
</dd>
<dt><code>skip(+<var>S</var>,-<var>C</var>)</code></dt>
<dd><a name="index-skip_002f2"></a>
<a name="index-skip_002f2-1"></a>
<a name="index-skip_002f2-2"></a>
<p>Like <code>skip/1</code>, but using stream <var>S</var> instead of the current
input stream.
</p>
</dd>
<dt><code>tab(+<var>S</var>,+<var>N</var>)</code></dt>
<dd><a name="index-tab_002f2"></a>
<a name="index-tab_002f2-1"></a>
<a name="index-tab_002f2-2"></a>
<p>The same as <code>tab/1</code>, but using stream <var>S</var>.
</p>
</dd>
<dt><code>nl(+<var>S</var>) [ISO]</code></dt>
<dd><a name="index-nl_002f1"></a>
<a name="index-nl_002f1-1"></a>
<a name="index-nl_002f1-2"></a>
<p>Outputs a new line to stream <var>S</var>.
</p>
</dd>
</dl>
<hr>
<a name="C_002dProlog-to-Terminal"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO-for-Streams" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO-Control" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Compatible-C_002dProlog-predicates-for-Terminal-I_002fO"></a>
<h3 class="subsection">6.9.6 Compatible C-Prolog predicates for Terminal I/O</h3>
<dl compact="compact">
<dt><code>ttyput(+<var>N</var>)</code></dt>
<dd><a name="index-ttyput_002f1"></a>
<a name="index-ttyput_002f1-1"></a>
<a name="index-ttyput_002f1-2"></a>
<p>As <code>put(N)</code> but always to <code>user_output</code>.
</p>
</dd>
<dt><code>ttyget(-<var>C</var>)</code></dt>
<dd><a name="index-ttyget_002f1"></a>
<a name="index-ttyget_002f1-1"></a>
<a name="index-ttyget_002f1-2"></a>
<p>The same as <code>get(C)</code>, but from stream <code>user_input</code>.
</p>
</dd>
<dt><code>ttyget0(-<var>C</var>)</code></dt>
<dd><a name="index-ttyget0_002f1"></a>
<a name="index-ttyget0_002f1-1"></a>
<a name="index-ttyget0_002f1-2"></a>
<p>The same as <code>get0(C)</code>, but from stream <code>user_input</code>.
</p>
</dd>
<dt><code>ttyskip(-<var>C</var>)</code></dt>
<dd><a name="index-ttyskip_002f1"></a>
<a name="index-ttyskip_002f1-1"></a>
<a name="index-ttyskip_002f1-2"></a>
<p>Like <code>skip/1</code>, but always using stream <code>user_input</code>.
stream.
</p>
</dd>
<dt><code>ttytab(+<var>N</var>)</code></dt>
<dd><a name="index-ttytab_002f1"></a>
<a name="index-ttytab_002f1-1"></a>
<a name="index-ttytab_002f1-2"></a>
<p>The same as <code>tab/1</code>, but using stream <code>user_output</code>.
</p>
</dd>
<dt><code>ttynl</code></dt>
<dd><a name="index-ttynl_002f0"></a>
<a name="index-ttynl_002f0-1"></a>
<a name="index-ttynl_002f0-2"></a>
<p>Outputs a new line to stream <code>user_output</code>.
</p>
</dd>
</dl>
<hr>
<a name="I_002fO-Control"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog-to-Terminal" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Sockets" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Controlling-Input_002fOutput"></a>
<h3 class="subsection">6.9.7 Controlling Input/Output</h3>
<dl compact="compact">
<dt><code>exists(+<var>F</var>)</code></dt>
<dd><a name="index-exists_002f1"></a>
<a name="index-exists_002f1-1"></a>
<a name="index-exists_002f1-2"></a>
<p>Checks if file <var>F</var> exists in the current directory.
</p>
</dd>
<dt><code>nofileerrors</code></dt>
<dd><a name="index-nofileerrors_002f0"></a>
<a name="index-nofileerrors_002f0-1"></a>
<a name="index-nofileerrors_002f0-2"></a>
<p>Switches off the file_errors flag, so that the predicates <code>see/1</code>,
<code>tell/1</code>, <code>open/3</code> and <code>close/1</code> just fail, instead of producing
an error message and aborting whenever the specified file cannot be
opened or closed.
</p>
</dd>
<dt><code>fileerrors</code></dt>
<dd><a name="index-fileerrors_002f0"></a>
<a name="index-fileerrors_002f0-1"></a>
<a name="index-fileerrors_002f0-2"></a>
<p>Switches on the file_errors flag so that in certain error conditions
I/O predicates will produce an appropriated message and abort.
</p>
</dd>
<dt><code>write_depth(<var>T</var>,<var>L</var>,<var>A</var>)</code></dt>
<dd><a name="index-write_005fdepth_002f3"></a>
<a name="index-write_005fdepth_002f3-1"></a>
<a name="index-write_005fdepth_002f3-2"></a>
<p>Unifies <var>T</var> with the value of the maximum depth of a term to be
written, <var>L</var> with the maximum length of a list to write, and <var>A</var>
with the maximum number of arguments of a compound term to write. The
setting will be used by <code>write/1</code> or <code>write/2</code>. The default
value for all arguments is 0, meaning unlimited depth and length.
</p>
<div class="example">
<pre class="example">?- 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
</pre></div>
</dd>
<dt><code>write_depth(<var>T</var>,<var>L</var>)</code></dt>
<dd><a name="index-write_005fdepth_002f2"></a>
<a name="index-write_005fdepth_002f2-1"></a>
<p>Same as <code>write_depth(<var>T</var>,<var>L</var>,_)</code>. Unifies <var>T</var> with the
value of the maximum depth of a term to be
written, and <var>L</var> with the maximum length of a list to write. The
setting will be used by <code>write/1</code> or <code>write/2</code>. The default
value for all arguments is 0, meaning unlimited depth and length.
</p>
<div class="example">
<pre class="example">?- 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
</pre></div>
</dd>
<dt><code>always_prompt_user</code></dt>
<dd><a name="index-always_005fprompt_005fuser_002f0"></a>
<a name="index-always_005fprompt_005fuser_002f0-1"></a>
<a name="index-always_005fprompt_005fuser_002f0-2"></a>
<p>Force the system to prompt the user even if the <code>user_input</code> stream
is not a terminal. This command is useful if you want to obtain
interactive control from a pipe or a socket.
</p>
</dd>
</dl>
<hr>
<a name="Sockets"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO-Control" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#I_002fO" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Database" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Using-Sockets-From-YAP"></a>
<h3 class="subsection">6.9.8 Using Sockets From YAP</h3>
<p>YAP includes a SICStus Prolog compatible socket interface. This
is a low level interface that provides direct access to the major socket
system calls. These calls can be used both to open a new connection in
the network or connect to a networked server. Socket connections are
described as read/write streams, and standard I/O built-ins can be used
to write on or read from sockets. The following calls are available:
</p>
<dl compact="compact">
<dt><code>socket(+<var>DOMAIN</var>,+<var>TYPE</var>,+<var>PROTOCOL</var>,-<var>SOCKET</var>)</code></dt>
<dd><a name="index-socket_002f4"></a>
<a name="index-socket_002f4-1"></a>
<a name="index-socket_002f4-2"></a>
<p>Corresponds to the BSD system call <code>socket</code>. Create a socket for
domain <var>DOMAIN</var> of type <var>TYPE</var> and protocol
<var>PROTOCOL</var>. Both <var>DOMAIN</var> and <var>TYPE</var> should be atoms,
whereas <var>PROTOCOL</var> must be an integer. The new socket object is
accessible through a descriptor bound to the variable <var>SOCKET</var>.
</p>
<p>The current implementation of YAP only accepts two socket
domains: <code>'AF_INET'</code> and <code>'AF_UNIX'</code>. Socket types depend on the
underlying operating system, but at least the following types are
supported: <code>'SOCK_STREAM'</code> and <code>'SOCK_DGRAM'</code>.
</p>
</dd>
<dt><code>socket(+<var>DOMAIN</var>,-<var>SOCKET</var>)</code></dt>
<dd><a name="index-socket_002f2"></a>
<a name="index-socket_002f2-1"></a>
<a name="index-socket_002f2-2"></a>
<p>Call <code>socket/4</code> with <var>TYPE</var> bound to <code>'SOCK_STREAM'</code> and
<var>PROTOCOL</var> bound to <code>0</code>.
</p>
</dd>
<dt><code>socket_close(+<var>SOCKET</var>)</code></dt>
<dd><a name="index-socket_005fclose_002f1"></a>
<a name="index-socket_005fclose_002f1-1"></a>
<a name="index-socket_005fclose_002f1-2"></a>
<p>Close socket <var>SOCKET</var>. Note that sockets used in
<code>socket_connect</code> (that is, client sockets) should not be closed with
<code>socket_close</code>, as they will be automatically closed when the
corresponding stream is closed with <code>close/1</code> or <code>close/2</code>.
</p>
</dd>
<dt><code>socket_bind(+<var>SOCKET</var>, ?<var>PORT</var>)</code></dt>
<dd><a name="index-socket_005fbind_002f2"></a>
<a name="index-socket_005fbind_002f2-1"></a>
<a name="index-socket_005fbind_002f2-2"></a>
<p>Interface to system call <code>bind</code>, as used for servers: bind socket
to a port. Port information depends on the domain:
</p><dl compact="compact">
<dt><code>'AF_UNIX'(+<var>FILENAME</var>)</code></dt>
<dt><code>'AF_FILE'(+<var>FILENAME</var>)</code></dt>
<dd><p>use file name <var>FILENAME</var> for UNIX or local sockets.
</p>
</dd>
<dt><code>'AF_INET'(?<var>HOST</var>,?PORT)</code></dt>
<dd><p>If <var>HOST</var> is bound to an atom, bind to host <var>HOST</var>, otherwise
if unbound bind to local host (<var>HOST</var> remains unbound). If port
<var>PORT</var> is bound to an integer, try to bind to the corresponding
port. If variable <var>PORT</var> is unbound allow operating systems to
choose a port number, which is unified with <var>PORT</var>.
</p>
</dd>
</dl>
</dd>
<dt><code>socket_connect(+<var>SOCKET</var>, +<var>PORT</var>, -<var>STREAM</var>)</code></dt>
<dd><a name="index-socket_005fconnect_002f3"></a>
<a name="index-socket_005fconnect_002f3-1"></a>
<a name="index-socket_005fconnect_002f3-2"></a>
<p>Interface to system call <code>connect</code>, used for clients: connect
socket <var>SOCKET</var> to <var>PORT</var>. The connection results in the
read/write stream <var>STREAM</var>.
</p>
<p>Port information depends on the domain:
</p><dl compact="compact">
<dt><code>'AF_UNIX'(+<var>FILENAME</var>)</code></dt>
<dt><code>'AF_FILE'(+<var>FILENAME</var>)</code></dt>
<dd><p>connect to socket at file <var>FILENAME</var>.
</p>
</dd>
<dt><code>'AF_INET'(+<var>HOST</var>,+<var>PORT</var>)</code></dt>
<dd><p>Connect to socket at host <var>HOST</var> and port <var>PORT</var>.
</p></dd>
</dl>
</dd>
<dt><code>socket_listen(+<var>SOCKET</var>, +<var>LENGTH</var>)</code></dt>
<dd><a name="index-socket_005flisten_002f2"></a>
<a name="index-socket_005flisten_002f2-1"></a>
<a name="index-socket_005flisten_002f2-2"></a>
<p>Interface to system call <code>listen</code>, used for servers to indicate
willingness to wait for connections at socket <var>SOCKET</var>. The
integer <var>LENGTH</var> gives the queue limit for incoming connections,
and should be limited to <code>5</code> for portable applications. The socket
must be of type <code>SOCK_STREAM</code> or <code>SOCK_SEQPACKET</code>.
</p>
</dd>
<dt><code>socket_accept(+<var>SOCKET</var>, -<var>STREAM</var>)</code></dt>
<dd><a name="index-socket_005faccept_002f2"></a>
<a name="index-socket_005faccept_002f2-1"></a>
<a name="index-socket_005faccept_002f2-2"></a>
</dd>
<dt><code>socket_accept(+<var>SOCKET</var>, -<var>CLIENT</var>, -<var>STREAM</var>)</code></dt>
<dd><a name="index-socket_005faccept_002f3"></a>
<a name="index-socket_005faccept_002f3-1"></a>
<a name="index-socket_005faccept_002f3-2"></a>
<p>Interface to system call <code>accept</code>, used for servers to wait for
connections at socket <var>SOCKET</var>. The stream descriptor <var>STREAM</var>
represents the resulting connection. If the socket belongs to the
domain <code>'AF_INET'</code>, <var>CLIENT</var> unifies with an atom containing
the IP address for the client in numbers and dots notation.
</p>
</dd>
<dt><code>socket_accept(+<var>SOCKET</var>, -<var>STREAM</var>)</code></dt>
<dd><a name="index-socket_005faccept_002f2-3"></a>
<a name="index-socket_005faccept_002f2-4"></a>
<a name="index-socket_005faccept_002f2-5"></a>
<p>Accept a connection but do not return client information.
</p>
</dd>
<dt><code>socket_buffering(+<var>SOCKET</var>, -<var>MODE</var>, -<var>OLD</var>, +<var>NEW</var>)</code></dt>
<dd><a name="index-socket_005fbuffering_002f4"></a>
<a name="index-socket_005fbuffering_002f4-1"></a>
<a name="index-socket_005fbuffering_002f4-2"></a>
<p>Set buffering for <var>SOCKET</var> in <code>read</code> or <code>write</code>
<var>MODE</var>. <var>OLD</var> is unified with the previous status, and <var>NEW</var>
receives the new status which may be one of <code>unbuf</code> or
<code>fullbuf</code>.
</p>
</dd>
<dt><code>socket_select(+<var>SOCKETS</var>, -<var>NEWSTREAMS</var>, +<var>TIMEOUT</var>, +<var>STREAMS</var>, -<var>READSTREAMS</var>)</code></dt>
<dd><a name="index-socket_005fselect_002f5"></a>
<a name="index-socket_005fselect_002f5-1"></a>
<a name="index-socket_005fselect_002f5-2"></a>
<p>Interface to system call <code>select</code>, used for servers to wait for
connection requests or for data at sockets. The variable
<var>SOCKETS</var> is a list of form <var>KEY-SOCKET</var>, where <var>KEY</var> is
an user-defined identifier and <var>SOCKET</var> is a socket descriptor. The
variable <var>TIMEOUT</var> is either <code>off</code>, indicating execution will
wait until something is available, or of the form <var>SEC-USEC</var>, where
<var>SEC</var> and <var>USEC</var> give the seconds and microseconds before
<code>socket_select/5</code> returns. The variable <var>SOCKETS</var> is a list of
form <var>KEY-STREAM</var>, where <var>KEY</var> is an user-defined identifier
and <var>STREAM</var> is a stream descriptor
</p>
<p>Execution of <code>socket_select/5</code> unifies <var>READSTREAMS</var> from
<var>STREAMS</var> with readable data, and <var>NEWSTREAMS</var> with a list of
the form <var>KEY-STREAM</var>, where <var>KEY</var> was the key for a socket
with pending data, and <var>STREAM</var> the stream descriptor resulting
from accepting the connection.
</p>
</dd>
<dt><code>current_host(?<var>HOSTNAME</var>)</code></dt>
<dd><p>Unify <var>HOSTNAME</var> with an atom representing the fully qualified
hostname for the current host. Also succeeds if <var>HOSTNAME</var> is bound
to the unqualified hostname.
</p>
</dd>
<dt><code>hostname_address(?<var>HOSTNAME</var>,?<var>IP_ADDRESS</var>)</code></dt>
<dd><p><var>HOSTNAME</var> is an host name and <var>IP_ADDRESS</var> its IP
address in number and dots notation.
</p>
</dd>
</dl>
<hr>
<a name="Database"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Sockets" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Modifying-the-Database" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Using-the-Clausal-Data-Base"></a>
<h2 class="section">6.10 Using the Clausal Data Base</h2>
<p>Predicates in YAP may be dynamic or static. By default, when
consulting or reconsulting, predicates are assumed to be static:
execution is faster and the code will probably use less space.
Static predicates impose some restrictions: in general there can be no
addition or removal of clauses for a procedure if it is being used in the
current execution.
</p>
<p>Dynamic predicates allow programmers to change the Clausal Data Base with
the same flexibility as in C-Prolog. With dynamic predicates it is
always possible to add or remove clauses during execution and the
semantics will be the same as for C-Prolog. But the programmer should be
aware of the fact that asserting or retracting are still expensive operations,
and therefore he should try to avoid them whenever possible.
</p>
<dl compact="compact">
<dt><code>dynamic +<var>P</var></code></dt>
<dd><a name="index-dynamic_002f1"></a>
<a name="index-dynamic_002f1-1"></a>
<a name="index-dynamic_002f1-2"></a>
<p>Declares predicate <var>P</var> or list of predicates [<var>P1</var>,...,<var>Pn</var>]
as a dynamic predicate. <var>P</var> must be written in form:
<var>name/arity</var>.
</p>
<div class="example">
<pre class="example">:- dynamic god/1.
</pre></div>
<p>a more convenient form can be used:
</p>
<div class="example">
<pre class="example">:- dynamic son/3, father/2, mother/2.
</pre></div>
<p>or, equivalently,
</p>
<div class="example">
<pre class="example">:- dynamic [son/3, father/2, mother/2].
</pre></div>
<p>Note:
</p>
<p>a predicate is assumed to be dynamic when
asserted before being defined.
</p>
</dd>
<dt><code>dynamic_predicate(+<var>P</var>,+<var>Semantics</var>)</code></dt>
<dd><a name="index-dynamic_005fpredicate_002f2"></a>
<a name="index-dynamic_005fpredicate_002f2-1"></a>
<a name="index-dynamic_005fpredicate_002f2-2"></a>
<p>Declares predicate <var>P</var> or list of predicates [<var>P1</var>,...,<var>Pn</var>]
as a dynamic predicate following either <code>logical</code> or
<code>immediate</code> semantics.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Database
</pre></th></tr><tr><td align="left" valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Asserting and Retracting
</td></tr>
<tr><td align="left" valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Finding out what is in the Data Base
</td></tr>
<tr><td align="left" valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> YAP&rsquo;s Internal Database
</td></tr>
<tr><td align="left" valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Storing and Fetching Terms in the BlackBoard
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
</pre></th></tr></table>
</dd>
</dl>
<hr>
<a name="Modifying-the-Database"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Database" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Database" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Looking-at-the-Database" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Modification-of-the-Data-Base"></a>
<h3 class="subsection">6.10.1 Modification of the Data Base</h3>
<p>These predicates can be used either for static or for dynamic
predicates:
</p>
<dl compact="compact">
<dt><code>assert(+<var>C</var>)</code></dt>
<dd><a name="index-assert_002f1"></a>
<a name="index-assert_002f1-1"></a>
<a name="index-assert_002f1-2"></a>
<p> Same as <code>assertz/1</code>. Adds clause <var>C</var> to the program. If the predicate is undefined,
declare it as dynamic. New code should use <code>assertz/1</code> for better portability.
</p>
<p> Most Prolog systems only allow asserting clauses for dynamic
predicates. This is also as specified in the ISO standard. YAP allows
asserting clauses for static predicates, as long as the predicate is not
in use and the language flag is <tt>cprolog</tt>. Note that this feature is
deprecated, if you want to assert clauses for static procedures you
should use <code>assert_static/1</code>.
</p>
</dd>
<dt><code>asserta(+<var>C</var>) [ISO]</code></dt>
<dd><a name="index-asserta_002f1"></a>
<a name="index-asserta_002f1-1"></a>
<a name="index-asserta_002f1-2"></a>
<p> Adds clause <var>C</var> to the beginning of the program. If the predicate is
undefined, declare it as dynamic.
</p>
</dd>
<dt><code>assertz(+<var>C</var>) [ISO]</code></dt>
<dd><a name="index-assertz_002f1"></a>
<a name="index-assertz_002f1-1"></a>
<a name="index-assertz_002f1-2"></a>
<p> Adds clause <var>C</var> to the end of the program. If the predicate is
undefined, declare it as dynamic.
</p>
<p> Most Prolog systems only allow asserting clauses for dynamic
predicates. This is also as specified in the ISO standard. YAP allows
asserting clauses for static predicates. The current version of YAP
supports this feature, but this feature is deprecated and support may go
away in future versions.
</p>
</dd>
<dt><code>abolish(+<var>PredSpec</var>) [ISO]</code></dt>
<dd><a name="index-abolish_002f1"></a>
<a name="index-abolish_002f1-1"></a>
<a name="index-abolish_002f1-2"></a>
<p> Deletes the predicate given by <var>PredSpec</var> from the database. If
<var>PredSpec</var> is an unbound variable, delete all predicates for the
current module. The
specification must include the name and arity, and it may include module
information. Under <tt>iso</tt> language mode this built-in will only abolish
dynamic procedures. Under other modes it will abolish any procedures.
</p>
</dd>
<dt><code>abolish(+<var>P</var>,+<var>N</var>)</code></dt>
<dd><a name="index-abolish_002f2"></a>
<a name="index-abolish_002f2-1"></a>
<a name="index-abolish_002f2-2"></a>
<p> Deletes the predicate with name <var>P</var> and arity <var>N</var>. It will remove
both static and dynamic predicates.
</p>
</dd>
<dt><code>assert_static(:<var>C</var>)</code></dt>
<dd><a name="index-assert_005fstatic_002f1"></a>
<a name="index-assert_005fstatic_002f1-1"></a>
<a name="index-assert_005fstatic_002f1-2"></a>
<p>Adds clause <var>C</var> to a static procedure. Asserting a static clause
for a predicate while choice-points for the predicate are available has
undefined results.
</p>
</dd>
<dt><code>asserta_static(:<var>C</var>)</code></dt>
<dd><a name="index-asserta_005fstatic_002f1"></a>
<a name="index-asserta_005fstatic_002f1-1"></a>
<a name="index-asserta_005fstatic_002f1-2"></a>
<p> Adds clause <var>C</var> to the beginning of a static procedure.
</p>
</dd>
<dt><code>assertz_static(:<var>C</var>)</code></dt>
<dd><a name="index-assertz_005fstatic_002f1"></a>
<a name="index-assertz_005fstatic_002f1-1"></a>
<a name="index-assertz_005fstatic_002f1-2"></a>
<p> Adds clause <var>C</var> 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.
</p>
</dd>
</dl>
<p>The following predicates can be used for dynamic predicates and for
static predicates, if source mode was on when they were compiled:
</p>
<dl compact="compact">
<dt><code>clause(+<var>H</var>,<var>B</var>) [ISO]</code></dt>
<dd><a name="index-clause_002f2"></a>
<a name="index-clause_002f2-1"></a>
<a name="index-clause_002f2-2"></a>
<p> A clause whose head matches <var>H</var> is searched for in the
program. Its head and body are respectively unified with <var>H</var> and
<var>B</var>. If the clause is a unit clause, <var>B</var> is unified with
<var>true</var>.
</p>
<p>This predicate is applicable to static procedures compiled with
<code>source</code> active, and to all dynamic procedures.
</p>
</dd>
<dt><code>clause(+<var>H</var>,<var>B</var>,-<var>R</var>)</code></dt>
<dd><a name="index-clause_002f3"></a>
<a name="index-clause_002f3-1"></a>
<a name="index-clause_002f3-2"></a>
<p>The same as <code>clause/2</code>, plus <var>R</var> is unified with the
reference to the clause in the database. You can use <code>instance/2</code>
to access the reference&rsquo;s value. Note that you may not use
<code>erase/1</code> on the reference on static procedures.
</p>
</dd>
<dt><code>nth_clause(+<var>H</var>,<var>I</var>,-<var>R</var>)</code></dt>
<dd><a name="index-nth_005fclause_002f3"></a>
<a name="index-nth_005fclause_002f3-1"></a>
<a name="index-nth_005fclause_002f3-2"></a>
<p>Find the <var>I</var>th clause in the predicate defining <var>H</var>, and give
a reference to the clause. Alternatively, if the reference <var>R</var> is
given the head <var>H</var> is unified with a description of the predicate
and <var>I</var> is bound to its position.
</p>
</dd>
</dl>
<p>The following predicates can only be used for dynamic predicates:
</p>
<dl compact="compact">
<dt><code>retract(+<var>C</var>) [ISO]</code></dt>
<dd><a name="index-retract_002f1"></a>
<a name="index-retract_002f1-1"></a>
<a name="index-retract_002f1-2"></a>
<p>Erases the first clause in the program that matches <var>C</var>. This
predicate may also be used for the static predicates that have been
compiled when the source mode was <code>on</code>. For more information on
<code>source/0</code> (see section <a href="#Setting-the-Compiler">Changing the Compiler&rsquo;s Behavior</a>).
</p>
</dd>
<dt><code>retractall(+<var>G</var>)</code></dt>
<dd><a name="index-retractall_002f1"></a>
<a name="index-retractall_002f1-1"></a>
<a name="index-retractall_002f1-2"></a>
<p>Retract all the clauses whose head matches the goal <var>G</var>. Goal
<var>G</var> must be a call to a dynamic predicate.
</p>
</dd>
</dl>
<hr>
<a name="Looking-at-the-Database"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Modifying-the-Database" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Database" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Database-References" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Looking-at-the-Data-Base"></a>
<h3 class="subsection">6.10.2 Looking at the Data Base</h3>
<dl compact="compact">
<dt><code>listing</code></dt>
<dd><a name="index-listing_002f0"></a>
<a name="index-listing_002f0-1"></a>
<a name="index-listing_002f0-2"></a>
<p>Lists in the current output stream all the clauses for which source code
is available (these include all clauses for dynamic predicates and
clauses for static predicates compiled when source mode was <code>on</code>).
</p>
</dd>
<dt><code>listing(+<var>P</var>)</code></dt>
<dd><a name="index-listing_002f1"></a>
<a name="index-listing_002f1-1"></a>
<a name="index-listing_002f1-2"></a>
<p>Lists predicate <var>P</var> if its source code is available.
</p>
</dd>
<dt><code>portray_clause(+<var>C</var>)</code></dt>
<dd><a name="index-portray_005fclause_002f1"></a>
<a name="index-portray_005fclause_002f1-1"></a>
<a name="index-portray_005fclause_002f1-2"></a>
<p>Write clause <var>C</var> as if written by <code>listing/0</code>.
</p>
</dd>
<dt><code>portray_clause(+<var>S</var>,+<var>C</var>)</code></dt>
<dd><a name="index-portray_005fclause_002f2"></a>
<a name="index-portray_005fclause_002f2-1"></a>
<a name="index-portray_005fclause_002f2-2"></a>
<p>Write clause <var>C</var> on stream <var>S</var> as if written by <code>listing/0</code>.
</p>
</dd>
<dt><code>current_atom(<var>A</var>)</code></dt>
<dd><a name="index-current_005fatom_002f1"></a>
<a name="index-current_005fatom_002f1-1"></a>
<a name="index-current_005fatom_002f1-2"></a>
<p>Checks whether <var>A</var> is a currently defined atom. It is used to find all
currently defined atoms by backtracking.
</p>
</dd>
<dt><code>current_predicate(<var>F</var>) [ISO]</code></dt>
<dd><a name="index-current_005fpredicate_002f1"></a>
<a name="index-current_005fpredicate_002f1-1"></a>
<a name="index-current_005fpredicate_002f1-2"></a>
<p><var>F</var> is the predicate indicator for a currently defined user or
library predicate. <var>F</var> is of the form <var>Na/Ar</var>, where the atom
<var>Na</var> is the name of the predicate, and <var>Ar</var> its arity.
</p>
</dd>
<dt><code>current_predicate(<var>A</var>,<var>P</var>)</code></dt>
<dd><a name="index-current_005fpredicate_002f2"></a>
<a name="index-current_005fpredicate_002f2-1"></a>
<a name="index-current_005fpredicate_002f2-2"></a>
<p>Defines the relation: <var>P</var> is a currently defined predicate whose
name is the atom <var>A</var>.
</p>
</dd>
<dt><code>system_predicate(<var>A</var>,<var>P</var>)</code></dt>
<dd><a name="index-system_005fpredicate_002f2"></a>
<a name="index-system_005fpredicate_002f2-1"></a>
<a name="index-system_005fpredicate_002f2-2"></a>
<p>Defines the relation: <var>P</var> is a built-in predicate whose name
is the atom <var>A</var>.
</p>
</dd>
<dt><code>predicate_property(<var>P</var>,<var>Prop</var>) [ISO]</code></dt>
<dd><a name="index-predicate_005fproperty_002f2"></a>
<a name="index-predicate_005fproperty_002f2-1"></a>
<a name="index-predicate_005fproperty_002f2-2"></a>
<p>For the predicates obeying the specification <var>P</var> unify <var>Prop</var>
with a property of <var>P</var>. These properties may be:
</p><dl compact="compact">
<dt><code>built_in</code></dt>
<dd><p>true for built-in predicates,
</p></dd>
<dt><code>dynamic</code></dt>
<dd><p>true if the predicate is dynamic
</p></dd>
<dt><code>static</code></dt>
<dd><p>true if the predicate is static
</p></dd>
<dt><code>meta_predicate(<var>M</var>)</code></dt>
<dd><p>true if the predicate has a meta_predicate declaration <var>M</var>.
</p></dd>
<dt><code>multifile</code></dt>
<dd><p>true if the predicate was declared to be multifile
</p></dd>
<dt><code>imported_from(<var>Mod</var>)</code></dt>
<dd><p>true if the predicate was imported from module <var>Mod</var>.
</p></dd>
<dt><code>exported</code></dt>
<dd><p>true if the predicate is exported in the current module.
</p></dd>
<dt><code>public</code></dt>
<dd><p>true if the predicate is public; note that all dynamic predicates are
public.
</p></dd>
<dt><code>tabled</code></dt>
<dd><p>true if the predicate is tabled; note that only static predicates can
be tabled in YAP.
</p></dd>
<dt><code>source</code></dt>
<dd><p>true if source for the predicate is available.
</p></dd>
<dt><code>number_of_clauses(<var>ClauseCount</var>)</code></dt>
<dd><p>Number of clauses in the predicate definition. Always one if external
or built-in.
</p></dd>
</dl>
</dd>
</dl>
<hr>
<a name="Database-References"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Looking-at-the-Database" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Database" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Internal-Database" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Using-Data-Base-References"></a>
<h3 class="subsection">6.10.3 Using Data Base References</h3>
<p>Data Base references are a fast way of accessing terms. The predicates
<code>erase/1</code> and <code>instance/1</code> also apply to these references and may
sometimes be used instead of <code>retract/1</code> and <code>clause/2</code>.
</p>
<dl compact="compact">
<dt><code>assert(+<var>C</var>,-<var>R</var>)</code></dt>
<dd><a name="index-assert_002f2"></a>
<a name="index-assert_002f2-1"></a>
<a name="index-assert_002f2-2"></a>
<p> The same as <code>assert(C)</code> (see section <a href="#Modifying-the-Database">Modification of the Data Base</a>) but
unifies <var>R</var> with the database reference that identifies the new
clause, in a one-to-one way. Note that <code>asserta/2</code> only works for dynamic
predicates. If the predicate is undefined, it will automatically be
declared dynamic.
</p>
</dd>
<dt><code>asserta(+<var>C</var>,-<var>R</var>)</code></dt>
<dd><a name="index-asserta_002f2"></a>
<a name="index-asserta_002f2-1"></a>
<a name="index-asserta_002f2-2"></a>
<p> The same as <code>asserta(C)</code> but unifying <var>R</var> with
the database reference that identifies the new clause, in a
one-to-one way. Note that <code>asserta/2</code> only works for dynamic
predicates. If the predicate is undefined, it will automatically be
declared dynamic.
</p>
</dd>
<dt><code>assertz(+<var>C</var>,-<var>R</var>)</code></dt>
<dd><a name="index-assertz_002f2"></a>
<a name="index-assertz_002f2-1"></a>
<a name="index-assertz_002f2-2"></a>
<p> The same as <code>assertz(C)</code> but unifying <var>R</var> with
the database reference that identifies the new clause, in a
one-to-one way. Note that <code>asserta/2</code> only works for dynamic
predicates. If the predicate is undefined, it will automatically be
declared dynamic.
</p>
</dd>
<dt><code>retract(+<var>C</var>,-<var>R</var>)</code></dt>
<dd><a name="index-retract_002f2"></a>
<a name="index-retract_002f2-1"></a>
<a name="index-retract_002f2-2"></a>
<p> Erases from the program the clause <var>C</var> whose
database reference is <var>R</var>. The predicate must be dynamic.
</p>
</dd>
</dl>
<hr>
<a name="Internal-Database"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Database-References" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#BlackBoard" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Internal-Data-Base"></a>
<h2 class="section">6.11 Internal Data Base</h2>
<p>Some programs need global information for, e.g. counting or collecting
data obtained by backtracking. As a rule, to keep this information, the
internal data base should be used instead of asserting and retracting
clauses (as most novice programmers do), .
In YAP (as in some other Prolog systems) the internal data base (i.d.b.
for short) is faster, needs less space and provides a better insulation of
program and data than using asserted/retracted clauses.
The i.d.b. is implemented as a set of terms, accessed by keys that
unlikely what happens in (non-Prolog) data bases are not part of the
term. Under each key a list of terms is kept. References are provided so that
terms can be identified: each term in the i.d.b. has a unique reference
(references are also available for clauses of dynamic predicates).
</p>
<dl compact="compact">
<dt><code>recorda(+<var>K</var>,<var>T</var>,-<var>R</var>)</code></dt>
<dd><a name="index-recorda_002f3"></a>
<a name="index-recorda_002f3-1"></a>
<a name="index-recorda_002f3-2"></a>
<p>Makes term <var>T</var> the first record under key <var>K</var> and unifies <var>R</var>
with its reference.
</p>
</dd>
<dt><code>recordz(+<var>K</var>,<var>T</var>,-<var>R</var>)</code></dt>
<dd><a name="index-recordz_002f3"></a>
<a name="index-recordz_002f3-1"></a>
<a name="index-recordz_002f3-2"></a>
<p>Makes term <var>T</var> the last record under key <var>K</var> and unifies <var>R</var>
with its reference.
</p>
</dd>
<dt><code>recorda_at(+<var>R0</var>,<var>T</var>,-<var>R</var>)</code></dt>
<dd><a name="index-recorda_005fat_002f3"></a>
<a name="index-recorda_005fat_002f3-1"></a>
<a name="index-recorda_005fat_002f3-2"></a>
<p>Makes term <var>T</var> the record preceding record with reference
<var>R0</var>, and unifies <var>R</var> with its reference.
</p>
</dd>
<dt><code>recordz_at(+<var>R0</var>,<var>T</var>,-<var>R</var>)</code></dt>
<dd><a name="index-recordz_005fat_002f3"></a>
<a name="index-recordz_005fat_002f3-1"></a>
<a name="index-recordz_005fat_002f3-2"></a>
<p>Makes term <var>T</var> the record following record with reference
<var>R0</var>, and unifies <var>R</var> with its reference.
</p>
</dd>
<dt><code>recordaifnot(+<var>K</var>,<var>T</var>,-<var>R</var>)</code></dt>
<dd><a name="index-recordaifnot_002f3"></a>
<a name="index-recordaifnot_002f3-1"></a>
<a name="index-recordaifnot_002f3-2"></a>
<p>If a term equal to <var>T</var> up to variable renaming is stored under key
<var>K</var> fail. Otherwise, make term <var>T</var> the first record under key
<var>K</var> and unify <var>R</var> with its reference.
</p>
</dd>
<dt><code>recordzifnot(+<var>K</var>,<var>T</var>,-<var>R</var>)</code></dt>
<dd><a name="index-recorda_002f3-3"></a>
<a name="index-recorda_002f3-4"></a>
<a name="index-recorda_002f3-5"></a>
<p>If a term equal to <var>T</var> up to variable renaming is stored under key
<var>K</var> fail. Otherwise, make term <var>T</var> the first record under key
<var>K</var> and unify <var>R</var> with its reference.
</p>
</dd>
<dt><code>recorded(+<var>K</var>,<var>T</var>,<var>R</var>)</code></dt>
<dd><a name="index-recorded_002f3"></a>
<a name="index-recorded_002f3-1"></a>
<a name="index-recorded_002f3-2"></a>
<p>Searches in the internal database under the key <var>K</var>, a term that
unifies with <var>T</var> and whose reference matches <var>R</var>. This
built-in may be used in one of two ways:
</p><ul>
<li> <var>K</var> may be given, in this case the built-in will return all
elements of the internal data-base that match the key.
</li><li> <var>R</var> may be given, if so returning the key and element that
match the reference.
</li></ul>
</dd>
<dt><code>erase(+<var>R</var>)</code></dt>
<dd><a name="index-erase_002f1"></a>
<a name="index-erase_002f1-1"></a>
<a name="index-erase_002f1-2"></a>
<p>The term referred to by <var>R</var> is erased from the internal database. If
reference <var>R</var> does not exist in the database, <code>erase</code> just fails.
</p>
</dd>
<dt><code>erased(+<var>R</var>)</code></dt>
<dd><a name="index-erased_002f1"></a>
<a name="index-erased_002f1-1"></a>
<a name="index-erased_002f1-2"></a>
<p>Succeeds if the object whose database reference is <var>R</var> has been
erased.
</p>
</dd>
<dt><code>instance(+<var>R</var>,-<var>T</var>)</code></dt>
<dd><a name="index-instance_002f2"></a>
<a name="index-instance_002f2-1"></a>
<a name="index-instance_002f2-2"></a>
<p>If <var>R</var> refers to a clause or a recorded term, <var>T</var> is unified
with its most general instance. If <var>R</var> refers to an unit clause
<var>C</var>, then <var>T</var> is unified with <code><var>C</var> :- true</code>. When
<var>R</var> is not a reference to an existing clause or to a recorded term,
this goal fails.
</p>
</dd>
<dt><code>eraseall(+<var>K</var>)</code></dt>
<dd><a name="index-eraseall_002f1"></a>
<a name="index-eraseall_002f1-1"></a>
<a name="index-eraseall_002f1-2"></a>
<p>All terms belonging to the key <code>K</code> are erased from the internal
database. The predicate always succeeds.
</p>
</dd>
<dt><code>current_key(?<var>A</var>,?<var>K</var>)</code></dt>
<dd><a name="index-current_005fkey_002f2"></a>
<a name="index-current_005fkey_002f2-1"></a>
<a name="index-current_005fkey_002f2-2"></a>
<p>Defines the relation: <var>K</var> is a currently defined database key whose
name is the atom <var>A</var>. It can be used to generate all the keys for
the internal data-base.
</p>
</dd>
<dt><code>nth_instance(?<var>Key</var>,?<var>Index</var>,?<var>R</var>)</code></dt>
<dd><a name="index-nth_005finstance_002f3"></a>
<a name="index-nth_005finstance_002f3-1"></a>
<a name="index-nth_005finstance_002f3-2"></a>
<p>Fetches the <var>Index</var>nth entry in the internal database under the key
<var>Key</var>. Entries are numbered from one. If the key <var>Key</var> or the
<var>Index</var> are bound, a reference is unified with <var>R</var>. Otherwise,
the reference <var>R</var> must be given, and YAP will find
the matching key and index.
</p>
</dd>
<dt><code>nth_instance(?<var>Key</var>,?<var>Index</var>,<var>T</var>,?<var>R</var>)</code></dt>
<dd><a name="index-nth_005finstance_002f4"></a>
<a name="index-nth_005finstance_002f4-1"></a>
<a name="index-nth_005finstance_002f4-2"></a>
<p>Fetches the <var>Index</var>nth entry in the internal database under the key
<var>Key</var>. Entries are numbered from one. If the key <var>Key</var> or the
<var>Index</var> are bound, a reference is unified with <var>R</var>. Otherwise,
the reference <var>R</var> must be given, and YAP will find
the matching key and index.
</p>
</dd>
<dt><code>key_statistics(+<var>K</var>,-<var>Entries</var>,-<var>Size</var>,-<var>IndexSize</var>)</code></dt>
<dd><a name="index-key_005fstatistics_002f4"></a>
<a name="index-key_005fstatistics_002f4-1"></a>
<a name="index-key_005fstatistics_002f4-2"></a>
<p>Returns several statistics for a key <var>K</var>. Currently, it says how
many entries we have for that key, <var>Entries</var>, what is the
total size spent on entries, <var>Size</var>, and what is the amount of
space spent in indices.
</p>
</dd>
<dt><code>key_statistics(+<var>K</var>,-<var>Entries</var>,-<var>TotalSize</var>)</code></dt>
<dd><a name="index-key_005fstatistics_002f3"></a>
<a name="index-key_005fstatistics_002f3-1"></a>
<a name="index-key_005fstatistics_002f3-2"></a>
<p>Returns several statistics for a key <var>K</var>. Currently, it says how
many entries we have for that key, <var>Entries</var>, what is the
total size spent on this key.
</p>
</dd>
<dt><code>get_value(+<var>A</var>,-<var>V</var>)</code></dt>
<dd><a name="index-get_005fvalue_002f2"></a>
<a name="index-get_005fvalue_002f2-1"></a>
<a name="index-get_005fvalue_002f2-2"></a>
<p>In YAP, atoms can be associated with constants. If one such
association exists for atom <var>A</var>, unify the second argument with the
constant. Otherwise, unify <var>V</var> with <code>[]</code>.
</p>
<p>This predicate is YAP specific.
</p>
</dd>
<dt><code>set_value(+<var>A</var>,+<var>C</var>)</code></dt>
<dd><a name="index-set_005fvalue_002f2"></a>
<a name="index-set_005fvalue_002f2-1"></a>
<a name="index-set_005fvalue_002f2-2"></a>
<p>Associate atom <var>A</var> with constant <var>C</var>.
</p>
<p>The <code>set_value</code> and <code>get_value</code> built-ins give a fast alternative to
the internal data-base. This is a simple form of implementing a global
counter.
</p><div class="example">
<pre class="example"> read_and_increment_counter(Value) :-
get_value(counter, Value),
Value1 is Value+1,
set_value(counter, Value1).
</pre></div>
<p>This predicate is YAP specific.
</p>
</dd>
<dt><code>recordzifnot(+<var>K</var>,<var>T</var>,-<var>R</var>)</code></dt>
<dd><a name="index-recordzifnot_002f3"></a>
<a name="index-recordzifnot_002f3-1"></a>
<a name="index-recordzifnot_002f3-2"></a>
<p>If a variant of <var>T</var> is stored under key <var>K</var> fail. Otherwise, make
term <var>T</var> the last record under key <var>K</var> and unify <var>R</var> with its
reference.
</p>
<p>This predicate is YAP specific.
</p>
</dd>
<dt><code>recordaifnot(+<var>K</var>,<var>T</var>,-<var>R</var>)</code></dt>
<dd><a name="index-recordaifnot_002f3-3"></a>
<a name="index-recordaifnot_002f3-4"></a>
<a name="index-recordaifnot_002f3-5"></a>
<p>If a variant of <var>T</var> is stored under key <var>K</var> fail. Otherwise, make
term <var>T</var> the first record under key <var>K</var> and unify <var>R</var> with its
reference.
</p>
<p>This predicate is YAP specific.
</p>
</dd>
</dl>
<p>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:
</p>
<div class="example">
<pre class="example">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).
</pre></div>
<p> 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.:
</p>
<div class="example">
<pre class="example">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,_).
</pre></div>
<p>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
</p>
<div class="example">
<pre class="example">b
b(a)
c(d)
e(g)
b(X)
e(h)
</pre></div>
<p>stored under the key k/1, when executing the query
</p>
<div class="example">
<pre class="example">:- recorded(k(_),c(_),R).
</pre></div>
<p><code>recorded</code> would proceed directly to the third term, spending almost the
time as if <code>a(X)</code> or <code>b(X)</code> was being searched.
The lookup function uses the functor of the term, and its first three
arguments (when they exist). So, <code>recorded(k(_),e(h),_)</code> would go
directly to the last term, while <code>recorded(k(_),e(_),_)</code> would find
first the fourth term, and then, after backtracking, the last one.
</p>
<p> 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.
</p>
<p> In the YAP&rsquo;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.
</p>
<hr>
<a name="BlackBoard"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Internal-Database" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Sets" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="The-Blackboard"></a>
<h2 class="section">6.12 The Blackboard</h2>
<p>YAP implements a blackboard in the style of the SICStus Prolog
blackboard. The blackboard uses the same underlying mechanism as the
internal data-base but has several important differences:
</p><ul>
<li> It is module aware, in contrast to the internal data-base.
</li><li> Keys can only be atoms or integers, and not compound terms.
</li><li> A single term can be stored per key.
</li><li> An atomic update operation is provided; this is useful for
parallelism.
</li></ul>
<dl compact="compact">
<dt><code>bb_put(+<var>Key</var>,?<var>Term</var>)</code></dt>
<dd><a name="index-bb_005fput_002f2"></a>
<a name="index-bb_005fput_002f2-1"></a>
<a name="index-bb_005fput_002f2-2"></a>
<p>Store term table <var>Term</var> in the blackboard under key <var>Key</var>. If a
previous term was stored under key <var>Key</var> it is simply forgotten.
</p>
</dd>
<dt><code>bb_get(+<var>Key</var>,?<var>Term</var>)</code></dt>
<dd><a name="index-bb_005fget_002f2"></a>
<a name="index-bb_005fget_002f2-1"></a>
<a name="index-bb_005fget_002f2-2"></a>
<p>Unify <var>Term</var> with a term stored in the blackboard under key
<var>Key</var>, or fail silently if no such term exists.
</p>
</dd>
<dt><code>bb_delete(+<var>Key</var>,?<var>Term</var>)</code></dt>
<dd><a name="index-bb_005fdelete_002f2"></a>
<a name="index-bb_005fdelete_002f2-1"></a>
<a name="index-bb_005fdelete_002f2-2"></a>
<p>Delete any term stored in the blackboard under key <var>Key</var> and unify
it with <var>Term</var>. Fail silently if no such term exists.
</p>
</dd>
<dt><code>bb_update(+<var>Key</var>,?<var>Term</var>,?<var>New</var>)</code></dt>
<dd><a name="index-bb_005fupdate_002f3"></a>
<a name="index-bb_005fupdate_002f3-1"></a>
<a name="index-bb_005fupdate_002f3-2"></a>
<p>Atomically unify a term stored in the blackboard under key <var>Key</var>
with <var>Term</var>, and if the unification succeeds replace it by
<var>New</var>. Fail silently if no such term exists or if unification fails.
</p>
</dd>
</dl>
<hr>
<a name="Sets"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#BlackBoard" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Grammars" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Collecting-Solutions-to-a-Goal"></a>
<h2 class="section">6.13 Collecting Solutions to a Goal</h2>
<p>When there are several solutions to a goal, if the user wants to collect all
the solutions he may be led to use the data base, because backtracking will
forget previous solutions.
</p>
<p>YAP allows the programmer to choose from several system
predicates instead of writing his own routines. <code>findall/3</code> gives you
the fastest, but crudest solution. The other built-in predicates
post-process the result of the query in several different ways:
</p>
<dl compact="compact">
<dt><code>findall(<var>T</var>,+<var>G</var>,-<var>L</var>) [ISO]</code></dt>
<dd><a name="index-findall_002f3"></a>
<a name="index-findall_002f3-1"></a>
<a name="index-findall_002f3-2"></a>
<p>Unifies <var>L</var> with a list that contains all the instantiations of the
term <var>T</var> satisfying the goal <var>G</var>.
</p>
<p>With the following program:
</p><div class="example">
<pre class="example">a(2,1).
a(1,1).
a(2,2).
</pre></div>
<p>the answer to the query
</p><div class="example">
<pre class="example">findall(X,a(X,Y),L).
</pre></div>
<p>would be:
</p><div class="example">
<pre class="example">X = _32
Y = _33
L = [2,1,2];
no
</pre></div>
</dd>
<dt><code>findall(<var>T</var>,+<var>G</var>,+<var>L</var>,-<var>L0</var>)</code></dt>
<dd><a name="index-findall_002f4"></a>
<a name="index-findall_002f4-1"></a>
<a name="index-findall_002f4-2"></a>
<p>Similar to <code>findall/3</code>, but appends all answers to list <var>L0</var>.
</p>
</dd>
<dt><code>all(<var>T</var>,+<var>G</var>,-<var>L</var>)</code></dt>
<dd><a name="index-all_002f3"></a>
<a name="index-all_002f3-1"></a>
<a name="index-all_002f3-2"></a>
<p>Similar to <code>findall(<var>T</var>,<var>G</var>,<var>L</var>)</code> but eliminate
repeated elements. Thus, assuming the same clauses as in the above
example, the reply to the query
</p>
<div class="example">
<pre class="example">all(X,a(X,Y),L).
</pre></div>
<p>would be:
</p>
<div class="example">
<pre class="example">X = _32
Y = _33
L = [2,1];
no
</pre></div>
<p>Note that <code>all/3</code> will fail if no answers are found.
</p>
</dd>
<dt><code>bagof(<var>T</var>,+<var>G</var>,-<var>L</var>) [ISO]</code></dt>
<dd><a name="index-bagof_002f3"></a>
<a name="index-bagof_002f3-1"></a>
<a name="index-bagof_002f3-2"></a>
<p>For each set of possible instances of the free variables occurring in
<var>G</var> but not in <var>T</var>, generates the list <var>L</var> of the instances of
<var>T</var> satisfying <var>G</var>. Again, assuming the same clauses as in the
examples above, the reply to the query
</p>
<div class="example">
<pre class="example">bagof(X,a(X,Y),L).
would be:
X = _32
Y = 1
L = [2,1];
X = _32
Y = 2
L = [2];
no
</pre></div>
</dd>
<dt><code>setof(<var>X</var>,+<var>P</var>,-<var>B</var>) [ISO]</code></dt>
<dd><a name="index-setof_002f3"></a>
<a name="index-setof_002f3-1"></a>
<a name="index-setof_002f3-2"></a>
<p>Similar to <code>bagof(<var>T</var>,<var>G</var>,<var>L</var>)</code> but sorting list
<var>L</var> and keeping only one copy of each element. Again, assuming the
same clauses as in the examples above, the reply to the query
</p><div class="example">
<pre class="example">setof(X,a(X,Y),L).
</pre></div>
<p>would be:
</p><div class="example">
<pre class="example">X = _32
Y = 1
L = [1,2];
X = _32
Y = 2
L = [2];
no
</pre></div>
</dd>
</dl>
<hr>
<a name="Grammars"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Sets" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#OS" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Grammar-Rules"></a>
<h2 class="section">6.14 Grammar Rules</h2>
<p>Grammar rules in Prolog are both a convenient way to express definite
clause grammars and an extension of the well known context-free grammars.
</p>
<p>A grammar rule is of the form:
</p>
<div class="example">
<pre class="example"><i> head --&gt; body </i>
</pre></div>
<p>where both <i>head</i> and <i>body</i> are sequences of one or more items
linked by the standard conjunction operator &rsquo;,&rsquo;.
</p>
<p><em>Items can be:</em>
</p>
<ul>
<li>
a <em>non-terminal</em> symbol may be either a complex term or an atom.
</li><li>
a <em>terminal</em> symbol may be any Prolog symbol. Terminals are
written as Prolog lists.
</li><li>
an <em>empty body</em> is written as the empty list &rsquo;[ ]&rsquo;.
</li><li>
<em>extra conditions</em> may be inserted as Prolog procedure calls, by being
written inside curly brackets &rsquo;{&rsquo; and &rsquo;}&rsquo;.
</li><li>
the left side of a rule consists of a nonterminal and an optional list
of terminals.
</li><li>
alternatives may be stated in the right-hand side of the rule by using
the disjunction operator &rsquo;;&rsquo;.
</li><li>
the <em>cut</em> and <em>conditional</em> symbol (&rsquo;-&gt;&rsquo;) may be inserted in the
right hand side of a grammar rule
</li></ul>
<p>Grammar related built-in predicates:
</p>
<dl compact="compact">
<dt><code><var>CurrentModule</var>:expand_term(<var>T</var>,-<var>X</var>)</code></dt>
<dt><code>user:expand_term(<var>T</var>,-<var>X</var>)</code></dt>
<dd><a name="index-expand_005fterm_002f2"></a>
<a name="index-expand_005fterm_002f2-1"></a>
<a name="index-expand_005fterm_002f2-2"></a>
<a name="index-term_005fexpansion_002f2"></a>
<a name="index-term_005fexpansion_002f2-1"></a>
<a name="index-term_005fexpansion_002f2-2"></a>
<p>This predicate is used by YAP for preprocessing each top level
term read when consulting a file and before asserting or executing it.
It rewrites a term <var>T</var> to a term <var>X</var> according to the following
rules: first try <code>term_expansion/2</code> in the current module, and then try to use the user defined predicate
<code>user:term_expansion/2</code>. If this call fails then the translating process
for DCG rules is applied, together with the arithmetic optimizer
whenever the compilation of arithmetic expressions is in progress.
</p>
</dd>
<dt><code><var>CurrentModule</var>:goal_expansion(+<var>G</var>,+<var>M</var>,-<var>NG</var>)</code></dt>
<dt><code>user:goal_expansion(+<var>G</var>,+<var>M</var>,-<var>NG</var>)</code></dt>
<dd><a name="index-goal_005fexpansion_002f3"></a>
<a name="index-goal_005fexpansion_002f3-1"></a>
<a name="index-goal_005fexpansion_002f3-2"></a>
<p>YAP now supports <code>goal_expansion/3</code>. This is an user-defined
procedure that is called after term expansion when compiling or
asserting goals for each sub-goal in a clause. The first argument is
bound to the goal and the second to the module under which the goal
<var>G</var> will execute. If <code>goal_expansion/3</code> succeeds the new
sub-goal <var>NG</var> will replace <var>G</var> and will be processed in the same
way. If <code>goal_expansion/3</code> fails the system will use the default
rules.
</p>
</dd>
<dt><code>phrase(+<var>P</var>,<var>L</var>,<var>R</var>)</code></dt>
<dd><a name="index-phrase_002f3"></a>
<a name="index-phrase_002f3-1"></a>
<a name="index-phrase_002f3-2"></a>
<p>This predicate succeeds when the difference list <code><var>L</var>-<var>R</var></code>
is a phrase of type <var>P</var>.
</p>
</dd>
<dt><code>phrase(+<var>P</var>,<var>L</var>)</code></dt>
<dd><a name="index-phrase_002f2"></a>
<a name="index-phrase_002f2-1"></a>
<a name="index-phrase_002f2-2"></a>
<p>This predicate succeeds when <var>L</var> is a phrase of type <var>P</var>. The
same as <code>phrase(P,L,[])</code>.
</p>
<p>Both this predicate and the previous are used as a convenient way to
start execution of grammar rules.
</p>
</dd>
<dt><code>'C'(<var>S1</var>,<var>T</var>,<var>S2</var>)</code></dt>
<dd><a name="index-C_002f3"></a>
<a name="index-C_002f3-1"></a>
<a name="index-C_002f3-2"></a>
<p>This predicate is used by the grammar rules compiler and is defined as
<code>'C'([H|T],H,T)</code>.
</p>
</dd>
</dl>
<hr>
<a name="OS"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Grammars" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Term-Modification" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Access-to-Operating-System-Functionality"></a>
<h2 class="section">6.15 Access to Operating System Functionality</h2>
<p>The following built-in predicates allow access to underlying
Operating System functionality:
</p>
<dl compact="compact">
<dt><code>cd(+<var>D</var>)</code></dt>
<dd><a name="index-cd_002f1"></a>
<a name="index-cd_002f1-1"></a>
<a name="index-cd_002f1-2"></a>
<p>Changes the current directory (on UNIX environments).
</p>
</dd>
<dt><code>environ(+<var>E</var>,-<var>S</var>)</code></dt>
<dd><a name="index-environ_002f2"></a>
<a name="index-environ_002f2-1"></a>
<a name="index-environ_002f2-2"></a>
<p> Given an environment variable <var>E</var> this predicate unifies the second argument <var>S</var> with its value.
</p>
</dd>
<dt><code>getcwd(-<var>D</var>)</code></dt>
<dd><a name="index-getcwd_002f1"></a>
<a name="index-getcwd_002f1-1"></a>
<a name="index-getcwd_002f1-2"></a>
<p>Unify the current directory, represented as an atom, with the argument
<var>D</var>.
</p>
</dd>
<dt><code>putenv(+<var>E</var>,+<var>S</var>)</code></dt>
<dd><a name="index-putenv_002f2"></a>
<a name="index-putenv_002f2-1"></a>
<a name="index-putenv_002f2-2"></a>
<p>Set environment variable <var>E</var> to the value <var>S</var>. If the
environment variable <var>E</var> does not exist, create a new one. Both the
environment variable and the value must be atoms.
</p>
</dd>
<dt><code>rename(+<var>F</var>,+<var>G</var>)</code></dt>
<dd><a name="index-rename_002f2"></a>
<a name="index-rename_002f2-1"></a>
<a name="index-rename_002f2-2"></a>
<p>Renames file <var>F</var> to <var>G</var>.
</p>
</dd>
<dt><code>sh</code></dt>
<dd><a name="index-sh_002f0"></a>
<a name="index-sh_002f0-1"></a>
<a name="index-sh_002f0-2"></a>
<p>Creates a new shell interaction.
</p>
</dd>
<dt><code>system(+<var>S</var>)</code></dt>
<dd><a name="index-system_002f1"></a>
<a name="index-system_002f1-1"></a>
<a name="index-system_002f1-2"></a>
<p>Passes command <var>S</var> to the Bourne shell (on UNIX environments) or the
current command interpreter in WIN32 environments.
</p>
</dd>
<dt><code>unix(+<var>S</var>)</code></dt>
<dd><a name="index-unix_002f1"></a>
<a name="index-unix_002f1-1"></a>
<a name="index-unix_002f1-2"></a>
<p>Access to Unix-like functionality:
</p><dl compact="compact">
<dt><code>argv/1</code></dt>
<dd><p>Return a list of arguments to the program. These are the arguments that
follow a <code>--</code>, as in the usual Unix convention.
</p></dd>
<dt><code>cd/0</code></dt>
<dd><p>Change to home directory.
</p></dd>
<dt><code>cd/1</code></dt>
<dd><p>Change to given directory. Acceptable directory names are strings or
atoms.
</p></dd>
<dt><code>environ/2</code></dt>
<dd><p>If the first argument is an atom, unify the second argument with the
value of the corresponding environment variable.
</p></dd>
<dt><code>getcwd/1</code></dt>
<dd><p>Unify the first argument with an atom representing the current directory.
</p></dd>
<dt><code>putenv/2</code></dt>
<dd><p>Set environment variable <var>E</var> to the value <var>S</var>. If the
environment variable <var>E</var> does not exist, create a new one. Both the
environment variable and the value must be atoms.
</p></dd>
<dt><code>shell/1</code></dt>
<dd><p>Execute command under current shell. Acceptable commands are strings or
atoms.
</p></dd>
<dt><code>system/1</code></dt>
<dd><p>Execute command with <code>/bin/sh</code>. Acceptable commands are strings or
atoms.
</p></dd>
<dt><code>shell/0</code></dt>
<dd><p>Execute a new shell.
</p></dd>
</dl>
</dd>
<dt><code>alarm(+<var>Seconds</var>,+<var>Callable</var>,+<var>OldAlarm</var>)</code></dt>
<dd><a name="index-alarm_002f3"></a>
<a name="index-alarm_002f3-1"></a>
<a name="index-alarm_002f3-2"></a>
<p>Arranges for YAP to be interrupted in <var>Seconds</var> seconds, or in
[<var>Seconds</var>|<var>MicroSeconds</var>]. When interrupted, YAP will execute
<var>Callable</var> and then return to the previous execution. If
<var>Seconds</var> is <code>0</code>, no new alarm is scheduled. In any event,
any previously set alarm is canceled.
</p>
<p>The variable <var>OldAlarm</var> unifies with the number of seconds remaining
until any previously scheduled alarm was due to be delivered, or with
<code>0</code> if there was no previously scheduled alarm.
</p>
<p>Note that execution of <var>Callable</var> will wait if YAP is
executing built-in predicates, such as Input/Output operations.
</p>
<p>The next example shows how <var>alarm/3</var> can be used to implement a
simple clock:
</p>
<div class="example">
<pre class="example">loop :- loop.
ticker :- write('.'), flush_output,
get_value(tick, yes),
alarm(1,ticker,_).
:- set_value(tick, yes), alarm(1,ticker,_), loop.
</pre></div>
<p>The clock, <code>ticker</code>, writes a dot and then checks the flag
<code>tick</code> to see whether it can continue ticking. If so, it calls
itself again. Note that there is no guarantee that the each dot
corresponds a second: for instance, if the YAP is waiting for
user input, <code>ticker</code> will wait until the user types the entry in.
</p>
<p>The next example shows how <code>alarm/3</code> can be used to guarantee that
a certain procedure does not take longer than a certain amount of time:
</p>
<div class="example">
<pre class="example">loop :- loop.
:- catch((alarm(10, throw(ball), _),loop),
ball,
format('Quota exhausted.~n',[])).
</pre></div>
<p>In this case after <code>10</code> seconds our <code>loop</code> is interrupted,
<code>ball</code> is thrown, and the handler writes <code>Quota exhausted</code>.
Execution then continues from the handler.
</p>
<p>Note that in this case <code>loop/0</code> always executes until the alarm is
sent. Often, the code you are executing succeeds or fails before the
alarm is actually delivered. In this case, you probably want to disable
the alarm when you leave the procedure. The next procedure does exactly so:
</p><div class="example">
<pre class="example">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) -&gt; alarm(0, alarm, _) ; alarm(0, alarm, _), fail).
</pre></div>
<p>The procedure <code>once_with_alarm/3</code> has three arguments:
the <var>Time</var> to wait before the alarm is
sent; the <var>Goal</var> to execute; and the goal <var>DoOnAlarm</var> to execute
if the alarm is sent. It uses <code>catch/3</code> to handle the case the
<code>alarm</code> is sent. Then it starts the alarm, calls the goal
<var>Goal</var>, and disables the alarm on success or failure.
</p>
</dd>
<dt><code>on_signal(+<var>Signal</var>,?<var>OldAction</var>,+<var>Callable</var>)</code></dt>
<dd><a name="index-on_005fsignal_002f3"></a>
<a name="index-on_005fsignal_002f3-1"></a>
<a name="index-on_005fsignal_002f3-2"></a>
<p>Set the interrupt handler for soft interrupt <var>Signal</var> to be
<var>Callable</var>. <var>OldAction</var> is unified with the previous handler.
</p>
<p>Only a subset of the software interrupts (signals) can have their
handlers manipulated through <code>on_signal/3</code>.
Their POSIX names, YAP names and default behavior is given below.
The &quot;YAP name&quot; of the signal is the atom that is associated with
each signal, and should be used as the first argument to
<code>on_signal/3</code>. It is chosen so that it matches the signal&rsquo;s POSIX
name.
</p>
<p><code>on_signal/3</code> 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.
</p>
<dl compact="compact">
<dt><code>sig_up (Hangup)</code></dt>
<dd><p> SIGHUP in Unix/Linux; Reconsult the initialization files
~/.yaprc, ~/.prologrc and ~/prolog.ini.
</p></dd>
<dt><code>sig_usr1 and sig_usr2 (User signals)</code></dt>
<dd><p> SIGUSR1 and SIGUSR2 in Unix/Linux; Print a message and halt.
</p></dd>
</dl>
<p>A special case is made, where if <var>Callable</var> is bound to
<code>default</code>, then the default handler is restored for that signal.
</p>
<p>A call in the form <code>on_signal(<var>S</var>,<var>H</var>,<var>H</var>)</code> can be used
to retrieve a signal&rsquo;s current handler without changing it.
</p>
<p>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.
</p>
<p>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.
</p>
</dd>
</dl>
<hr>
<a name="Term-Modification"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#OS" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Global-Variables" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Term-Modification-1"></a>
<h2 class="section">6.16 Term Modification</h2>
<a name="index-updating-terms"></a>
<p>It is sometimes useful to change the value of instantiated
variables. Although, this is against the spirit of logic programming, it
is sometimes useful. As in other Prolog systems, YAP has
several primitives that allow updating Prolog terms. Note that these
primitives are also backtrackable.
</p>
<p>The <code>setarg/3</code> primitive allows updating any argument of a Prolog
compound terms. The <code>mutable</code> family of predicates provides
<em>mutable variables</em>. They should be used instead of <code>setarg/3</code>,
as they allow the encapsulation of accesses to updatable
variables. Their implementation can also be more efficient for long
deterministic computations.
</p>
<dl compact="compact">
<dt><code>setarg(+<var>I</var>,+<var>S</var>,?<var>T</var>)</code></dt>
<dd><a name="index-setarg_002f3n"></a>
<a name="index-setarg_002f3n-1"></a>
<a name="index-setarg_002f3n-2"></a>
<p>Set the value of the <var>I</var>th argument of term <var>S</var> to term <var>T</var>.
</p>
<a name="index-mutable-variables"></a>
</dd>
<dt><code>create_mutable(+<var>D</var>,-<var>M</var>)</code></dt>
<dd><a name="index-create_005fmutable_002f2"></a>
<a name="index-create_005fmutable_002f2-1"></a>
<a name="index-create_005fmutable_002f2-2"></a>
<p>Create new mutable variable <var>M</var> with initial value <var>D</var>.
</p>
</dd>
<dt><code>get_mutable(?<var>D</var>,+<var>M</var>)</code></dt>
<dd><a name="index-get_005fmutable_002f2"></a>
<a name="index-get_005fmutable_002f2-1"></a>
<a name="index-get_005fmutable_002f2-2"></a>
<p>Unify the current value of mutable term <var>M</var> with term <var>D</var>.
</p>
</dd>
<dt><code>is_mutable(?<var>D</var>)</code></dt>
<dd><a name="index-is_005fmutable_002f1"></a>
<a name="index-is_005fmutable_002f1-1"></a>
<a name="index-is_005fmutable_002f1-2"></a>
<p>Holds if <var>D</var> is a mutable term.
</p>
</dd>
<dt><code>get_mutable(?<var>D</var>,+<var>M</var>)</code></dt>
<dd><a name="index-get_005fmutable_002f2-3"></a>
<a name="index-get_005fmutable_002f2-4"></a>
<a name="index-get_005fmutable_002f2-5"></a>
<p>Unify the current value of mutable term <var>M</var> with term <var>D</var>.
</p>
</dd>
<dt><code>update_mutable(+<var>D</var>,+<var>M</var>)</code></dt>
<dd><a name="index-update_005fmutable_002f2"></a>
<a name="index-update_005fmutable_002f2-1"></a>
<a name="index-update_005fmutable_002f2-2"></a>
<p>Set the current value of mutable term <var>M</var> to term <var>D</var>.
</p></dd>
</dl>
<hr>
<a name="Global-Variables"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Term-Modification" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Profiling" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Global-Variables-1"></a>
<h2 class="section">6.17 Global Variables</h2>
<a name="index-global-variables"></a>
<p>Global variables are associations between names (atoms) and
terms. They differ in various ways from storing information using
<code>assert/1</code> or <code>recorda/3</code>.
</p>
<ul>
<li> The value lives on the Prolog (global) stack. This implies that
lookup time is independent from the size of the term. This is
particularly interesting for large data structures such as parsed XML
documents or the CHR global constraint store.
</li><li> They support both global assignment using <code>nb_setval/2</code> and
backtrackable assignment using <code>b_setval/2</code>.
</li><li> Only one value (which can be an arbitrary complex Prolog term)
can be associated to a variable at a time.
</li><li> Their value cannot be shared among threads. Each thread has its own
namespace and values for global variables.
</li></ul>
<p>Currently global variables are scoped globally. We may consider module
scoping in future versions. Both <code>b_setval/2</code> and
<code>nb_setval/2</code> implicitly create a variable if the referenced name
does not already refer to a variable.
</p>
<p>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
<code>initialization/1</code> to recreate them after loading the saved
state. Each thread has its own set of global variables, starting with
an empty set. Using <code>thread_initialization/1</code> 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. Finally, global variables can be initialised using the
exception hook called <code>exception/3</code>. The latter technique is used
by CHR.
</p>
<dl compact="compact">
<dt><code>b_setval(+<var>Name</var>, +<var>Value</var>)</code></dt>
<dd><a name="index-b_005fsetval_002f2"></a>
<a name="index-b_005fsetval_002f2-1"></a>
<a name="index-b_005fsetval_002f2-2"></a>
<p>Associate the term <var>Value</var> with the atom <var>Name</var> or replaces
the currently associated value with <var>Value</var>. If <var>Name</var> does
not refer to an existing global variable a variable with initial value
[] is created (the empty list). On backtracking the assignment is
reversed.
</p>
</dd>
<dt><code>b_getval(+<var>Name</var>, -<var>Value</var>)</code></dt>
<dd><a name="index-b_005fgetval_002f2"></a>
<a name="index-b_005fgetval_002f2-1"></a>
<a name="index-b_005fgetval_002f2-2"></a>
<p>Get the value associated with the global variable <var>Name</var> and unify
it with <var>Value</var>. Note that this unification may further
instantiate the value of the global variable. If this is undesirable
the normal precautions (double negation or <code>copy_term/2</code>) must be
taken. The <code>b_getval/2</code> predicate generates errors if <var>Name</var> is not
an atom or the requested variable does not exist.
</p>
<p>Notice that for compatibility with other systems <var>Name</var> <em>must</em> be already associated with a term: otherwise the system will generate an error.
</p>
</dd>
<dt><code>nb_setval(+<var>Name</var>, +<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fsetval_002f2"></a>
<a name="index-nb_005fsetval_002f2-1"></a>
<a name="index-nb_005fsetval_002f2-2"></a>
<p>Associates a copy of <var>Value</var> created with <code>duplicate_term/2</code> with
the atom <var>Name</var>. Note that this can be used to set an initial
value other than <code>[]</code> prior to backtrackable assignment.
</p>
</dd>
<dt><code>nb_getval(+<var>Name</var>, -<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fgetval_002f2"></a>
<a name="index-nb_005fgetval_002f2-1"></a>
<a name="index-nb_005fgetval_002f2-2"></a>
<p>The <code>nb_getval/2</code> predicate is a synonym for <code>b_getval/2</code>,
introduced for compatibility and symmetry. As most scenarios will use
a particular global variable either using non-backtrackable or
backtrackable assignment, using <code>nb_getval/2</code> can be used to
document that the variable is used non-backtrackable.
</p>
</dd>
<dt><code>nb_linkval(+<var>Name</var>, +<var>Value</var>)</code></dt>
<dd><a name="index-nb_005flinkval_002f2"></a>
<a name="index-nb_005flinkval_002f2-1"></a>
<a name="index-nb_005flinkval_002f2-2"></a>
<p>Associates the term <var>Value</var> with the atom <var>Name</var> without
copying it. This is a fast special-purpose variation of <code>nb_setval/2</code>
intended for expert users only because the semantics on backtracking
to a point before creating the link are poorly defined for compound
terms. The principal term is always left untouched, but backtracking
behaviour on arguments is undone if the original assignment was
trailed and left alone otherwise, which implies that the history that
created the term affects the behaviour on backtracking. Please
consider the following example:
</p>
<div class="example">
<pre class="example">demo_nb_linkval :-
T = nice(N),
( N = world,
nb_linkval(myvar, T),
fail
; nb_getval(myvar, V),
writeln(V)
).
</pre></div>
</dd>
<dt><code>nb_set_shared_val(+<var>Name</var>, +<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fset_005fshared_005fval_002f2"></a>
<a name="index-nb_005fset_005fshared_005fval_002f2-1"></a>
<a name="index-nb_005fset_005fshared_005fval_002f2-2"></a>
<p>Associates the term <var>Value</var> with the atom <var>Name</var>, but sharing
non-backtrackable terms. This may be useful if you want to rewrite a
global variable so that the new copy will survive backtracking, but
you want to share structure with the previous term.
</p>
<p>The next example shows the differences between the three built-ins:
</p><div class="example">
<pre class="example">?- nb_setval(a,a(_)),nb_getval(a,A),nb_setval(b,t(C,A)),nb_getval(b,B).
A = a(_A),
B = t(_B,a(_C)) ?
?- nb_setval(a,a(_)),nb_getval(a,A),nb_set_shared_val(b,t(C,A)),nb_getval(b,B).
?- nb_setval(a,a(_)),nb_getval(a,A),nb_linkval(b,t(C,A)),nb_getval(b,B).
A = a(_A),
B = t(C,a(_A)) ?
</pre></div>
</dd>
<dt><code>nb_setarg(+{Arg], +<var>Term</var>, +<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fsetarg_002f3"></a>
<a name="index-nb_005fsetarg_002f3-1"></a>
<a name="index-nb_005fsetarg_002f3-2"></a>
<p>Assigns the <var>Arg</var>-th argument of the compound term <var>Term</var> with
the given <var>Value</var> as setarg/3, but on backtracking the assignment
is not reversed. If <var>Term</var> is not atomic, it is duplicated using
duplicate_term/2. This predicate uses the same technique as
<code>nb_setval/2</code>. We therefore refer to the description of
<code>nb_setval/2</code> for details on non-backtrackable assignment of
terms. This predicate is compatible to GNU-Prolog
<code>setarg(A,T,V,false)</code>, removing the type-restriction on
<var>Value</var>. See also <code>nb_linkarg/3</code>. Below is an example for
counting the number of solutions of a goal. Note that this
implementation is thread-safe, reentrant and capable of handling
exceptions. Realising these features with a traditional implementation
based on assert/retract or flag/3 is much more complicated.
</p>
<div class="example">
<pre class="example"> succeeds_n_times(Goal, Times) :-
Counter = counter(0),
( Goal,
arg(1, Counter, N0),
N is N0 + 1,
nb_setarg(1, Counter, N),
fail
; arg(1, Counter, Times)
).
</pre></div>
</dd>
<dt><code>nb_set_shared_arg(+<var>Arg</var>, +<var>Term</var>, +<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fset_005fshared_005farg_002f3"></a>
<a name="index-nb_005fset_005fshared_005farg_002f3-1"></a>
<a name="index-nb_005fset_005fshared_005farg_002f3-2"></a>
<p>As <code>nb_setarg/3</code>, but like <code>nb_linkval/2</code> it does not
duplicate the global sub-terms in <var>Value</var>. Use with extreme care
and consult the documentation of <code>nb_linkval/2</code> before use.
</p>
</dd>
<dt><code>nb_linkarg(+<var>Arg</var>, +<var>Term</var>, +<var>Value</var>)</code></dt>
<dd><a name="index-nb_005flinkarg_002f3"></a>
<a name="index-nb_005flnkarg_002f3"></a>
<a name="index-nb_005flinkarg_002f3-1"></a>
<p>As <code>nb_setarg/3</code>, but like <code>nb_linkval/2</code> it does not
duplicate <var>Value</var>. Use with extreme care and consult the
documentation of <code>nb_linkval/2</code> before use.
</p>
</dd>
<dt><code>nb_current(?<var>Name</var>, ?<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fcurrent_002f2"></a>
<a name="index-nb_005fcurrent_002f2-1"></a>
<a name="index-nb_005fcurrent_002f2-2"></a>
<p>Enumerate all defined variables with their value. The order of
enumeration is undefined.
</p>
</dd>
<dt><code>nb_delete(+<var>Name</var>)</code></dt>
<dd><a name="index-nb_005fdelete_002f2"></a>
<a name="index-nb_005fdelete_002f2-1"></a>
<a name="index-nb_005fdelete_002f2-2"></a>
<p>Delete the named global variable.
</p></dd>
</dl>
<p>Global variables have been introduced by various Prolog
implementations recently. We follow the implementation of them in
SWI-Prolog, itself based on hProlog by Bart Demoen.
</p>
<p>GNU-Prolog provides a rich set of global variables, including
arrays. Arrays can be implemented easily in YAP and SWI-Prolog using
<code>functor/3</code> and <code>setarg/3</code> due to the unrestricted arity of
compound terms.
</p>
<hr>
<a name="Profiling"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Global-Variables" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-Count-Profiler" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Profiling-Prolog-Programs"></a>
<h2 class="section">6.18 Profiling Prolog Programs</h2>
<a name="index-profiling"></a>
<p>YAP includes two profilers. The count profiler keeps information on the
number of times a predicate was called. This information can be used to
detect what are the most commonly called predicates in the program. The
count profiler can be compiled by setting YAP&rsquo;s flag <code>profiling</code>
to <code>on</code>. The time-profiler is a <code>gprof</code> profiler, and counts
how many ticks are being spent on specific predicates, or on other
system functions such as internal data-base accesses or garbage collects.
</p>
<p>The YAP profiling sub-system is currently under
development. Functionality for this sub-system will increase with newer
implementation.
</p>
<hr>
<a name="The-Count-Profiler"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Profiling" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Profiling" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Tick-Profiler" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">6.18.1 The Count Profiler</h3>
<p><strong>Notes:</strong>
</p>
<p>The count profiler works by incrementing counters at procedure entry or
backtracking. It provides exact information:
</p>
<ul>
<li> Profiling works for both static and dynamic predicates.
</li><li> Currently only information on entries and retries to a predicate
are maintained. This may change in the future.
</li><li> As an example, the following user-level program gives a list of
the most often called procedures in a program. The procedure
<code>list_profile</code> shows all procedures, irrespective of module, and
the procedure <code>list_profile/1</code> shows the procedures being used in
a specific module.
<div class="example">
<pre class="example">list_profile :-
% get number of calls for each profiled procedure
setof(D-[M:P|D1],(current_module(M),profile_data(M:P,calls,D),profile_data(M:P,retries,D1)),LP),
% output so that the most often called
% predicates will come last:
write_profile_data(LP).
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,retries,D1)),LP),
% output so that the most often called
% predicates will come last:
write_profile_data(LP).
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).
</pre></div>
</li></ul>
<p>These are the current predicates to access and clear profiling data:
</p>
<dl compact="compact">
<dt><code>profile_data(?<var>Na/Ar</var>, ?<var>Parameter</var>, -<var>Data</var>)</code></dt>
<dd><a name="index-profile_005fdata_002f3"></a>
<a name="index-profile_005fdata_002f3-1"></a>
<a name="index-profile_005fdata_002f3-2"></a>
<p>Give current profile data on <var>Parameter</var> for a predicate described
by the predicate indicator <var>Na/Ar</var>. If any of <var>Na/Ar</var> or
<var>Parameter</var> are unbound, backtrack through all profiled predicates
or stored parameters. Current parameters are:
</p>
<dl compact="compact">
<dt><code>calls</code></dt>
<dd><p>Number of times a procedure was called.
</p>
</dd>
<dt><code>retries</code></dt>
<dd><p> Number of times a call to the procedure was backtracked to and retried.
</p></dd>
</dl>
</dd>
<dt><code>profile_reset</code></dt>
<dd><a name="index-profiled_005freset_002f0"></a>
<a name="index-profiled_005freset_002f0-1"></a>
<a name="index-profiled_005freset_002f0-2"></a>
<p>Reset all profiling information.
</p>
</dd>
</dl>
<hr>
<a name="Tick-Profiler"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-Count-Profiler" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Profiling" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Call-Counting" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">6.18.2 Tick Profiler</h3>
<p>The tick profiler works by interrupting the Prolog code every so often
and checking at each point the code was. The profiler must be able to
retrace the state of the abstract machine at every moment. The major
advantage of this approach is that it gives the actual amount of time
being spent per procedure, or whether garbage collection dominates
execution time. The major drawback is that tracking down the state of
the abstract machine may take significant time, and in the worst case
may slow down the whole execution.
</p>
<p>The following procedures are available:
</p>
<dl compact="compact">
<dt><code>profinit</code></dt>
<dd><a name="index-profinit_002f0"></a>
<a name="index-profinit_002f0-1"></a>
<a name="index-profinit_002f0-2"></a>
<p>Initialise the data-structures for the profiler. Unnecessary for
dynamic profiler.
</p>
</dd>
<dt><code>profon</code></dt>
<dd><a name="index-profon_002f0"></a>
<a name="index-profon_002f0-1"></a>
<a name="index-profon_002f0-2"></a>
<p>Start profiling.
</p>
</dd>
<dt><code>profoff</code></dt>
<dd><a name="index-profoff_002f0"></a>
<a name="index-profoff_002f0-1"></a>
<a name="index-profoff_002f0-2"></a>
<p>Stop profiling.
</p>
</dd>
<dt><code>showprofres</code></dt>
<dd><a name="index-showprofres_002f0"></a>
<a name="index-showprofres_002f0-1"></a>
<a name="index-showprofres_002f0-2"></a>
<p>Show profiling info.
</p>
</dd>
<dt><code>showprofres(<var>N</var>)</code></dt>
<dd><a name="index-showprofres_002f1"></a>
<a name="index-showprofres_002f1-1"></a>
<a name="index-showprofres_002f1-2"></a>
<p>Show profiling info for the top-most <var>N</var> predicates.
</p>
</dd>
</dl>
<hr>
<a name="Call-Counting"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tick-Profiler" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Arrays" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Counting-Calls"></a>
<h2 class="section">6.19 Counting Calls</h2>
<a name="index-Counting-Calls"></a>
<p>Predicates compiled with YAP&rsquo;s flag <code>call_counting</code> set to
<code>on</code> update counters on the numbers of calls and of
retries. Counters are actually decreasing counters, so that they can be
used as timers. Three counters are available:
</p><ul>
<li> <code>calls</code>: number of predicate calls since execution started or since
system was reset;
</li><li> <code>retries</code>: number of retries for predicates called since
execution started or since counters were reset;
</li><li> <code>calls_and_retries</code>: count both on predicate calls and
retries.
</li></ul>
<p>These counters can be used to find out how many calls a certain
goal takes to execute. They can also be used as timers.
</p>
<p>The code for the call counters piggybacks on the profiling
code. Therefore, activating the call counters also activates the profiling
counters.
</p>
<p>These are the predicates that access and manipulate the call counters:
</p>
<dl compact="compact">
<dt><code>call_count_data(-<var>Calls</var>, -<var>Retries</var>, -<var>CallsAndRetries</var>)</code></dt>
<dd><a name="index-call_005fcount_005fdata_002f3"></a>
<a name="index-call_005fcount_005fdata_002f3-1"></a>
<a name="index-call_005fcount_005fdata_002f3-2"></a>
<p>Give current call count data. The first argument gives the current value
for the <var>Calls</var> counter, next the <var>Retries</var> counter, and last
the <var>CallsAndRetries</var> counter.
</p>
</dd>
<dt><code>call_count_reset</code></dt>
<dd><a name="index-call_005fcount_005fdata_002f0"></a>
<a name="index-call_005fcount_005fdata_002f0-1"></a>
<a name="index-call_005fcount_005fdata_002f0-2"></a>
<p>Reset call count counters. All timers are also reset.
</p>
</dd>
<dt><code>call_count(?<var>CallsMax</var>, ?<var>RetriesMax</var>, ?<var>CallsAndRetriesMax</var>)</code></dt>
<dd><a name="index-call_005fcount_005fdata_002f3-3"></a>
<a name="index-call_005fcount_005fdata_002f3-4"></a>
<a name="index-call_005fcount_005fdata_002f3-5"></a>
<p>Set call count counter as timers. YAP will generate an exception
if one of the instantiated call counters decreases to 0. YAP will ignore
unbound arguments:
</p><ul>
<li> <var>CallsMax</var>: throw the exception <code>call_counter</code> when the
counter <code>calls</code> reaches 0;
</li><li> <var>RetriesMax</var>: throw the exception <code>retry_counter</code> when the
counter <code>retries</code> reaches 0;
</li><li> <var>CallsAndRetriesMax</var>: throw the exception
<code>call_and_retry_counter</code> when the counter <code>calls_and_retries</code>
reaches 0.
</li></ul>
</dd>
</dl>
<p>Next, we show a simple example of how to use call counters:
</p><div class="example">
<pre class="example"> ?- yap_flag(call_counting,on), [-user]. l :- l. end_of_file. yap_flag(call_counting,off).
yes
yes
?- catch((call_count(10000,_,_),l),call_counter,format(&quot;limit_exceeded.~n&quot;,[])).
limit_exceeded.
yes
</pre></div>
<p>Notice that we first compile the looping predicate <code>l/0</code> with
<code>call_counting</code> <code>on</code>. Next, we <code>catch/3</code> to handle an
exception when <code>l/0</code> performs more than 10000 reductions.
</p>
<hr>
<a name="Arrays"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Call-Counting" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Preds" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Arrays-1"></a>
<h2 class="section">6.20 Arrays</h2>
<p>The YAP system includes experimental support for arrays. The
support is enabled with the option <code>YAP_ARRAYS</code>.
</p>
<p>There are two very distinct forms of arrays in YAP. The
<em>dynamic arrays</em> are a different 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 alternative to the standard <code>arg/3</code>
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
</p><div class="example">
<pre class="example">g(X) :- array_element(a,2,X).
</pre></div>
<p>will succeed as long as the programmer has used the built-in <tt>array/2</tt>
to create an array term with at least 3 elements in the current
environment, and the array was associated with the name <code>a</code>. The
element <code>X</code> 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.
</p>
<p>The <em>static arrays</em> 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.
</p>
<p>In order to efficiently manage space elements in a static array must
have a type. Currently, elements of static arrays in YAP should
have one of the following predefined types:
</p>
<ul>
<li> <code>byte</code>: an 8-bit signed character.
</li><li> <code>unsigned_byte</code>: an 8-bit unsigned character.
</li><li> <code>int</code>: Prolog integers. Size would be the natural size for
the machine&rsquo;s architecture.
</li><li> <code>float</code>: Prolog floating point number. Size would be equivalent
to a double in <code>C</code>.
</li><li> <code>atom</code>: a Prolog atom.
</li><li> <code>dbref</code>: an internal database reference.
</li><li> <code>term</code>: a generic Prolog term. Note that this will term will
not be stored in the array itself, but instead will be stored in the
Prolog internal database.
</li></ul>
<p>Arrays may be <em>named</em> or <em>anonymous</em>. Most arrays will be
<em>named</em>, that is associated with an atom that will be used to find
the array. Anonymous arrays do not have a name, and they are only of
interest if the <code>TERM_EXTENSIONS</code> compilation flag is enabled. In
this case, the unification and parser are extended to replace
occurrences of Prolog terms of the form <code>X[I]</code> by run-time calls to
<code>array_element/3</code>, so that one can use array references instead of
extra calls to <code>arg/3</code>. As an example:
</p><div class="example">
<pre class="example">g(X,Y,Z,I,J) :- X[I] is Y[J]+Z[I].
</pre></div>
<p>should give the same results as:
</p><div class="example">
<pre class="example">G(X,Y,Z,I,J) :-
array_element(X,I,E1),
array_element(Y,J,E2),
array_element(Z,I,E3),
E1 is E2+E3.
</pre></div>
<p>Note that the only limitation on array size are the stack size for
dynamic arrays; and, the heap size for static (not memory mapped)
arrays. Memory mapped arrays are limited by available space in the file
system and in the virtual memory space.
</p>
<p>The following predicates manipulate arrays:
</p>
<dl compact="compact">
<dt><code>array(+<var>Name</var>, +<var>Size</var>)</code></dt>
<dd><a name="index-array_002f2"></a>
<a name="index-array_002f2-1"></a>
<a name="index-array_002f2-2"></a>
<p>Creates a new dynamic array. The <var>Size</var> must evaluate to an
integer. The <var>Name</var> may be either an atom (named array) or an
unbound variable (anonymous array).
</p>
<p>Dynamic arrays work as standard compound terms, hence space for the
array is recovered automatically on backtracking.
</p>
</dd>
<dt><code>static_array(+<var>Name</var>, +<var>Size</var>, +<var>Type</var>)</code></dt>
<dd><a name="index-static_005farray_002f3"></a>
<a name="index-static_005farray_002f3-1"></a>
<a name="index-static_005farray_002f3-2"></a>
<p>Create a new static array with name <var>Name</var>. Note that the <var>Name</var>
must be an atom (named array). The <var>Size</var> must evaluate to an
integer. The <var>Type</var> must be bound to one of types mentioned
previously.
</p>
</dd>
<dt><code>reset_static_array(+<var>Name</var>)</code></dt>
<dd><a name="index-reset_005fstatic_005farray_002f1"></a>
<a name="index-reset_005fstatic_005farray_002f1-1"></a>
<a name="index-reset_005fstatic_005farray_002f1-2"></a>
<p>Reset static array with name <var>Name</var> to its initial value.
</p>
</dd>
<dt><code>static_array_location(+<var>Name</var>, -<var>Ptr</var>)</code></dt>
<dd><a name="index-static_005farray_005flocation_002f4"></a>
<a name="index-static_005farray_005flocation_002f4-1"></a>
<a name="index-static_005farray_005flocation_002f4-2"></a>
<p>Give the location for a static array with name
<var>Name</var>.
</p>
</dd>
<dt><code>static_array_properties(?<var>Name</var>, ?<var>Size</var>, ?<var>Type</var>)</code></dt>
<dd><a name="index-static_005farray_005fproperties_002f3"></a>
<a name="index-static_005farray_005fproperties_002f3-1"></a>
<a name="index-static_005farray_005fproperties_002f3-2"></a>
<p>Show the properties size and type of a static array with name
<var>Name</var>. Can also be used to enumerate all current
static arrays.
</p>
<p>This built-in will silently fail if the there is no static array with
that name.
</p>
</dd>
<dt><code>static_array_to_term(?<var>Name</var>, ?<var>Term</var>)</code></dt>
<dd><a name="index-static_005farray_005fto_005fterm_002f3"></a>
<a name="index-static_005farray_005fto_005fterm_002f3-1"></a>
<a name="index-static_005farray_005fto_005fterm_002f3-2"></a>
<p>Convert a static array with name
<var>Name</var> to a compound term of name <var>Name</var>.
</p>
<p>This built-in will silently fail if the there is no static array with
that name.
</p>
</dd>
<dt><code>mmapped_array(+<var>Name</var>, +<var>Size</var>, +<var>Type</var>, +<var>File</var>)</code></dt>
<dd><a name="index-static_005farray_002f3-3"></a>
<a name="index-static_005farray_002f3-4"></a>
<a name="index-static_005farray_002f3-5"></a>
<p>Similar to <code>static_array/3</code>, but the array is memory mapped to file
<var>File</var>. This means that the array is initialized from the file, and
that any changes to the array will also be stored in the file.
</p>
<p>This built-in is only available in operating systems that support the
system call <code>mmap</code>. Moreover, mmapped arrays do not store generic
terms (type <code>term</code>).
</p>
</dd>
<dt><code>close_static_array(+<var>Name</var>)</code></dt>
<dd><a name="index-close_005fstatic_005farray_002f1"></a>
<a name="index-close_005fstatic_005farray_002f1-1"></a>
<a name="index-close_005fstatic_005farray_002f1-2"></a>
<p>Close an existing static array of name <var>Name</var>. The <var>Name</var> must
be an atom (named array). Space for the array will be recovered and
further accesses to the array will return an error.
</p>
</dd>
<dt><code>resize_static_array(+<var>Name</var>, -<var>OldSize</var>, +<var>NewSize</var>)</code></dt>
<dd><a name="index-resize_005fstatic_005farray_002f3"></a>
<a name="index-resize_005fstatic_005farray_002f3-1"></a>
<a name="index-resize_005fstatic_005farray_002f3-2"></a>
<p>Expand or reduce a static array, The <var>Size</var> must evaluate to an
integer. The <var>Name</var> must be an atom (named array). The <var>Type</var>
must be bound to one of <code>int</code>, <code>dbref</code>, <code>float</code> or
<code>atom</code>.
</p>
<p>Note that if the array is a mmapped array the size of the mmapped file
will be actually adjusted to correspond to the size of the array.
</p>
</dd>
<dt><code>array_element(+<var>Name</var>, +<var>Index</var>, ?<var>Element</var>)</code></dt>
<dd><a name="index-array_005felement_002f3"></a>
<a name="index-array_005felement_002f3-1"></a>
<a name="index-array_005felement_002f3-2"></a>
<p>Unify <var>Element</var> with <var>Name</var>[<var>Index</var>]. It works for both
static and dynamic arrays, but it is read-only for static arrays, while
it can be used to unify with an element of a dynamic array.
</p>
</dd>
<dt><code>update_array(+<var>Name</var>, +<var>Index</var>, ?<var>Value</var>)</code></dt>
<dd><a name="index-update_005farray_002f3"></a>
<a name="index-update_005farray_002f3-1"></a>
<a name="index-update_005farray_002f3-2"></a>
<p>Attribute value <var>Value</var> to <var>Name</var>[<var>Index</var>]. Type
restrictions must be respected for static arrays. This operation is
available for dynamic arrays if <code>MULTI_ASSIGNMENT_VARIABLES</code> is
enabled (true by default). Backtracking undoes <var>update_array/3</var> for
dynamic arrays, but not for static arrays.
</p>
<p>Note that <code>update_array/3</code> actually uses <code>setarg/3</code> to update
elements of dynamic arrays, and <code>setarg/3</code> spends an extra cell for
every update. For intensive operations we suggest it may be less
expensive to unify each element of the array with a mutable terms and
to use the operations on mutable terms.
</p>
</dd>
<dt><code>add_to_array_element(+<var>Name</var>, +<var>Index</var>, , +<var>Number</var>, ?<var>NewValue</var>)</code></dt>
<dd><a name="index-add_005fto_005farray_005felement_002f4"></a>
<a name="index-add_005fto_005farray_005felement_002f4-1"></a>
<a name="index-add_005fto_005farray_005felement_002f4-2"></a>
<p>Add <var>Number</var> <var>Name</var>[<var>Index</var>] and unify <var>NewValue</var> with
the incremented value. Observe that <var>Name</var>[<var>Index</var>] must be an
number. If <var>Name</var> is a static array the type of the array must be
<code>int</code> or <code>float</code>. If the type of the array is <code>int</code> you
only may add integers, if it is <code>float</code> you may add integers or
floats. If <var>Name</var> corresponds to a dynamic array the array element
must have been previously bound to a number and <code>Number</code> can be
any kind of number.
</p>
<p>The <code>add_to_array_element/3</code> built-in actually uses
<code>setarg/3</code> to update elements of dynamic arrays. For intensive
operations we suggest it may be less expensive to unify each element
of the array with a mutable terms and to use the operations on mutable
terms.
</p>
</dd>
</dl>
<hr>
<a name="Preds"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Arrays" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Misc" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Predicate-Information"></a>
<h2 class="section">6.21 Predicate Information</h2>
<p>Built-ins that return information on the current predicates and modules:
</p>
<dl compact="compact">
<dt><code>current_module(<var>M</var>)</code></dt>
<dd><a name="index-current_005fmodule_002f1"></a>
<a name="index-current_005fmodule_002f1-1"></a>
<a name="index-current_005fmodule_002f1-2"></a>
<p>Succeeds if <var>M</var> 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.
</p>
</dd>
<dt><code>current_module(<var>M</var>,<var>F</var>)</code></dt>
<dd><a name="index-current_005fmodule_002f2"></a>
<a name="index-current_005fmodule_002f2-1"></a>
<a name="index-current_005fmodule_002f2-2"></a>
<p>Succeeds if <var>M</var> are current modules associated to the file <var>F</var>.
</p>
</dd>
</dl>
<hr>
<a name="Misc"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Preds" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Built_002dins" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Miscellaneous"></a>
<h2 class="section">6.22 Miscellaneous</h2>
<dl compact="compact">
<dt><code>statistics/0</code></dt>
<dd><a name="index-statistics_002f0"></a>
<a name="index-statistics_002f0-1"></a>
<a name="index-statistics_002f0-2"></a>
<p>Send to the current user error stream general information on space used and time
spent by the system.
</p><div class="example">
<pre class="example">?- 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
0.010 sec. for 5 code, 2 stack, and 1 trail space overflows
0.130 sec. for 3 garbage collections which collected 421000 bytes
0.000 sec. for 0 atom garbage collections which collected 0 bytes
0.880 sec. runtime
1.020 sec. cputime
25.055 sec. elapsed time
</pre></div>
<p>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.
</p>
<p>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).
</p>
<p>YAP also shows information on how many memory overflows and garbage
collections the system executed, and statistics on total execution
time. Cputime includes all running time, runtime excludes garbage
collection and stack overflow time.
</p>
</dd>
<dt><code>statistics(?<var>Param</var>,-<var>Info</var>)</code></dt>
<dd><a name="index-statistics_002f2"></a>
<a name="index-statistics_002f2-1"></a>
<a name="index-statistics_002f2-2"></a>
<p>Gives statistical information on the system parameter given by first
argument:
</p>
<dl compact="compact">
<dt><code>atoms</code></dt>
<dd><a name="index-atoms-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>NumberOfAtoms</var>,<var>SpaceUsedBy Atoms</var>]</code>
<br>
This gives the total number of atoms <code>NumberOfAtoms</code> and how much
space they require in bytes, <var>SpaceUsedBy Atoms</var>.
</p>
</dd>
<dt><code>cputime</code></dt>
<dd><a name="index-cputime-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Time since Boot</var>,<var>Time From Last Call to Cputime</var>]</code>
<br>
This gives the total cputime in milliseconds spent executing Prolog code,
garbage collection and stack shifts time included.
</p>
</dd>
<dt><code>dynamic_code</code></dt>
<dd><a name="index-dynamic_005fcode-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Clause Size</var>,<var>Index Size</var>,<var>Tree Index
Size</var>,<var>Choice Point Instructions
Size</var>,<var>Expansion Nodes Size</var>,<var>Index Switch Size</var>]</code>
<br>
Size of static code in YAP in bytes: <var>Clause Size</var>, the number of
bytes allocated for clauses, plus
<var>Index Size</var>, the number of bytes spent in the indexing code. The
indexing code is divided into main tree, <var>Tree Index
Size</var>, tables that implement choice-point manipulation, <var>Choice Point Instructions
Size</var>, tables that cache clauses for future expansion of the index
tree, <var>Expansion Nodes Size</var>, and
tables such as hash tables that select according to value, <var>Index Switch Size</var>.
</p>
</dd>
<dt><code>garbage_collection</code></dt>
<dd><a name="index-garbage_005fcollection-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Number of GCs</var>,<var>Total Global Recovered</var>,<var>Total Time
Spent</var>]</code>
<br>
Number of garbage collections, amount of space recovered in kbytes, and
total time spent doing garbage collection in milliseconds. More detailed
information is available using <code>yap_flag(gc_trace,verbose)</code>.
</p>
</dd>
<dt><code>global_stack</code></dt>
<dd><a name="index-global_005fstack-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Global Stack Used</var>,<var>Execution Stack Free</var>]</code>
<br>
Space in kbytes currently used in the global stack, and space available for
expansion by the local and global stacks.
</p>
</dd>
<dt><code>local_stack</code></dt>
<dd><a name="index-local_005fstack-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Local Stack Used</var>,<var>Execution Stack Free</var>]</code>
<br>
Space in kbytes currently used in the local stack, and space available for
expansion by the local and global stacks.
</p>
</dd>
<dt><code>heap</code></dt>
<dd><a name="index-heap-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Heap Used</var>,<var>Heap Free</var>]</code>
<br>
Total space in kbytes not recoverable
in backtracking. It includes the program code, internal data base, and,
atom symbol table.
</p>
</dd>
<dt><code>program</code></dt>
<dd><a name="index-program-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Program Space Used</var>,<var>Program Space Free</var>]</code>
<br>
Equivalent to <code>heap</code>.
</p>
</dd>
<dt><code>runtime</code></dt>
<dd><a name="index-runtime-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Time since Boot</var>,<var>Time From Last Call to Runtime</var>]</code>
<br>
This gives the total cputime in milliseconds spent executing Prolog
code, not including garbage collections and stack shifts. Note that
until YAP4.1.2 the <code>runtime</code> statistics would return time spent on
garbage collection and stack shifting.
</p>
</dd>
<dt><code>stack_shifts</code></dt>
<dd><a name="index-stack_005fshifts-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Number of Heap Shifts</var>,<var>Number of Stack
Shifts</var>,<var>Number of Trail Shifts</var>]</code>
<br>
Number of times YAP had to
expand the heap, the stacks, or the trail. More detailed information is
available using <code>yap_flag(gc_trace,verbose)</code>.
</p>
</dd>
<dt><code>static_code</code></dt>
<dd><a name="index-static_005fcode-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Clause Size</var>,<var>Index Size</var>,<var>Tree Index
Size</var>,<var>Expansion Nodes Size</var>,<var>Index Switch Size</var>]</code>
<br>
Size of static code in YAP in bytes: <var>Clause Size</var>, the number of
bytes allocated for clauses, plus
<var>Index Size</var>, the number of bytes spent in the indexing code. The
indexing code is divided into a main tree, <var>Tree Index
Size</var>, table that cache clauses for future expansion of the index
tree, <var>Expansion Nodes Size</var>, and and
tables such as hash tables that select according to value, <var>Index Switch Size</var>.
</p>
</dd>
<dt><code>trail</code></dt>
<dd><a name="index-trail-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Trail Used</var>,<var>Trail Free</var>]</code>
<br>
Space in kbytes currently being used and still available for the trail.
</p>
</dd>
<dt><code>walltime</code></dt>
<dd><a name="index-walltime-_0028statistics_002f2-option_0029"></a>
<p><code>[<var>Time since Boot</var>,<var>Time From Last Call to Walltime</var>]</code>
<br>
This gives the clock time in milliseconds since starting Prolog.
</p>
</dd>
</dl>
</dd>
<dt><code>time(:<var>Goal</var>)</code></dt>
<dd><a name="index-time_002f1"></a>
<a name="index-time_002f1-1"></a>
<a name="index-time_002f1-2"></a>
<p>Prints the CPU time and the wall time for the execution of <var>Goal</var>.
Possible choice-points of <var>Goal</var> are removed. Based on the SWI-Prolog
definition (minus reporting the number of inferences, which YAP currently
does not support).
</p>
</dd>
<dt><code>yap_flag(?<var>Param</var>,?<var>Value</var>)</code></dt>
<dd><a name="index-yap_005fflag_002f2"></a>
<a name="index-yap_005fflag_002f2-1"></a>
<a name="index-yap_005fflag_002f2-2"></a>
<p>Set or read system properties for <var>Param</var>:
</p>
<dl compact="compact">
<dt><code>argv</code></dt>
<dd><a name="index-argv-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Read-only flag. It unifies with a list of atoms that gives the
arguments to YAP after <code>--</code>.
</p>
</dd>
<dt><code>agc_margin</code></dt>
<dd><a name="index-agc_005fmargin-_0028yap_005fflag_002f2-option_0029"></a>
<p>An integer: if this amount of atoms has been created since the last
atom-garbage collection, perform atom garbage collection at the first
opportunity. Initial value is 10,000. May be changed. A value of 0
(zero) disables atom garbage collection.
</p>
</dd>
<dt><code>bounded [ISO]</code></dt>
<dd><a name="index-bounded-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Read-only flag telling whether integers are bounded. The value depends
on whether YAP uses the GMP library or not.
</p>
</dd>
<dt><code>profiling</code></dt>
<dd><a name="index-call_005fcounting-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>off</code> (default) do not compile call counting information for
procedures. If <code>on</code> compile predicates so that they calls and
retries to the predicate may be counted. Profiling data can be read through the
<code>call_count_data/3</code> built-in.
</p>
</dd>
<dt><code>char_conversion [ISO]</code></dt>
<dd><a name="index-char_005fconversion-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Writable flag telling whether a character conversion table is used when
reading terms. The default value for this flag is <code>off</code> except in
<code>sicstus</code> and <code>iso</code> language modes, where it is <code>on</code>.
</p>
</dd>
<dt><code>character_escapes [ISO]</code></dt>
<dd><a name="index-character_005fescapes-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Writable flag telling whether a character escapes are enables,
<code>on</code>, or disabled, <code>off</code>. The default value for this flag is
<code>on</code>.
</p>
</dd>
<dt><code>debug [ISO]</code></dt>
<dd><a name="index-debug-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <var>Value</var> is unbound, tell whether debugging is <code>on</code> or
<code>off</code>. If <var>Value</var> is bound to <code>on</code> enable debugging, and if
it is bound to <code>off</code> disable debugging.
</p>
<p>+</p></dd>
<dt><code>debugger_print_options</code></dt>
<dd><a name="index-debugger_005fprint_005foptions-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If bound, set the argument to the <code>write_term/3</code> options the
debugger uses to write terms. If unbound, show the current options.
</p>
</dd>
<dt><code>dialect</code></dt>
<dd><a name="index-dialect-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Read-only flag that always returns <code>yap</code>.
</p>
</dd>
<dt><code>discontiguous_warnings</code></dt>
<dd><a name="index-discontiguous_005fwarnings-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <var>Value</var> is unbound, tell whether warnings for discontiguous
predicates are <code>on</code> or
<code>off</code>. If <var>Value</var> is bound to <code>on</code> enable these warnings,
and if it is bound to <code>off</code> disable them. The default for YAP is
<code>off</code>, unless we are in <code>sicstus</code> or <code>iso</code> mode.
</p>
</dd>
<dt><code>dollar_as_lower_case</code></dt>
<dd><a name="index-dollar_005fas_005flower_005fcase-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>off</code> (default) consider the character &rsquo;$&rsquo; a control character, if
<code>on</code> consider &rsquo;$&rsquo; a lower case character.
</p>
</dd>
<dt><code>double_quotes [ISO]</code></dt>
<dd><a name="index-double_005fquotes-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <var>Value</var> is unbound, tell whether a double quoted list of characters
token is converted to a list of atoms, <code>chars</code>, to a list of integers,
<code>codes</code>, or to a single atom, <code>atom</code>. If <var>Value</var> is bound, set to
the corresponding behavior. The default value is <code>codes</code>.
</p>
</dd>
<dt><code>executable</code></dt>
<dd><a name="index-executable_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Read-only flag. It unifies with an atom that gives the
original program path.
</p>
</dd>
<dt><code>fast</code></dt>
<dd><a name="index-fast-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>on</code> allow fast machine code, if <code>off</code> (default) disable it. Only
available in experimental implementations.
</p>
</dd>
<dt><code>fileerrors</code></dt>
<dd><a name="index-fileerrors-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>on</code> <code>fileerrors</code> is <code>on</code>, if <code>off</code> (default)
<code>fileerrors</code> is disabled.
</p>
</dd>
<dt><code>float_format</code></dt>
<dd><a name="index-float_005fformat-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> C-library <code>printf()</code> format specification used by <code>write/1</code> and
friends to determine how floating point numbers are printed. The
default is <code>%.15g</code>. The specified value is passed to <code>printf()</code>
without further checking. For example, if you want less digits
printed, <code>%g</code> will print all floats using 6 digits instead of the
default 15.
</p>
</dd>
<dt><code>gc</code></dt>
<dd><a name="index-gc-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>on</code> allow garbage collection (default), if <code>off</code> disable it.
</p>
</dd>
<dt><code>gc_margin</code></dt>
<dd><a name="index-gc_005fmargin-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Set or show the minimum free stack before starting garbage
collection. The default depends on total stack size.
</p>
</dd>
<dt><code>gc_trace</code></dt>
<dd><a name="index-gc_005ftrace-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> If <code>off</code> (default) do not show information on garbage collection
and stack shifts, if <code>on</code> inform when a garbage collection or stack
shift happened, if <code>verbose</code> give detailed information on garbage
collection and stack shifts. Last, if <code>very_verbose</code> give detailed
information on data-structures found during the garbage collection
process, namely, on choice-points.
</p>
</dd>
<dt><code>generate_debugging_info</code></dt>
<dd><a name="index-generate_005fdebugging_005finfo-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> If <code>true</code> (default) generate debugging information for
procedures, including source mode. If <code>false</code> predicates no
information is generated, although debugging is still possible, and
source mode is disabled.
</p>
</dd>
<dt><code>host_type</code></dt>
<dd><a name="index-host_005ftype-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Return <code>configure</code> system information, including the machine-id
for which YAP was compiled and Operating System information.
</p>
</dd>
<dt><code>index</code></dt>
<dd><a name="index-index-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>on</code> allow indexing (default), if <code>off</code> disable it.
</p>
</dd>
<dt><code>informational_messages</code></dt>
<dd><a name="index-informational_005fmessages-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>on</code> allow printing of informational messages, such as the ones
that are printed when consulting. If <code>off</code> disable printing
these messages. It is <code>on</code> by default except if YAP is booted with
the <code>-L</code> flag.
</p>
</dd>
<dt><code>integer_rounding_function [ISO]</code></dt>
<dd><a name="index-integer_005frounding_005ffunction-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Read-only flag telling the rounding function used for integers. Takes the value
<code>down</code> for the current version of YAP.
</p>
</dd>
<dt><code>language</code></dt>
<dd><a name="index-language-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Choose whether YAP is closer to C-Prolog, <code>cprolog</code>, iso-prolog,
<code>iso</code> or SICStus Prolog, <code>sicstus</code>. The current default is
<code>cprolog</code>. This flag affects update semantics, leashing mode,
style checking, handling calls to undefined procedures, how directives
are interpreted, when to use dynamic, character escapes, and how files
are consulted.
</p>
</dd>
<dt><code>max_arity [ISO]</code></dt>
<dd><a name="index-max_005farity-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Read-only flag telling the maximum arity of a functor. Takes the value
<code>unbounded</code> for the current version of YAP.
</p>
</dd>
<dt><code>max_integer [ISO]</code></dt>
<dd><a name="index-max_005finteger-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Read-only flag telling the maximum integer in the
implementation. Depends on machine and Operating System
architecture, and on whether YAP uses the <code>GMP</code> multi-precision
library. If <code>bounded</code> is false, requests for <code>max_integer</code>
will fail.
</p>
</dd>
<dt><code>max_tagged_integer</code></dt>
<dd><a name="index-max_005ftagged_005finteger-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Read-only flag telling the maximum integer we can store as a single
word. Depends on machine and Operating System
architecture. It can be used to find the word size of the current machine.
</p>
</dd>
<dt><code>min_integer [ISO]</code></dt>
<dd><a name="index-min_005finteger-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Read-only flag telling the minimum integer in the
implementation. Depends on machine and Operating System architecture,
and on whether YAP uses the <code>GMP</code> multi-precision library. If
<code>bounded</code> is false, requests for <code>min_integer</code> will fail.
</p>
</dd>
<dt><code>min_tagged_integer</code></dt>
<dd><a name="index-max_005ftagged_005finteger-_0028yap_005fflag_002f2-option_0029-1"></a>
<br>
<p>Read-only flag telling the minimum integer we can store as a single
word. Depends on machine and Operating System
architecture.
</p>
</dd>
<dt><code>n_of_integer_keys_in_bb</code></dt>
<dd><a name="index-n_005fof_005finteger_005fkeys_005fin_005fbb-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Read or set the size of the hash table that is used for looking up the
blackboard when the key is an integer.
</p>
</dd>
<dt><code>n_of_integer_keys_in_db</code></dt>
<dd><a name="index-n_005fof_005finteger_005fkeys_005fin_005fdb-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>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.
</p>
</dd>
<dt><code>open_expands_filename</code></dt>
<dd><a name="index-open_005fexpands_005ffilename-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>true</code> the <code>open/3</code> builtin performs filename-expansion
before opening a file (SICStus Prolog like). If <code>false</code> it does not
(SWI-Prolog like).
</p>
</dd>
<dt><code>open_shared_object</code></dt>
<dd><a name="index-open_005fshared_005fobject-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If true, <code>open_shared_object/2</code> and friends are implemented,
providing access to shared libraries (<code>.so</code> files) or to dynamic link
libraries (<code>.DLL</code> files).
</p>
</dd>
<dt><code>profiling</code></dt>
<dd><a name="index-profiling-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>off</code> (default) do not compile profiling information for
procedures. If <code>on</code> compile predicates so that they will output
profiling information. Profiling data can be read through the
<code>profile_data/3</code> built-in.
</p>
</dd>
<dt><code>prompt_alternatives_on(atom, changeable)</code></dt>
<dd><a name="index-prompt_005falternatives_005fon--_0028yap_005fflag_002f2-option_0029"></a>
<p>SWI-Compatible option, determines prompting for alternatives in the Prolog toplevel. Default is <tt>groundness</tt>, YAP prompts for alternatives if and only if the query contains variables. The alternative, default in SWI-Prolog is <tt>determinism</tt> which implies the system prompts for alternatives if the goal succeeded while leaving choicepoints.
</p>
</dd>
<dt><code>redefine_warnings</code></dt>
<dd><a name="index-discontiguous_005fwarnings-_0028yap_005fflag_002f2-option_0029-1"></a>
<br>
<p>If <var>Value</var> is unbound, tell whether warnings for procedures defined
in several different files are <code>on</code> or
<code>off</code>. If <var>Value</var> is bound to <code>on</code> enable these warnings,
and if it is bound to <code>off</code> disable them. The default for YAP is
<code>off</code>, unless we are in <code>sicstus</code> or <code>iso</code> mode.
</p>
</dd>
<dt><code>shared_object_search_path</code></dt>
<dd><a name="index-shared_005fobject_005fsearch_005fpath-_0028yap_005fflag_002f2-option_0029"></a>
<p>Name of the environment variable used by the system to search for shared
objects.
</p>
</dd>
<dt><code>single_var_warnings</code></dt>
<dd><a name="index-single_005fvar_005fwarnings-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <var>Value</var> is unbound, tell whether warnings for singleton variables
are <code>on</code> or <code>off</code>. If <var>Value</var> is bound to <code>on</code> enable
these warnings, and if it is bound to <code>off</code> disable them. The
default for YAP is <code>off</code>, unless we are in <code>sicstus</code> or
<code>iso</code> mode.
</p>
</dd>
<dt><code>strict_iso</code></dt>
<dd><a name="index-strict_005fiso-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p> If <var>Value</var> is unbound, tell whether strict ISO compatibility mode
is <code>on</code> or <code>off</code>. If <var>Value</var> is bound to <code>on</code> set
language mode to <code>iso</code> and enable strict mode. If <var>Value</var> is
bound to <code>off</code> disable strict mode, and keep the current language
mode. The default for YAP is <code>off</code>.
</p>
<p>Under strict ISO Prolog mode all calls to non-ISO built-ins generate an
error. Compilation of clauses that would call non-ISO built-ins will
also generate errors. Pre-processing for grammar rules is also
disabled. Module expansion is still performed.
</p>
<p>Arguably, ISO Prolog does not provide all the functionality required
from a modern Prolog system. Moreover, because most Prolog
implementations do not fully implement the standard and because the
standard itself gives the implementor latitude in a few important
questions, such as the unification algorithm and maximum size for
numbers there is no guarantee that programs compliant with this mode
will work the same way in every Prolog and in every platform. We thus
believe this mode is mostly useful when investigating how a program
depends on a Prolog&rsquo;s platform specific features.
</p>
</dd>
<dt><code>stack_dump_on_error</code></dt>
<dd><a name="index-stack_005fdump_005fon_005ferror-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>on</code> show a stack dump when YAP finds an error. The default is
<code>off</code>.
</p>
</dd>
<dt><code>syntax_errors</code></dt>
<dd><a name="index-syntax_005ferrors-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Control action to be taken after syntax errors while executing <code>read/1</code>,
<code>read/2</code>, or <code>read_term/3</code>:
</p><dl compact="compact">
<dt><code>dec10</code></dt>
<dd><br>
<p>Report the syntax error and retry reading the term.
</p>
</dd>
<dt><code>fail</code></dt>
<dd><br>
<p>Report the syntax error and fail (default).
</p>
</dd>
<dt><code>error</code></dt>
<dd><br>
<p>Report the syntax error and generate an error.
</p>
</dd>
<dt><code>quiet</code></dt>
<dd><br>
<p>Just fail
</p></dd>
</dl>
</dd>
<dt><code>system_options</code></dt>
<dd><a name="index-system_005foptions-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> This read only flag tells which options were used to compile
YAP. Currently it informs whether the system supports <code>big_numbers</code>,
<code>coroutining</code>, <code>depth_limit</code>, <code>low_level_tracer</code>,
<code>or-parallelism</code>, <code>rational_trees</code>, <code>readline</code>, <code>tabling</code>,
<code>threads</code>, or the <code>wam_profiler</code>.
</p>
</dd>
<dt><code>tabling_mode</code></dt>
<dd><br><p> Sets or reads the tabling mode for all tabled predicates. Please
see section <a href="#Tabling">Tabling</a> for the list of options.
</p>
</dd>
<dt><code>to_chars_mode</code></dt>
<dd><a name="index-to_005fchars_005fmodes-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Define whether YAP should follow <code>quintus</code>-like
semantics for the <code>atom_chars/1</code> or <code>number_chars/1</code> built-in,
or whether it should follow the ISO standard (<code>iso</code> option).
</p>
<p>+</p></dd>
<dt><code>toplevel_hook</code></dt>
<dd><a name="index-toplevel_005fhook-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>+If bound, set the argument to a goal to be executed before entering the
top-level. If unbound show the current goal or <code>true</code> if none is
presented. Only the first solution is considered and the goal is not
backtracked into.
</p>
<p>+</p></dd>
<dt><code>toplevel_print_options</code></dt>
<dd><a name="index-toplevel_005fprint_005foptions-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>+If bound, set the argument to the <code>write_term/3</code> options used to write
terms from the top-level. If unbound, show the current options.
</p>
</dd>
<dt><code>typein_module</code></dt>
<dd><a name="index-typein_005fmodule-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If bound, set the current working or type-in module to the argument,
which must be an atom. If unbound, unify the argument with the current
working module.
</p>
</dd>
<dt><code>unix</code></dt>
<dd><a name="index-unix-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Read-only Boolean flag that unifies with <code>true</code> if YAP is
running on an Unix system. Defined if the C-compiler used to compile
this version of YAP either defines <code>__unix__</code> or <code>unix</code>.
</p>
</dd>
<dt><code>unknown [ISO]</code></dt>
<dd><a name="index-unknown-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Corresponds to calling the <code>unknown/2</code> built-in. Possible values
are <code>error</code>, <code>fail</code>, and <code>warning</code>.
</p>
</dd>
<dt><code>update_semantics</code></dt>
<dd><a name="index-update_005fsemantics-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Define whether YAP should follow <code>immediate</code> update
semantics, as in C-Prolog (default), <code>logical</code> update semantics,
as in Quintus Prolog, SICStus Prolog, or in the ISO standard. There is
also an intermediate mode, <code>logical_assert</code>, where dynamic
procedures follow logical semantics but the internal data base still
follows immediate semantics.
</p>
</dd>
<dt><code>user_error</code></dt>
<dd><a name="index-user_005ferror-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If the second argument is bound to a stream, set <code>user_error</code> to
this stream. If the second argument is unbound, unify the argument with
the current <code>user_error</code> stream.
</p>
<p>By default, the <code>user_error</code> stream is set to a stream
corresponding to the Unix <code>stderr</code> stream.
</p>
<p>The next example shows how to use this flag:
</p><div class="example">
<pre class="example"> ?- open( '/dev/null', append, Error,
[alias(mauri_tripa)] ).
Error = '$stream'(3) ? ;
no
?- set_prolog_flag(user_error, mauri_tripa).
close(mauri_tripa).
yes
?-
</pre></div>
<p>We execute three commands. First, we open a stream in write mode and
give it an alias, in this case <code>mauri_tripa</code>. Next, we set
<code>user_error</code> to the stream via the alias. Note that after we did so
prompts from the system were redirected to the stream
<code>mauri_tripa</code>. Last, we close the stream. At this point, YAP
automatically redirects the <code>user_error</code> alias to the original
<code>stderr</code>.
</p>
</dd>
<dt><code>user_flags</code></dt>
<dd><a name="index-user_005fflags--_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Define the behaviour of <code>set_prolog_flag/2</code> if the flag is not known. Values are <code>silent</code>, <code>warning</code> and <code>error</code>. The first two create the flag on-the-fly, with <code>warning</code> printing a message. The value <code>error</code> is consistent with ISO: it raises an existence error and does not create the flag. See also <code>create_prolog_flag/3</code>. The default is<code>error</code>, and developers are encouraged to use <code>create_prolog_flag/3</code> to create flags for their library.
</p>
</dd>
<dt><code>user_input</code></dt>
<dd><a name="index-user_005finput-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If the second argument is bound to a stream, set <code>user_input</code> to
this stream. If the second argument is unbound, unify the argument with
the current <code>user_input</code> stream.
</p>
<p>By default, the <code>user_input</code> stream is set to a stream
corresponding to the Unix <code>stdin</code> stream.
</p>
</dd>
<dt><code>user_output</code></dt>
<dd><a name="index-user_005foutput-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If the second argument is bound to a stream, set <code>user_output</code> to
this stream. If the second argument is unbound, unify the argument with
the current <code>user_output</code> stream.
</p>
<p>By default, the <code>user_output</code> stream is set to a stream
corresponding to the Unix <code>stdout</code> stream.
</p>
</dd>
<dt><code>verbose</code></dt>
<dd><a name="index-verbose-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>If <code>normal</code> allow printing of informational and banner messages,
such as the ones that are printed when consulting. If <code>silent</code>
disable printing these messages. It is <code>normal</code> by default except if
YAP is booted with the <code>-q</code> or <code>-L</code> flag.
</p>
</dd>
<dt><code>verbose_load</code></dt>
<dd><a name="index-verbose_005fload-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> If <code>true</code> allow printing of informational messages when
consulting files. If <code>false</code> disable printing these messages. It
is <code>normal</code> by default except if YAP is booted with the <code>-L</code>
flag.
</p>
</dd>
<dt><code>version</code></dt>
<dd><a name="index-version-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Read-only flag that returns an atom with the current version of
YAP.
</p>
</dd>
<dt><code>version_data</code></dt>
<dd><a name="index-version_005fdata-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Read-only flag that reads a term of the form
<code>yap</code>(<var>Major</var>,<var>Minor</var>,<var>Patch</var>,<var>Undefined</var>), where
<var>Major</var> is the major version, <var>Minor</var> is the minor version,
and <var>Patch</var> is the patch number.
</p>
</dd>
<dt><code>windows</code></dt>
<dd><a name="index-windoes-_0028yap_005fflag_002f2-option_0029"></a>
<br>
<p>Read-only boolean flag that unifies with tr <code>true</code> if YAP is
running on an Windows machine.
</p>
</dd>
<dt><code>write_strings</code></dt>
<dd><a name="index-write_005fstrings-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Writable flag telling whether the system should write lists of
integers that are writable character codes using the list notation. It
is <code>on</code> if enables or <code>off</code> if disabled. The default value for
this flag is <code>off</code>.
</p>
</dd>
<dt><code>max_workers</code></dt>
<dd><a name="index-max_005fworkers-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Read-only flag telling the maximum number of parallel processes.
</p>
</dd>
<dt><code>max_threads</code></dt>
<dd><a name="index-max_005fthreads-_0028yap_005fflag_002f2-option_0029"></a>
<br><p> Read-only flag telling the maximum number of Prolog threads that can
be created.
</p>
</dd>
</dl>
</dd>
<dt><code>current_prolog_flag(?<var>Flag</var>,-<var>Value</var>) [ISO]</code></dt>
<dd><a name="index-current_005fprolog_005fflag_002f2"></a>
<a name="index-current_005fprolog_005fflag_002f2-1"></a>
<a name="index-current_005fprolog_005fflag_002f2-2"></a>
<p>Obtain the value for a YAP Prolog flag. Equivalent to calling
<code>yap_flag/2</code> with the second argument unbound, and unifying the
returned second argument with <var>Value</var>.
</p>
</dd>
<dt><code>prolog_flag(?<var>Flag</var>,-<var>OldValue</var>,+<var>NewValue</var>)</code></dt>
<dd><a name="index-prolog_005fflag_002f3"></a>
<a name="index-prolog_005fflag_002f3-1"></a>
<a name="index-prolog_005fflag_002f3-2"></a>
<p>Obtain the value for a YAP Prolog flag and then set it to a new
value. Equivalent to first calling <code>current_prolog_flag/2</code> with the
second argument <var>OldValue</var> unbound and then calling
<code>set_prolog_flag/2</code> with the third argument <var>NewValue</var>.
</p>
</dd>
<dt><code>set_prolog_flag(+<var>Flag</var>,+<var>Value</var>) [ISO]</code></dt>
<dd><a name="index-set_005fprolog_005fflag_002f2"></a>
<a name="index-set_005fprolog_005fflag_002f2-1"></a>
<a name="index-set_005fprolog_005fflag_002f2-2"></a>
<p>Set the value for YAP Prolog flag <code>Flag</code>. Equivalent to
calling <code>yap_flag/2</code> with both arguments bound.
</p>
</dd>
<dt><code>create_prolog_flag(+<var>Flag</var>,+<var>Value</var>,+<var>Options</var>)</code></dt>
<dd><a name="index-create_005fprolog_005fflag_002f2"></a>
<a name="index-create_005fprolog_005fflag_002f2-1"></a>
<a name="index-create_005fprolog_005fflag_002f2-2"></a>
<p>Create a new YAP Prolog flag. <var>Options</var> include <code>type(+Type)</code> and <code>access(+Access)</code> with <var>Access</var>
one of <code>read_only</code> or <code>read_write</code> and <var>Type</var> one of <code>boolean</code>, <code>integer</code>, <code>float</code>, <code>atom</code>
and <code>term</code> (that is, no type).
</p>
</dd>
<dt><code>op(+<var>P</var>,+<var>T</var>,+<var>A</var>) [ISO]</code></dt>
<dd><a name="index-op_002f3"></a>
<a name="index-op_002f3-1"></a>
<a name="index-op_002f3-2"></a>
<p>Defines the operator <var>A</var> or the list of operators <var>A</var> with type
<var>T</var> (which must be one of <code>xfx</code>, <code>xfy</code>,<code>yfx</code>,
<code>xf</code>, <code>yf</code>, <code>fx</code> or <code>fy</code>) and precedence <var>P</var>
(see appendix iv for a list of predefined operators).
</p>
<p>Note that if there is a preexisting operator with the same name and
type, this operator will be discarded. Also, <code>','</code> may not be defined
as an operator, and it is not allowed to have the same for an infix and
a postfix operator.
</p>
</dd>
<dt><code>current_op(<var>P</var>,<var>T</var>,<var>F</var>) [ISO]</code></dt>
<dd><a name="index-current_005fop_002f3"></a>
<a name="index-current_005fop_002f3-1"></a>
<a name="index-current_005fop_002f3-2"></a>
<p>Defines the relation: <var>P</var> is a currently defined operator of type
<var>T</var> and precedence <var>P</var>.
</p>
</dd>
<dt><code>prompt(-<var>A</var>,+<var>B</var>)</code></dt>
<dd><a name="index-prompt_002f2"></a>
<a name="index-prompt_002f2-1"></a>
<a name="index-prompt_002f2-2"></a>
<p>Changes YAP input prompt from <var>A</var> to <var>B</var>.
</p>
</dd>
<dt><code>initialization</code></dt>
<dd><a name="index-initialization_002f0"></a>
<a name="index-initialization_002f0-1"></a>
<a name="index-initialization_002f0-2"></a>
<p>Execute the goals defined by initialization/1. Only the first answer is
considered.
</p>
</dd>
<dt><code>prolog_initialization(<var>G</var>)</code></dt>
<dd><a name="index-prolog_005finitialization_002f1"></a>
<a name="index-prolog_005finitialization_002f1-1"></a>
<a name="index-prolog_005finitialization_002f1-2"></a>
<p>Add a goal to be executed on system initialization. This is compatible
with SICStus Prolog&rsquo;s <code>initialization/1</code>.
</p>
</dd>
<dt><code>version</code></dt>
<dd><a name="index-version_002f0"></a>
<a name="index-version_002f0-1"></a>
<a name="index-version_002f0-2"></a>
<p>Write YAP&rsquo;s boot message.
</p>
</dd>
<dt><code>version(-<var>Message</var>)</code></dt>
<dd><a name="index-version_002f1"></a>
<a name="index-version_002f1-1"></a>
<a name="index-version_002f1-2"></a>
<p>Add a message to be written when yap boots or after aborting. It is not
possible to remove messages.
</p>
</dd>
<dt><code>prolog_load_context(?<var>Key</var>, ?<var>Value</var>)</code></dt>
<dd><a name="index-prolog_005fload_005fcontext_002f2"></a>
<a name="index-prolog_005fload_005fcontext_002f2-1"></a>
<a name="index-prolog_005fload_005fcontext_002f2-2"></a>
<p>Obtain information on what is going on in the compilation process. The
following keys are available:
</p>
<dl compact="compact">
<dt><code>directory</code></dt>
<dd><a name="index-directory-_0028prolog_005fload_005fcontext_002f2-option_0029"></a>
<br>
<p>Full name for the directory where YAP is currently consulting the
file.
</p>
</dd>
<dt><code>file</code></dt>
<dd><a name="index-file-_0028prolog_005fload_005fcontext_002f2-option_0029"></a>
<br>
<p>Full name for the file currently being consulted. Notice that included
filed are ignored.
</p>
</dd>
<dt><code>module</code></dt>
<dd><a name="index-module-_0028prolog_005fload_005fcontext_002f2-option_0029"></a>
<br>
<p>Current source module.
</p>
</dd>
<dt><code>source</code></dt>
<dd><a name="index-file-_0028prolog_005fload_005fcontext_002f2-option_0029-1"></a>
<br>
<p>Full name for the file currently being read in, which may be consulted,
reconsulted, or included.
</p>
</dd>
<dt><code>stream</code></dt>
<dd><a name="index-file-_0028prolog_005fload_005fcontext_002f2-option_0029-2"></a>
<br>
<p>Stream currently being read in.
</p>
</dd>
<dt><code>term_position</code></dt>
<dd><a name="index-file-_0028prolog_005fload_005fcontext_002f2-option_0029-3"></a>
<br>
<p>Stream position at the stream currently being read in.
</p></dd>
</dl>
</dd>
<dt><code>source_location(?<var>FileName</var>, ?<var>Line</var>)</code></dt>
<dd><a name="index-source_005flocation_002f2"></a>
<a name="index-source_005flocation_002f2-1"></a>
<a name="index-source_005flocation_002f2-2"></a>
<p>SWI-compatible predicate. If the last term has been read from a physical file (i.e., not from the file user or a string), unify File with an absolute path to the file and Line with the line-number in the file. Please use <code>prolog_load_context/2</code>.
</p>
</dd>
<dt><code>source_file(?<var>File</var>)</code></dt>
<dd><a name="index-source_005ffile_002f1"></a>
<a name="index-source_005ffile_002f1-1"></a>
<a name="index-source_005ffile_002f1-2"></a>
<p>SWI-compatible predicate. True if <var>File</var> is a loaded Prolog source file.
</p>
</dd>
<dt><code>source_file(?<var>ModuleAndPred</var>,?<var>File</var>)</code></dt>
<dd><a name="index-source_005ffile_002f2"></a>
<a name="index-source_005ffile_002f2-1"></a>
<a name="index-source_005ffile_002f2-2"></a>
<p>SWI-compatible predicate. True if the predicate specified by <var>ModuleAndPred</var> was loaded from file <var>File</var>, where <var>File</var> is an absolute path name (see <code>absolute_file_name/2</code>).
</p>
</dd>
</dl>
<hr>
<a name="Library"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Built_002dins" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Misc" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Aggregate" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Library-Predicates"></a>
<h1 class="chapter">7 Library Predicates</h1>
<p>Library files reside in the library_directory path (set by the
<code>LIBDIR</code> variable in the Makefile for YAP). Currently,
most files in the library are from the Edinburgh Prolog library.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Library, Extensions, Built-ins, Top
</pre></th></tr><tr><td align="left" valign="top"><a href="#Aggregate">7.1 Aggregate</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI and SICStus compatible aggregate library
</td></tr>
<tr><td align="left" valign="top"><a href="#Apply">7.2 Apply Macros</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI-Compatible Apply library.
</td></tr>
<tr><td align="left" valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Binary Tree Implementation of Association Lists.
</td></tr>
<tr><td align="left" valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Predicates to add and lookup balanced binary trees.
</td></tr>
<tr><td align="left" valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Call With registered Cleanup Calls
</td></tr>
<tr><td align="left" valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Directed Graphs Implemented With Red-Black Trees
</td></tr>
<tr><td align="left" valign="top"><a href="#Heaps">7.5 Heaps</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Labelled binary tree where the key of each node is less
than or equal to the keys of its children.
</td></tr>
<tr><td align="left" valign="top"><a href="#LAM">7.32 LAM</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> LAM MPI
</td></tr>
<tr><td align="left" valign="top"><a href="#Lambda">7.31 Lambda Expressions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Ulrich Neumerkel&rsquo;s Lambda Library
</td></tr>
<tr><td align="left" valign="top"><a href="#Lists">7.6 List Manipulation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#MapList">7.8 Maplist</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI-Compatible Apply library.
</td></tr>
<tr><td align="left" valign="top"><a href="#matrix">7.9 Matrix Library</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Matrix Objects
</td></tr>
<tr><td align="left" valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Matlab Interface
</td></tr>
<tr><td align="left" valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Queues, Heaps, and Beams.
</td></tr>
<tr><td align="left" valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Ordered Set Manipulation
</td></tr>
<tr><td align="left" valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Pseudo Random Numbers
</td></tr>
<tr><td align="left" valign="top"><a href="#Queues">7.14 Queues</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Queue Manipulation
</td></tr>
<tr><td align="left" valign="top"><a href="#Random">7.15 Random Number Generator</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Random Numbers
</td></tr>
<tr><td align="left" valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI inspired utilities for fast stream scanning.
</td></tr>
<tr><td align="left" valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Predicates to add, lookup and delete in red-black binary trees.
</td></tr>
<tr><td align="left" valign="top"><a href="#RegExp">7.18 Regular Expressions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Regular Expression Manipulation
</td></tr>
<tr><td align="left" valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> SWI Prolog shlib library
</td></tr>
<tr><td align="left" valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Writing To and Reading From Strings
</td></tr>
<tr><td align="left" valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> System Utilities
</td></tr>
<tr><td align="left" valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Utilities on Terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Timeout">7.26 Calls With Timeout</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Call With Timeout
</td></tr>
<tr><td align="left" valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Undirected Graphs Using DGraphs
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
</pre></th></tr></table>
<hr>
<a name="Aggregate"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Apply" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Aggregate-1"></a>
<h2 class="section">7.1 Aggregate</h2>
<a name="index-aggregate"></a>
<p>This is the SWI-Prolog library based on the Quintus and SICStus 4
library. Notice that <code>forall/2</code>
is a SWI-Prolog built-in and <code>term_variables/3</code> is a SWI-Prolog with a
different definition. </p>
<p>This library provides aggregating operators over the solutions of a
predicate. The operations are a generalisation of the <code>bagof/3</code>,
<code>setof/3</code> and <code>findall/3</code> built-in predicates. The defined
aggregation operations are counting, computing the sum, minimum,
maximum, a bag of solutions and a set of solutions. We first give a
simple example, computing the country with the smallest area:
</p>
<div class="example">
<pre class="example">smallest_country(Name, Area) :-
aggregate(min(A, N), country(N, A), min(Area, Name)).
</pre></div>
<p>There are four aggregation predicates, distinguished on two properties.
</p>
<dl compact="compact">
<dt><code>aggregate vs. aggregate_all</code></dt>
<dd><p> The aggregate predicates use setof/3 (aggregate/4) or bagof/3
(aggregate/3), dealing with existential qualified variables
(<var>Var</var>/\<var>Goal</var>) and providing multiple solutions for the
remaining free variables in <var>Goal</var>. The aggregate_all/3
predicate uses findall/3, implicitly qualifying all free variables
and providing exactly one solution, while aggregate_all/4 uses
sort/2 over solutions and Distinguish (see below) generated using
findall/3.
</p></dd>
<dt><code>The <var>Distinguish</var> argument</code></dt>
<dd><p> The versions with 4 arguments provide a <var>Distinguish</var> argument
that allow for keeping duplicate bindings of a variable in the
result. For example, if we wish to compute the total population of
all countries we do not want to lose results because two countries
have the same population. Therefore we use:
</p>
<div class="example">
<pre class="example"> aggregate(sum(P), Name, country(Name, P), Total)
</pre></div>
</dd>
</dl>
<p>All aggregation predicates support the following operator below in
<var>Template</var>. In addition, they allow for an arbitrary named compound
term where each of the arguments is a term from the list below. I.e. the
term <code>r(min(X), max(X))</code> computes both the minimum and maximum
binding for <var>X</var>.
</p>
<dl compact="compact">
<dt><code>count</code></dt>
<dd><p> Count number of solutions. Same as <code>sum(1)</code>.
</p></dd>
<dt><code>sum(<var>Expr</var>)</code></dt>
<dd><p> Sum of <var>Expr</var> for all solutions.
</p></dd>
<dt><code>min(<var>Expr</var>)</code></dt>
<dd><p> Minimum of <var>Expr</var> for all solutions.
</p></dd>
<dt><code>min(<var>Expr</var>, <var>Witness</var>)</code></dt>
<dd><p> A term min(<var>Min</var>, <var>Witness</var>), where <var>Min</var> is the minimal version of <var>Expr</var>
over all Solution and <var>Witness</var> is any other template applied to
Solution that produced <var>Min</var>. If multiple solutions provide the same
minimum, <var>Witness</var> corresponds to the first solution.
</p></dd>
<dt><code>max(<var>Expr</var>)</code></dt>
<dd><p> Maximum of <var>Expr</var> for all solutions.
</p></dd>
<dt><code>max(<var>Expr</var>, <var>Witness</var>)</code></dt>
<dd><p> As min(<var>Expr</var>, <var>Witness</var>), but producing the maximum result.
</p></dd>
<dt><code>set(<var>X</var>)</code></dt>
<dd><p> An ordered set with all solutions for <var>X</var>.
</p></dd>
<dt><code>bag(<var>X</var>)</code></dt>
<dd><p> A list of all solutions for <var>X</var>.
</p></dd>
</dl>
<p>The predicates are:
</p><dl compact="compact">
<dt><code>[nondet]aggregate(+<var>Template</var>, :<var>Goal</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-aggregate_002f3"></a>
<a name="index-aggregate_002f3-1"></a>
<a name="index-aggregate_002f3-2"></a>
<p> Aggregate bindings in <var>Goal</var> according to <var>Template</var>. The
aggregate/3 version performs bagof/3 on <var>Goal</var>.
</p></dd>
<dt><code>[nondet]aggregate(+<var>Template</var>, +<var>Discriminator</var>, :<var>Goal</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-aggregate_002f4"></a>
<a name="index-aggregate_002f4-1"></a>
<a name="index-aggregate_002f4-2"></a>
<p> Aggregate bindings in <var>Goal</var> according to <var>Template</var>. The
aggregate/3 version performs setof/3 on <var>Goal</var>.
</p></dd>
<dt><code>[semidet]aggregate_all(+<var>Template</var>, :<var>Goal</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-aggregate_005fall_002f3"></a>
<a name="index-aggregate_005fall_002f3-1"></a>
<a name="index-aggregate_005fall_002f3-2"></a>
<p> Aggregate bindings in <var>Goal</var> according to <var>Template</var>. The
aggregate_all/3 version performs findall/3 on <var>Goal</var>.
</p></dd>
<dt><code>[semidet]aggregate_all(+<var>Template</var>, +<var>Discriminator</var>, :<var>Goal</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-aggregate_005fall_002f4"></a>
<a name="index-aggregate_005fall_002f4-1"></a>
<a name="index-aggregate_005fall_002f4-2"></a>
<p> Aggregate bindings in <var>Goal</var> according to <var>Template</var>. The
aggregate_all/3 version performs findall/3 followed by sort/2 on
<var>Goal</var>.
</p></dd>
<dt><code>foreach(:Generator, :<var>Goal</var>)</code></dt>
<dd><a name="index-foreach_002f2"></a>
<a name="index-foreach_002f2-1"></a>
<a name="index-foreach_002f2-2"></a>
<p> True if the conjunction of instances of <var>Goal</var> using the
bindings from Generator is true. Unlike forall/2, which runs a
failure-driven loop that proves <var>Goal</var> for each solution of
Generator, foreach creates a conjunction. Each member of the
conjunction is a copy of <var>Goal</var>, where the variables it shares
with Generator are filled with the values from the corresponding
solution.
</p>
<p> The implementation executes forall/2 if <var>Goal</var> does not contain
any variables that are not shared with Generator.
</p>
<p> Here is an example:
</p><div class="example">
<pre class="example"> ?- foreach(between(1,4,X), dif(X,Y)), Y = 5.
Y = 5
?- foreach(between(1,4,X), dif(X,Y)), Y = 3.
No
</pre></div>
<p> Notice that <var>Goal</var> is copied repeatedly, which may cause
problems if attributed variables are involved.
</p>
</dd>
<dt><code>[det]free_variables(:Generator, +<var>Template</var>, +VarList0, -VarList)</code></dt>
<dd><a name="index-free_005fvariables_002f4"></a>
<a name="index-free_005fvariables_002f4-1"></a>
<a name="index-free_005fvariables_002f4-2"></a>
<p> In order to handle variables properly, we have to find all the universally quantified variables in the Generator. All variables as yet unbound are universally quantified, unless
</p>
<ol>
<li> they occur in the template
</li><li> they are bound by X/\P, setof, or bagof
</li></ol>
<p> <code>free_variables(Generator, Template, OldList, NewList)</code> finds this set, using OldList as an accumulator.
</p></dd>
</dl>
<p>The original author of this code was Richard O&rsquo;Keefe. Jan Wielemaker
made some SWI-Prolog enhancements, sponsored by SecuritEase,
http://www.securitease.com. The code is public domain (from DEC10 library).
</p>
<hr>
<a name="Apply"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Aggregate" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Association-Lists" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Apply-Macros"></a>
<h2 class="section">7.2 Apply Macros</h2>
<a name="index-apply"></a>
<p>This library provides a SWI-compatible set of utilities for applying a
predicate to all elements of a list. The library just forwards
definitions from the <code>maplist</code> library.
</p>
<hr>
<a name="Association-Lists"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Apply" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#AVL-Trees" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Association-Lists-1"></a>
<h2 class="section">7.3 Association Lists</h2>
<a name="index-association-list"></a>
<p>The following association list manipulation predicates are available
once included with the <code>use_module(library(assoc))</code> command. The
original library used Richard O&rsquo;Keefe&rsquo;s implementation, on top of
unbalanced binary trees. The current code utilises code from the
red-black trees library and emulates the SICStus Prolog interface.
</p>
<dl compact="compact">
<dt><code>assoc_to_list(+<var>Assoc</var>,?<var>List</var>)</code></dt>
<dd><a name="index-assoc_005fto_005flist_002f2"></a>
<a name="index-assoc_005fto_005flist_002f2-1"></a>
<a name="index-assoc_005fto_005flist_002f2-2"></a>
<p>Given an association list <var>Assoc</var> unify <var>List</var> with a list of
the form <var>Key-Val</var>, where the elements <var>Key</var> are in ascending
order.
</p>
</dd>
<dt><code>del_assoc(+<var>Key</var>, +<var>Assoc</var>, ?<var>Val</var>, ?<var>NewAssoc</var>)</code></dt>
<dd><a name="index-del_005fassoc_002f4"></a>
<a name="index-del_005fassoc_002f4-1"></a>
<a name="index-del_005fassoc_002f4-2"></a>
<p>Succeeds if <var>NewAssoc</var> is an association list, obtained by removing
the element with <var>Key</var> and <var>Val</var> from the list <var>Assoc</var>.
</p>
</dd>
<dt><code>del_max_assoc(+<var>Assoc</var>, ?<var>Key</var>, ?<var>Val</var>, ?<var>NewAssoc</var>)</code></dt>
<dd><a name="index-del_005fmax_005fassoc_002f4"></a>
<a name="index-del_005fmax_005fassoc_002f4-1"></a>
<a name="index-del_005fmax_005fassoc_002f4-2"></a>
<p>Succeeds if <var>NewAssoc</var> is an association list, obtained by removing
the largest element of the list, with <var>Key</var> and <var>Val</var> from the
list <var>Assoc</var>.
</p>
</dd>
<dt><code>del_min_assoc(+<var>Assoc</var>, ?<var>Key</var>, ?<var>Val</var>, ?<var>NewAssoc</var>)</code></dt>
<dd><a name="index-del_005fmin_005fassoc_002f4"></a>
<a name="index-del_005fmin_005fassoc_002f4-1"></a>
<a name="index-del_005fmin_005fassoc_002f4-2"></a>
<p>Succeeds if <var>NewAssoc</var> is an association list, obtained by removing
the smallest element of the list, with <var>Key</var> and <var>Val</var>
from the list <var>Assoc</var>.
</p>
</dd>
<dt><code>empty_assoc(+<var>Assoc</var>)</code></dt>
<dd><a name="index-empty_005fassoc_002f1"></a>
<a name="index-empty_005fassoc_002f1-1"></a>
<a name="index-empty_005fassoc_002f1-2"></a>
<p>Succeeds if association list <var>Assoc</var> is empty.
</p>
</dd>
<dt><code>gen_assoc(+<var>Assoc</var>,?<var>Key</var>,?<var>Value</var>)</code></dt>
<dd><a name="index-gen_005fassoc_002f3"></a>
<a name="index-gen_005fassoc_002f3-1"></a>
<a name="index-gen_005fassoc_002f3-2"></a>
<p>Given the association list <var>Assoc</var>, unify <var>Key</var> and <var>Value</var>
with two associated elements. It can be used to enumerate all elements
in the association list.
</p>
</dd>
<dt><code>get_assoc(+<var>Key</var>,+<var>Assoc</var>,?<var>Value</var>)</code></dt>
<dd><a name="index-get_005fnext_005fassoc_002f4"></a>
<a name="index-get_005fnext_005fassoc_002f4-1"></a>
<a name="index-get_005fnext_005fassoc_002f4-2"></a>
<p>If <var>Key</var> is one of the elements in the association list <var>Assoc</var>,
return the associated value.
</p>
</dd>
<dt><code>get_assoc(+<var>Key</var>,+<var>Assoc</var>,?<var>Value</var>,+<var>NAssoc</var>,?<var>NValue</var>)</code></dt>
<dd><a name="index-get_005fassoc_002f5"></a>
<a name="index-get_005fassoc_002f5-1"></a>
<a name="index-get_005fassoc_002f5-2"></a>
<p>If <var>Key</var> is one of the elements in the association list <var>Assoc</var>,
return the associated value <var>Value</var> and a new association list
<var>NAssoc</var> where <var>Key</var> is associated with <var>NValue</var>.
</p>
</dd>
<dt><code>get_prev_assoc(+<var>Key</var>,+<var>Assoc</var>,?<var>Next</var>,?<var>Value</var>)</code></dt>
<dd><a name="index-get_005fprev_005fassoc_002f4"></a>
<a name="index-get_005fprev_005fassoc_002f4-1"></a>
<a name="index-get_005fprev_005fassoc_002f4-2"></a>
<p>If <var>Key</var> is one of the elements in the association list <var>Assoc</var>,
return the previous key, <var>Next</var>, and its value, <var>Value</var>.
</p>
</dd>
<dt><code>get_next_assoc(+<var>Key</var>,+<var>Assoc</var>,?<var>Next</var>,?<var>Value</var>)</code></dt>
<dd><a name="index-get_005fassoc_002f3"></a>
<a name="index-get_005fassoc_002f3-1"></a>
<a name="index-get_005fassoc_002f3-2"></a>
<p>If <var>Key</var> is one of the elements in the association list <var>Assoc</var>,
return the next key, <var>Next</var>, and its value, <var>Value</var>.
</p>
</dd>
<dt><code>is_assoc(+<var>Assoc</var>)</code></dt>
<dd><a name="index-is_005fassoc_002f1"></a>
<a name="index-is_005fassoc_002f1-1"></a>
<a name="index-is_005fassoc_002f1-2"></a>
<p>Succeeds if <var>Assoc</var> is an association list, that is, if it is a
red-black tree.
</p>
</dd>
<dt><code>list_to_assoc(+<var>List</var>,?<var>Assoc</var>)</code></dt>
<dd><a name="index-list_005fto_005fassoc_002f2"></a>
<a name="index-list_005fto_005fassoc_002f2-1"></a>
<a name="index-list_005fto_005fassoc_002f2-2"></a>
<p>Given a list <var>List</var> such that each element of <var>List</var> is of the
form <var>Key-Val</var>, and all the <var>Keys</var> are unique, <var>Assoc</var> is
the corresponding association list.
</p>
</dd>
<dt><code>map_assoc(+<var>Pred</var>,+<var>Assoc</var>)</code></dt>
<dd><a name="index-map_005fassoc_002f2"></a>
<a name="index-map_005fassoc_002f2-1"></a>
<a name="index-map_005fassoc_002f2-2"></a>
<p>Succeeds if the unary predicate name <var>Pred</var>(<var>Val</var>) holds for every
element in the association list.
</p>
</dd>
<dt><code>map_assoc(+<var>Pred</var>,+<var>Assoc</var>,?<var>New</var>)</code></dt>
<dd><a name="index-map_005fassoc_002f3"></a>
<a name="index-map_005fassoc_002f3-1"></a>
<a name="index-map_005fassoc_002f3-2"></a>
<p>Given the binary predicate name <var>Pred</var> and the association list
<var>Assoc</var>, <var>New</var> in an association list with keys in <var>Assoc</var>,
and such that if <var>Key-Val</var> is in <var>Assoc</var>, and <var>Key-Ans</var> is in
<var>New</var>, then <var>Pred</var>(<var>Val</var>,<var>Ans</var>) holds.
</p>
</dd>
<dt><code>max_assoc(+<var>Assoc</var>,-<var>Key</var>,?<var>Value</var>)</code></dt>
<dd><a name="index-max_005fassoc_002f3"></a>
<a name="index-max_005fassoc_002f3-1"></a>
<a name="index-max_005fassoc_002f3-2"></a>
<p>Given the association list
<var>Assoc</var>, <var>Key</var> in the largest key in the list, and <var>Value</var>
the associated value.
</p>
</dd>
<dt><code>min_assoc(+<var>Assoc</var>,-<var>Key</var>,?<var>Value</var>)</code></dt>
<dd><a name="index-min_005fassoc_002f3"></a>
<a name="index-min_005fassoc_002f3-1"></a>
<a name="index-min_005fassoc_002f3-2"></a>
<p>Given the association list
<var>Assoc</var>, <var>Key</var> in the smallest key in the list, and <var>Value</var>
the associated value.
</p>
</dd>
<dt><code>ord_list_to_assoc(+<var>List</var>,?<var>Assoc</var>)</code></dt>
<dd><a name="index-ord_005flist_005fto_005fassoc_002f2"></a>
<a name="index-ord_005flist_005fto_005fassoc_002f2-1"></a>
<a name="index-ord_005flist_005fto_005fassoc_002f2-2"></a>
<p>Given an ordered list <var>List</var> such that each element of <var>List</var> is
of the form <var>Key-Val</var>, and all the <var>Keys</var> are unique, <var>Assoc</var> is
the corresponding association list.
</p>
</dd>
<dt><code>put_assoc(+<var>Key</var>,+<var>Assoc</var>,+<var>Val</var>,+<var>New</var>)</code></dt>
<dd><a name="index-put_005fassoc_002f4"></a>
<a name="index-put_005fassoc_002f4-1"></a>
<a name="index-put_005fassoc_002f4-2"></a>
<p>The association list <var>New</var> includes and element of association
<var>key</var> with <var>Val</var>, and all elements of <var>Assoc</var> that did not
have key <var>Key</var>.
</p>
</dd>
</dl>
<hr>
<a name="AVL-Trees"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Association-Lists" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Heaps" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="AVL-Trees-1"></a>
<h2 class="section">7.4 AVL Trees</h2>
<a name="index-AVL-trees"></a>
<p>AVL trees are balanced search binary trees. They are named after their
inventors, Adelson-Velskii and Landis, and they were the first
dynamically balanced trees to be proposed. The YAP AVL tree manipulation
predicates library uses code originally written by Martin van Emdem and
published in the Logic Programming Newsletter, Autumn 1981. A bug in
this code was fixed by Philip Vasey, in the Logic Programming
Newsletter, Summer 1982. The library currently only includes routines to
insert and lookup elements in the tree. Please try red-black trees if
you need deletion.
</p>
<dl compact="compact">
<dt><code>avl_new(+<var>T</var>)</code></dt>
<dd><a name="index-avl_005fnew_002f1"></a>
<a name="index-avl_005fnew_002f1-1"></a>
<a name="index-avl_005fnew_002f1-2"></a>
<p>Create a new tree.
</p>
</dd>
<dt><code>avl_insert(+<var>Key</var>,?<var>Value</var>,+<var>T0</var>,-<var>TF</var>)</code></dt>
<dd><a name="index-avl_005finsert_002f4"></a>
<a name="index-avl_005finsert_002f4-1"></a>
<a name="index-avl_005finsert_002f4-2"></a>
<p>Add an element with key <var>Key</var> and <var>Value</var> to the AVL tree
<var>T0</var> creating a new AVL tree <var>TF</var>. Duplicated elements are
allowed.
</p>
</dd>
<dt><code>avl_lookup(+<var>Key</var>,-<var>Value</var>,+<var>T</var>)</code></dt>
<dd><a name="index-avl_005flookup_002f3"></a>
<a name="index-avl_005flookup_002f3-1"></a>
<a name="index-avl_005flookup_002f3-2"></a>
<p>Lookup an element with key <var>Key</var> in the AVL tree
<var>T</var>, returning the value <var>Value</var>.
</p>
</dd>
</dl>
<hr>
<a name="Heaps"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#AVL-Trees" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Lists" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Heaps-1"></a>
<h2 class="section">7.5 Heaps</h2>
<a name="index-heap"></a>
<p>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.
</p>
<p>The following heap manipulation routines are available once included
with the <code>use_module(library(heaps))</code> command.
</p>
<dl compact="compact">
<dt><code>add_to_heap(+<var>Heap</var>,+<var>key</var>,+<var>Datum</var>,-<var>NewHeap</var>)</code></dt>
<dd><a name="index-add_005fto_005fheap_002f4"></a>
<a name="index-add_005fto_005fheap_002f4-1"></a>
<a name="index-add_005fto_005fheap_002f4-2"></a>
<p>Inserts the new <var>Key-Datum</var> pair into the heap. The insertion is not
stable, that is, if you insert several pairs with the same <var>Key</var> 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.
</p>
</dd>
<dt><code>empty_heap(?<var>Heap</var>)</code></dt>
<dd><a name="index-empty_005fheap_002f1"></a>
<a name="index-empty_005fheap_002f1-1"></a>
<a name="index-empty_005fheap_002f1-2"></a>
<p>Succeeds if <var>Heap</var> is an empty heap.
</p>
</dd>
<dt><code>get_from_heap(+<var>Heap</var>,-<var>key</var>,-<var>Datum</var>,-<var>Heap</var>)</code></dt>
<dd><a name="index-get_005ffrom_005fheap_002f4"></a>
<a name="index-get_005ffrom_005fheap_002f4-1"></a>
<a name="index-get_005ffrom_005fheap_002f4-2"></a>
<p>Returns the <var>Key-Datum</var> pair in <var>OldHeap</var> with the smallest
<var>Key</var>, and also a <var>Heap</var> which is the <var>OldHeap</var> with that
pair deleted.
</p>
</dd>
<dt><code>heap_size(+<var>Heap</var>, -<var>Size</var>)</code></dt>
<dd><a name="index-heap_005fsize_002f2"></a>
<a name="index-heap_005fsize_002f2-1"></a>
<a name="index-heap_005fsize_002f2-2"></a>
<p>Reports the number of elements currently in the heap.
</p>
</dd>
<dt><code>heap_to_list(+<var>Heap</var>, -<var>List</var>)</code></dt>
<dd><a name="index-heap_005fto_005flist_002f2"></a>
<a name="index-heap_005fto_005flist_002f2-1"></a>
<a name="index-heap_005fto_005flist_002f2-2"></a>
<p>Returns the current set of <var>Key-Datum</var> pairs in the <var>Heap</var> as a
<var>List</var>, sorted into ascending order of <var>Keys</var>.
</p>
</dd>
<dt><code>list_to_heap(+<var>List</var>, -<var>Heap</var>)</code></dt>
<dd><a name="index-list_005fto_005fheap_002f2"></a>
<a name="index-list_005fto_005fheap_002f2-1"></a>
<a name="index-list_005fto_005fheap_002f2-2"></a>
<p>Takes a list of <var>Key-Datum</var> pairs (such as keysort could be used to sort)
and forms them into a heap.
</p>
</dd>
<dt><code>min_of_heap(+<var>Heap</var>, -<var>Key</var>, -<var>Datum</var>)</code></dt>
<dd><a name="index-min_005fof_005fheap_002f3"></a>
<a name="index-min_005fof_005fheap_002f3-1"></a>
<a name="index-min_005fof_005fheap_002f3-2"></a>
<p>Returns the Key-Datum pair at the top of the heap (which is of course
the pair with the smallest Key), but does not remove it from the heap.
</p>
</dd>
<dt><code>min_of_heap(+<var>Heap</var>, -<var>Key1</var>, -<var>Datum1</var>,</code></dt>
<dd><p>-<var>Key2</var>, -<var>Datum2</var>)
<a name="index-min_005fof_005fheap_002f5"></a>
<a name="index-min_005fof_005fheap_002f5-1"></a>
<a name="index-min_005fof_005fheap_002f5-2"></a>
Returns the smallest (Key1) and second smallest (Key2) pairs in the
heap, without deleting them.
</p></dd>
</dl>
<hr>
<a name="Lists"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Heaps" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#LineUtilities" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="List-Manipulation"></a>
<h2 class="section">7.6 List Manipulation</h2>
<a name="index-list-manipulation"></a>
<p>The following list manipulation routines are available once included
with the <code>use_module(library(lists))</code> command.
</p>
<dl compact="compact">
<dt><code>append(?<var>Prefix</var>,?<var>Suffix</var>,?<var>Combined</var>)</code></dt>
<dd><a name="index-append_002f3"></a>
<a name="index-append_002f3-1"></a>
<a name="index-append_002f3-2"></a>
<p>True when all three arguments are lists, and the members of
<var>Combined</var> are the members of <var>Prefix</var> followed by the members of <var>Suffix</var>.
It may be used to form <var>Combined</var> from a given <var>Prefix</var>, <var>Suffix</var> or to take
a given <var>Combined</var> apart.
</p>
</dd>
<dt><code>append(?<var>Lists</var>,?<var>Combined</var>)</code></dt>
<dd><a name="index-append_002f2"></a>
<a name="index-append_002f2-1"></a>
<a name="index-append_002f2-2"></a>
<p>Holds if the lists of <var>Lists</var> can be concatenated as a
<var>Combined</var> list.
</p>
</dd>
<dt><code>delete(+<var>List</var>, ?<var>Element</var>, ?<var>Residue</var>)</code></dt>
<dd><a name="index-delete_002f3"></a>
<a name="index-delete_002f3-1"></a>
<a name="index-delete_002f3-2"></a>
<p>True when <var>List</var> is a list, in which <var>Element</var> may or may not
occur, and <var>Residue</var> is a copy of <var>List</var> with all elements
identical to <var>Element</var> deleted.
</p>
</dd>
<dt><code>flatten(+<var>List</var>, ?<var>FlattenedList</var>)</code></dt>
<dd><a name="index-flatten_002f2"></a>
<a name="index-flatten_002f2-1"></a>
<a name="index-flatten_002f2-2"></a>
<p>Flatten a list of lists <var>List</var> into a single list
<var>FlattenedList</var>.
</p>
<div class="example">
<pre class="example">?- flatten([[1],[2,3],[4,[5,6],7,8]],L).
L = [1,2,3,4,5,6,7,8] ? ;
no
</pre></div>
</dd>
<dt><code>last(+<var>List</var>,?<var>Last</var>)</code></dt>
<dd><a name="index-last_002f2"></a>
<a name="index-last_002f2-1"></a>
<a name="index-last_002f2-2"></a>
<p>True when <var>List</var> is a list and <var>Last</var> is identical to its last element.
</p>
</dd>
<dt><code>list_concat(+<var>Lists</var>,?<var>List</var>)</code></dt>
<dd><a name="index-list_005fconcat_002f2"></a>
<a name="index-list_005fconcat_002f2-1"></a>
<a name="index-list_005fconcat_002f2-2"></a>
<p>True when <var>Lists</var> is a list of lists and <var>List</var> is the
concatenation of <var>Lists</var>.
</p>
</dd>
<dt><code>member(?<var>Element</var>, ?<var>Set</var>)</code></dt>
<dd><a name="index-member_002f2"></a>
<a name="index-member_002f2-1"></a>
<a name="index-member_002f2-2"></a>
<p>True when <var>Set</var> is a list, and <var>Element</var> occurs in it. It may be used
to test for an element or to enumerate all the elements by backtracking.
</p>
</dd>
<dt><code>memberchk(+<var>Element</var>, +<var>Set</var>)</code></dt>
<dd><a name="index-memberchk_002f2"></a>
<a name="index-memberchk_002f2-1"></a>
<a name="index-memberchk_002f2-2"></a>
<p>As <code>member/2</code>, but may only be used to test whether a known
<var>Element</var> occurs in a known Set. In return for this limited use, it
is more efficient when it is applicable.
</p>
</dd>
<dt><code>nth0(?<var>N</var>, ?<var>List</var>, ?<var>Elem</var>)</code></dt>
<dd><a name="index-nth0_002f3"></a>
<a name="index-nth0_002f3-1"></a>
<a name="index-nth0_002f3-2"></a>
<p>True when <var>Elem</var> is the Nth member of <var>List</var>,
counting the first as element 0. (That is, throw away the first
N elements and unify <var>Elem</var> 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 <code>member/2</code>
</p>
</dd>
<dt><code>nth1(?<var>N</var>, ?<var>List</var>, ?<var>Elem</var>)</code></dt>
<dd><a name="index-nth1_002f3"></a>
<a name="index-nth1_002f3-1"></a>
<a name="index-nth1_002f3-2"></a>
<p>The same as <code>nth0/3</code>, except that it counts from
1, that is <code>nth(1, [H|_], H)</code>.
</p>
</dd>
<dt><code>nth(?<var>N</var>, ?<var>List</var>, ?<var>Elem</var>)</code></dt>
<dd><a name="index-nth_002f3"></a>
<a name="index-nth_002f3-1"></a>
<a name="index-nth_002f3-2"></a>
<p>The same as <code>nth1/3</code>.
</p>
</dd>
<dt><code>nth0(?<var>N</var>, ?<var>List</var>, ?<var>Elem</var>, ?<var>Rest</var>)</code></dt>
<dd><a name="index-nth0_002f4"></a>
<a name="index-nth0_002f4-1"></a>
<a name="index-nth0_002f4-2"></a>
<p>Unifies <var>Elem</var> with the Nth element of <var>List</var>,
counting from 0, and <var>Rest</var> with the other elements. It can be used
to select the Nth element of <var>List</var> (yielding <var>Elem</var> and <var>Rest</var>), or to
insert <var>Elem</var> before the Nth (counting from 1) element of <var>Rest</var>, when
it yields <var>List</var>, e.g. <code>nth0(2, List, c, [a,b,d,e])</code> unifies List with
<code>[a,b,c,d,e]</code>. <code>nth/4</code> is the same except that it counts from 1. <code>nth0/4</code>
can be used to insert <var>Elem</var> after the Nth element of <var>Rest</var>.
</p>
</dd>
<dt><code>nth1(?<var>N</var>, ?<var>List</var>, ?<var>Elem</var>, ?<var>Rest</var>)</code></dt>
<dd><a name="index-nth1_002f4"></a>
<a name="index-nth1_002f4-1"></a>
<a name="index-nth1_002f4-2"></a>
<p>Unifies <var>Elem</var> with the Nth element of <var>List</var>, counting from 1,
and <var>Rest</var> with the other elements. It can be used to select the
Nth element of <var>List</var> (yielding <var>Elem</var> and <var>Rest</var>), or to
insert <var>Elem</var> before the Nth (counting from 1) element of
<var>Rest</var>, when it yields <var>List</var>, e.g. <code>nth(3, List, c,
[a,b,d,e])</code> unifies List with <code>[a,b,c,d,e]</code>. <code>nth/4</code>
can be used to insert <var>Elem</var> after the Nth element of <var>Rest</var>.
</p>
</dd>
<dt><code>nth(?<var>N</var>, ?<var>List</var>, ?<var>Elem</var>, ?<var>Rest</var>)</code></dt>
<dd><a name="index-nth_002f4"></a>
<a name="index-nth_002f4-1"></a>
<a name="index-nth_002f4-2"></a>
<p>Same as <code>nth1/4</code>.
</p>
</dd>
<dt><code>permutation(+<var>List</var>,?<var>Perm</var>)</code></dt>
<dd><a name="index-permutation_002f2"></a>
<a name="index-permutation_002f2-1"></a>
<a name="index-permutation_002f2-2"></a>
<p>True when <var>List</var> and <var>Perm</var> are permutations of each other.
</p>
</dd>
<dt><code>remove_duplicates(+<var>List</var>, ?<var>Pruned</var>)</code></dt>
<dd><a name="index-remove_005fduplicates_002f2"></a>
<a name="index-remove_005fduplicates_002f2-1"></a>
<a name="index-remove_005fduplicates_002f2-2"></a>
<p>Removes duplicated elements from <var>List</var>. Beware: if the <var>List</var> has
non-ground elements, the result may surprise you.
</p>
</dd>
<dt><code>reverse(+<var>List</var>, ?<var>Reversed</var>)</code></dt>
<dd><a name="index-reverse_002f2"></a>
<a name="index-reverse_002f2-1"></a>
<a name="index-reverse_002f2-2"></a>
<p>True when <var>List</var> and <var>Reversed</var> are lists with the same elements
but in opposite orders.
</p>
</dd>
<dt><code>same_length(?<var>List1</var>, ?<var>List2</var>)</code></dt>
<dd><a name="index-same_005flength_002f2"></a>
<a name="index-same_005flength_002f2-1"></a>
<a name="index-same_005flength_002f2-2"></a>
<p>True when <var>List1</var> and <var>List2</var> are both lists and have the same number
of elements. No relation between the values of their elements is
implied.
Modes <code>same_length(-,+)</code> and <code>same_length(+,-)</code> generate either list given
the other; mode <code>same_length(-,-)</code> generates two lists of the same length,
in which case the arguments will be bound to lists of length 0, 1, 2, ...
</p>
</dd>
<dt><code>select(?<var>Element</var>, ?<var>List</var>, ?<var>Residue</var>)</code></dt>
<dd><a name="index-select_002f3"></a>
<a name="index-select_002f3-1"></a>
<a name="index-select_002f3-2"></a>
<p>True when <var>Set</var> is a list, <var>Element</var> occurs in <var>List</var>, and
<var>Residue</var> is everything in <var>List</var> except <var>Element</var> (things
stay in the same order).
</p>
</dd>
<dt><code>selectchk(?<var>Element</var>, ?<var>List</var>, ?<var>Residue</var>)</code></dt>
<dd><a name="index-selectchk_002f3"></a>
<a name="index-selectchk_002f3-1"></a>
<a name="index-selectchk_002f3-2"></a>
<p>Semi-deterministic selection from a list. Steadfast: defines as
</p>
<div class="example">
<pre class="example">selectchk(Elem, List, Residue) :-
select(Elem, List, Rest0), !,
Rest = Rest0.
</pre></div>
</dd>
<dt><code>sublist(?<var>Sublist</var>, ?<var>List</var>)</code></dt>
<dd><a name="index-sublist_002f2"></a>
<a name="index-sublist_002f2-1"></a>
<a name="index-sublist_002f2-2"></a>
<p>True when both <code>append(_,Sublist,S)</code> and <code>append(S,_,List)</code> hold.
</p>
</dd>
<dt><code>suffix(?<var>Suffix</var>, ?<var>List</var>)</code></dt>
<dd><a name="index-suffix_002f2"></a>
<a name="index-suffix_002f2-1"></a>
<a name="index-suffix_002f2-2"></a>
<p>Holds when <code>append(_,Suffix,List)</code> holds.
</p>
</dd>
<dt><code>sum_list(?<var>Numbers</var>, ?<var>Total</var>)</code></dt>
<dd><a name="index-sum_005flist_002f2"></a>
<a name="index-sum_005flist_002f2-1"></a>
<a name="index-sum_005flist_002f2-2"></a>
<p>True when <var>Numbers</var> is a list of numbers, and <var>Total</var> is their sum.
</p>
</dd>
<dt><code>sum_list(?<var>Numbers</var>, +<var>SoFar</var>, ?<var>Total</var>)</code></dt>
<dd><a name="index-sum_005flist_002f3"></a>
<a name="index-sum_005flist_002f3-1"></a>
<a name="index-sum_005flist_002f3-2"></a>
<p>True when <var>Numbers</var> is a list of numbers, and <var>Total</var> is the sum of their total plus <var>SoFar</var>.
</p>
</dd>
<dt><code>sumlist(?<var>Numbers</var>, ?<var>Total</var>)</code></dt>
<dd><a name="index-sumlist_002f2"></a>
<a name="index-sumlist_002f2-1"></a>
<a name="index-sumlist_002f2-2"></a>
<p>True when <var>Numbers</var> is a list of integers, and <var>Total</var> is their
sum. The same as <code>sum_list/2</code>, please do use <code>sum_list/2</code>
instead.
</p>
</dd>
<dt><code>max_list(?<var>Numbers</var>, ?<var>Max</var>)</code></dt>
<dd><a name="index-max_005flist_002f2"></a>
<a name="index-max_005flist_002f2-1"></a>
<a name="index-max_005flist_002f2-2"></a>
<p>True when <var>Numbers</var> is a list of numbers, and <var>Max</var> is the maximum.
</p>
</dd>
<dt><code>min_list(?<var>Numbers</var>, ?<var>Min</var>)</code></dt>
<dd><a name="index-min_005flist_002f2"></a>
<a name="index-min_005flist_002f2-1"></a>
<a name="index-min_005flist_002f2-2"></a>
<p>True when <var>Numbers</var> is a list of numbers, and <var>Min</var> is the minimum.
</p>
</dd>
<dt><code>numlist(+<var>Low</var>, +<var>High</var>, +<var>List</var>)</code></dt>
<dd><a name="index-numlist_002f3"></a>
<a name="index-numlist_002f3-1"></a>
<a name="index-numlist_002f3-2"></a>
<p>If <var>Low</var> and <var>High</var> are integers with <var>Low</var> =&lt;
<var>High</var>, unify <var>List</var> to a list <code>[Low, Low+1, ...High]</code>. See
also <code>between/3</code>.
</p>
</dd>
<dt><code>intersection(+<var>Set1</var>, +<var>Set2</var>, +<var>Set3</var>)</code></dt>
<dd><a name="index-intersection_002f3"></a>
<a name="index-intersection_002f3-1"></a>
<a name="index-intersection_002f3-2"></a>
<p>Succeeds if <var>Set3</var> unifies with the intersection of <var>Set1</var> and
<var>Set2</var>. <var>Set1</var> and <var>Set2</var> are lists without duplicates. They
need not be ordered.
</p></dd>
</dl>
<hr>
<a name="LineUtilities"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Lists" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#MapList" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Line-Manipulation-Utilities"></a>
<h2 class="section">7.7 Line Manipulation Utilities</h2>
<a name="index-Line-Utilities-Library"></a>
<p>This package provides a set of useful predicates to manipulate
sequences of characters codes, usually first read in as a line. It is
available by loading the library <code>library(lineutils)</code>.
</p>
<dl compact="compact">
<dt><code>search_for(+<var>Char</var>,+<var>Line</var>)</code></dt>
<dd><a name="index-search_005ffor_002f2"></a>
<a name="index-search_005ffor_002f2-1"></a>
<a name="index-search_005ffor_002f2-2"></a>
<p>Search for a character <var>Char</var> in the list of codes <var>Line</var>.
</p>
</dd>
<dt><code>search_for(+<var>Char</var>,+<var>Line</var>)</code></dt>
<dd><a name="index-search_005ffor_002f2-3"></a>
<a name="index-search_005ffor_002f2-4"></a>
<a name="index-search_005ffor_002f2-5"></a>
<p>Search for a character <var>Char</var> in the list of codes <var>Line</var>.
</p>
</dd>
<dt><code>search_for(+<var>Char</var>,+<var>Line</var>,-<var>RestOfine</var>)</code></dt>
<dd><a name="index-search_005ffor_002f2-6"></a>
<a name="index-search_005ffor_002f2-7"></a>
<a name="index-search_005ffor_002f2-8"></a>
<p>Search for a character <var>Char</var> in the list of codes <var>Line</var>,
<var>RestOfLine</var> has the line to the right.
</p>
</dd>
<dt><code>scan_natural(?<var>Nat</var>,+<var>Line</var>,+<var>RestOfLine</var>)</code></dt>
<dd><a name="index-scan_005fnatural_002f3"></a>
<a name="index-scan_005fnatural_002f3-1"></a>
<a name="index-scan_005fnatural_002f3-2"></a>
<p>Scan the list of codes <var>Line</var> for a natural number <var>Nat</var>, zero
or a positive integer, and unify <var>RestOfLine</var> with the remainder
of the line.
</p>
</dd>
<dt><code>scan_integer(?<var>Int</var>,+<var>Line</var>,+<var>RestOfLine</var>)</code></dt>
<dd><a name="index-scan_005finteger_002f3"></a>
<a name="index-scan_005finteger_002f3-1"></a>
<a name="index-scan_005finteger_002f3-2"></a>
<p>Scan the list of codes <var>Line</var> for an integer <var>Nat</var>, either a
positive, zero, or negative integer, and unify <var>RestOfLine</var> with
the remainder of the line.
</p>
</dd>
<dt><code>split(+<var>Line</var>,+<var>Separators</var>,-<var>Split</var>)</code></dt>
<dd><a name="index-split_002f3"></a>
<a name="index-split_002f3-1"></a>
<a name="index-split_002f3-2"></a>
<p>Unify <var>Words</var> with a set of strings obtained from <var>Line</var> by
using the character codes in <var>Separators</var> as separators. As an
example, consider:
</p><div class="example">
<pre class="example">?- split(&quot;Hello * I am free&quot;,&quot; *&quot;,S).
S = [&quot;Hello&quot;,&quot;I&quot;,&quot;am&quot;,&quot;free&quot;] ?
no
</pre></div>
</dd>
<dt><code>split(+<var>Line</var>,-<var>Split</var>)</code></dt>
<dd><a name="index-split_002f2"></a>
<a name="index-split_002f2-1"></a>
<a name="index-split_002f2-2"></a>
<p>Unify <var>Words</var> with a set of strings obtained from <var>Line</var> by
using the blank characters as separators.
</p>
</dd>
<dt><code>fields(+<var>Line</var>,+<var>Separators</var>,-<var>Split</var>)</code></dt>
<dd><a name="index-fields_002f3"></a>
<a name="index-fields_002f3-1"></a>
<a name="index-fields_002f3-2"></a>
<p>Unify <var>Words</var> with a set of strings obtained from <var>Line</var> by
using the character codes in <var>Separators</var> as separators for
fields. If two separators occur in a row, the field is considered
empty. As an example, consider:
</p><div class="example">
<pre class="example">?- fields(&quot;Hello I am free&quot;,&quot; *&quot;,S).
S = [&quot;Hello&quot;,&quot;&quot;,&quot;I&quot;,&quot;am&quot;,&quot;&quot;,&quot;free&quot;] ?
</pre></div>
</dd>
<dt><code>fields(+<var>Line</var>,-<var>Split</var>)</code></dt>
<dd><a name="index-fields_002f2"></a>
<a name="index-fields_002f2-1"></a>
<a name="index-fields_002f2-2"></a>
<p>Unify <var>Words</var> with a set of strings obtained from <var>Line</var> by
using the blank characters as field separators.
</p>
</dd>
<dt><code>glue(+<var>Words</var>,+<var>Separator</var>,-<var>Line</var>)</code></dt>
<dd><a name="index-glue_002f3"></a>
<a name="index-glue_002f3-1"></a>
<a name="index-glue_002f3-2"></a>
<p>Unify <var>Line</var> with string obtained by glueing <var>Words</var> with
the character code <var>Separator</var>.
</p>
</dd>
<dt><code>copy_line(+<var>StreamInput</var>,+<var>StreamOutput</var>)</code></dt>
<dd><a name="index-copy_005fline_002f2"></a>
<a name="index-copy_005fline_002f2-1"></a>
<a name="index-copy_005fline_002f2-2"></a>
<p>Copy a line from <var>StreamInput</var> to <var>StreamOutput</var>.
</p>
</dd>
<dt><code>copy_line(+<var>StreamInput</var>,+<var>StreamOutput</var>)</code></dt>
<dd><a name="index-copy_005fline_002f2-3"></a>
<a name="index-copy_005fline_002f2-4"></a>
<a name="index-copy_005fline_002f2-5"></a>
<p>Copy a line from <var>StreamInput</var> to <var>StreamOutput</var>.
</p>
</dd>
<dt><code>process(+<var>StreamInp</var>, +<var>Goal</var>)</code></dt>
<dd><a name="index-process_002f2"></a>
<a name="index-process_002f2-1"></a>
<a name="index-process_002f2-2"></a>
<p>For every line <var>LineIn</var> in stream <var>StreamInp</var>, call
<code>call(Goal,LineIn)</code>.
</p>
</dd>
<dt><code>filter(+<var>StreamInp</var>, +<var>StreamOut</var>, +<var>Goal</var>)</code></dt>
<dd><a name="index-filter_002f3"></a>
<a name="index-filter_002f3-1"></a>
<a name="index-filter_002f3-2"></a>
<p>For every line <var>LineIn</var> in stream <var>StreamInp</var>, execute
<code>call(Goal,LineIn,LineOut)</code>, and output <var>LineOut</var> to
stream <var>StreamOut</var>.
</p>
</dd>
<dt><code>file_filter(+<var>FileIn</var>, +<var>FileOut</var>, +<var>Goal</var>)</code></dt>
<dd><a name="index-file_005ffilter_002f3"></a>
<a name="index-file_005ffilter_002f3-1"></a>
<a name="index-file_005ffilter_002f3-2"></a>
<p>For every line <var>LineIn</var> in file <var>FileIn</var>, execute
<code>call(Goal,LineIn,LineOut)</code>, and output <var>LineOut</var> to file
<var>FileOut</var>.
</p>
</dd>
<dt><code>file_filter(+<var>FileIn</var>, +<var>FileOut</var>, +<var>Goal</var>,</code></dt>
<dd><p>+<var>FormatCommand</var>, +<var>Arguments</var>)
<a name="index-file_005ffilter_005fwith_005finit_002f5"></a>
<a name="index-file_005ffilter_005fwith_005finit_002f5-1"></a>
<a name="index-file_005ffilter_005fwith_005finit_002f5-2"></a>
</p>
<p>Same as <code>file_filter/3</code>, but before starting the filter execute
<code>format/3</code> on the output stream, using <var>FormatCommand</var> and
<var>Arguments</var>.
</p>
</dd>
</dl>
<hr>
<a name="MapList"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#LineUtilities" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#matrix" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Maplist"></a>
<h2 class="section">7.8 Maplist</h2>
<a name="index-macros"></a>
<p>This library provides a set of utilities for applying a predicate to
all elements of a list or to all sub-terms of a term. They allow to
easily perform the most common do-loop constructs in Prolog. To avoid
performance degradation due to <code>apply/2</code>, each call creates an
equivalent Prolog program, without meta-calls, which is executed by
the Prolog engine instead. Note that if the equivalent Prolog program
already exists, it will be simply used. The library is based on code
by Joachim Schimpf and on code from SWI-Prolog.
</p>
<p>The following routines are available once included with the
<code>use_module(library(apply_macros))</code> command.
</p>
<dl compact="compact">
<dt><code>maplist(+<var>Pred</var>, ?<var>ListIn</var>, ?<var>ListOut</var>)</code></dt>
<dd><a name="index-maplist_002f3"></a>
<a name="index-maplist_002f3-1"></a>
<a name="index-maplist_002f3-2"></a>
<p> Creates <var>ListOut</var> by applying the predicate <var>Pred</var> to all
elements of <var>ListIn</var>.
</p>
</dd>
<dt><code>maplist(+<var>Pred</var>, ?<var>ListIn</var>)</code></dt>
<dd><a name="index-maplist_002f3-3"></a>
<a name="index-maplist_002f3-4"></a>
<a name="index-maplist_002f3-5"></a>
<p> Creates <var>ListOut</var> by applying the predicate <var>Pred</var> to all
elements of <var>ListIn</var>.
</p>
</dd>
<dt><code>maplist(+<var>Pred</var>, ?<var>L1</var>, ?<var>L2</var>, ?<var>L3</var>)</code></dt>
<dd><a name="index-maplist_002f4"></a>
<a name="index-maplist_002f4-1"></a>
<a name="index-maplist_002f4-2"></a>
<p> <var>L1</var>, <var>L2</var>, and <var>L3</var> are such that
<code>call(<var>Pred</var>,<var>A1</var>,<var>A2</var>,<var>A3</var>)</code> holds for every
corresponding element in lists <var>L1</var>, <var>L2</var>, and <var>L3</var>.
</p>
</dd>
<dt><code>maplist(+<var>Pred</var>, ?<var>L1</var>, ?<var>L2</var>, ?<var>L3</var>, ?<var>L4</var>)</code></dt>
<dd><a name="index-maplist_002f5"></a>
<a name="index-maplist_002f5-1"></a>
<a name="index-maplist_002f5-2"></a>
<p> <var>L1</var>, <var>L2</var>, <var>L3</var>, and <var>L4</var> are such that
<code>call(<var>Pred</var>,<var>A1</var>,<var>A2</var>,<var>A3</var>,<var>A4</var>)</code> holds
for every corresponding element in lists <var>L1</var>, <var>L2</var>, <var>L3</var>, and
<var>L4</var>.
</p>
</dd>
<dt><code>checklist(+<var>Pred</var>, +<var>List</var>)</code></dt>
<dd><a name="index-checklist_002f2"></a>
<a name="index-checklist_002f2-1"></a>
<a name="index-checklist_002f2-2"></a>
<p> Succeeds if the predicate <var>Pred</var> succeeds on all elements of <var>List</var>.
</p>
</dd>
<dt><code>selectlist(+<var>Pred</var>, +<var>ListIn</var>, ?<var>ListOut</var>)</code></dt>
<dd><a name="index-selectlist_002f3"></a>
<a name="index-selectlist_002f3-1"></a>
<a name="index-selectlist_002f3-2"></a>
<p> Creates <var>ListOut</var> of all list elements of <var>ListIn</var> that pass a given test
</p>
</dd>
<dt><code>convlist(+<var>Pred</var>, +<var>ListIn</var>, ?<var>ListOut</var>)</code></dt>
<dd><a name="index-convlist_002f3"></a>
<a name="index-convlist_002f3-1"></a>
<a name="index-convlist_002f3-2"></a>
<p> A combination of <code>maplist</code> and <code>selectlist</code>: creates <var>ListOut</var> by
applying the predicate <var>Pred</var> to all list elements on which
<var>Pred</var> succeeds
</p>
</dd>
<dt><code>sumlist(+<var>Pred</var>, +<var>List</var>, ?<var>AccIn</var>, ?<var>AccOut</var>)</code></dt>
<dd><a name="index-sumlist_002f4"></a>
<a name="index-sumlist_002f4-1"></a>
<a name="index-sumlist_002f4-2"></a>
<p> Calls <var>Pred</var> on all elements of List and collects a result in
<var>Accumulator</var>.
</p>
</dd>
<dt><code>mapargs(+<var>Pred</var>, ?<var>TermIn</var>, ?<var>TermOut</var>)</code></dt>
<dd><a name="index-mapargs_002f3"></a>
<a name="index-mapargs_002f3-1"></a>
<a name="index-mapargs_002f3-2"></a>
<p> Creates <var>TermOut</var> by applying the predicate <var>Pred</var> to all
arguments of <var>TermIn</var>
</p>
</dd>
<dt><code>sumargs(+<var>Pred</var>, +<var>Term</var>, ?<var>AccIn</var>, ?<var>AccOut</var>)</code></dt>
<dd><a name="index-sumargs_002f4"></a>
<a name="index-sumargs_002f4-1"></a>
<a name="index-sumargs_002f4-2"></a>
<p> Calls the predicate <var>Pred</var> on all arguments of <var>Term</var> and
collects a result in <var>Accumulator</var>
</p>
</dd>
<dt><code>mapnodes(+<var>Pred</var>, +<var>TermIn</var>, ?<var>TermOut</var>)</code></dt>
<dd><a name="index-mapnodes_002f3"></a>
<a name="index-mapnodes_002f3-1"></a>
<a name="index-mapnodes_002f3-2"></a>
<p> Creates <var>TermOut</var> by applying the predicate <var>Pred</var>
to all sub-terms of <var>TermIn</var> (depth-first and left-to-right order)
</p>
</dd>
<dt><code>checknodes(+<var>Pred</var>, +<var>Term</var>)</code></dt>
<dd><a name="index-checknodes_002f3"></a>
<a name="index-checknodes_002f3-1"></a>
<a name="index-checknodes_002f3-2"></a>
<p> Succeeds if the predicate <var>Pred</var> succeeds on all sub-terms of
<var>Term</var> (depth-first and left-to-right order)
</p>
</dd>
<dt><code>sumnodes(+<var>Pred</var>, +<var>Term</var>, ?<var>AccIn</var>, ?<var>AccOut</var>)</code></dt>
<dd><a name="index-sumnodes_002f4"></a>
<a name="index-sumnodes_002f4-1"></a>
<a name="index-sumnodes_002f4-2"></a>
<p> Calls the predicate <var>Pred</var> on all sub-terms of <var>Term</var> and
collect a result in <var>Accumulator</var> (depth-first and left-to-right
order)
</p>
</dd>
<dt><code>include(+<var>Pred</var>, +<var>ListIn</var>, ?<var>ListOut</var>)</code></dt>
<dd><a name="index-include_002f3"></a>
<a name="index-include_002f3-1"></a>
<a name="index-include_002f3-2"></a>
<p> Same as <code>selectlist/3</code>.
</p>
</dd>
<dt><code>exclude(+<var>Goal</var>, +<var>List1</var>, ?<var>List2</var>)</code></dt>
<dd><a name="index-exclude_002f3"></a>
<a name="index-exclude_002f3-1"></a>
<a name="index-exclude_002f3-2"></a>
<p>Filter elements for which <var>Goal</var> fails. True if <var>List2</var> contains
those elements <var>Xi</var> of <var>List1</var> for which <code>call(Goal, Xi)</code> fails.
</p>
</dd>
<dt><code>partition(+<var>Pred</var>, +<var>List1</var>, ?<var>Included</var>, ?<var>Excluded</var>)</code></dt>
<dd><a name="index-partition_002f4"></a>
<a name="index-partition_002f4-1"></a>
<a name="index-partition_002f4-2"></a>
<p>Filter elements of <var>List</var> according to <var>Pred</var>. True if
<var>Included</var> contains all elements for which <code>call(Pred, X)</code>
succeeds and <var>Excluded</var> contains the remaining elements.
</p>
</dd>
<dt><code>partition(+<var>Pred</var>, +<var>List1</var>, ?<var>Lesser</var>, ?<var>Equal</var>, ?<var>Greater</var>)</code></dt>
<dd><a name="index-partition_002f5"></a>
<a name="index-partition_002f5-1"></a>
<a name="index-partition_002f5-2"></a>
<p>Filter list according to <var>Pred</var> in three sets. For each element
<var>Xi</var> of <var>List</var>, its destination is determined by
<code>call(Pred, Xi, Place)</code>, where <var>Place</var> must be unified to one
of <code>&lt;</code>, <code>=</code> or <code>&gt;</code>. <code>Pred</code> must be deterministic.
</p>
</dd>
</dl>
<p>Examples:
</p>
<div class="example">
<pre class="example">%given
plus(X,Y,Z) :- Z is X + Y.
plus_if_pos(X,Y,Z) :- Y &gt; 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
maplist(plus(1), [1,2,3,4], [2,3,4,5]).
checklist(var, [X,Y,Z]).
selectlist(&lt;(0), [-1,0,1], [1]).
convlist(plus_if_pos(1), [-1,0,1], [2]).
sumlist(plus, [1,2,3,4], 1, 11).
mapargs(number_atom,s(1,2,3), s('1','2','3')).
sumargs(vars, s(1,X,2,Y), [], [Y,X]).
mapnodes(trans, p(a,p(b,a),c), q(a,q(b,a),c)).
checknodes(\==(T), p(X,p(Y,X),Z)).
sumnodes(vars, [c(X), p(X,Y), q(Y)], [], [Y,Y,X,X]).
% another one
maplist(mapargs(number_atom),[c(1),s(1,2,3)],[c('1'),s('1','2','3')]).
</pre></div>
<hr>
<a name="matrix"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MapList" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#MATLAB" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Matrix-Library"></a>
<h2 class="section">7.9 Matrix Library</h2>
<a name="index-Matrix-Library"></a>
<p>This package provides a fast implementation of multi-dimensional
matrices of integers and floats. In contrast to dynamic arrays, these
matrices are multi-dimensional and compact. In contrast to static
arrays. these arrays are allocated in the stack. Matrices are available
by loading the library <code>library(matrix)</code>.
</p>
<p>Notice that the functionality in this library is only partial. Please
contact the YAP maintainers if you require extra functionality.
</p>
<dl compact="compact">
<dt><code>matrix_new(+<var>Type</var>,+<var>Dims</var>,-<var>Matrix</var>)</code></dt>
<dd><a name="index-matrix_005fnew_002f3"></a>
<a name="index-matrix_005fnew_002f3-1"></a>
<a name="index-matrix_005fnew_002f3-2"></a>
<p>Create a new matrix <var>Matrix</var> of type <var>Type</var>, which may be one of
<code>ints</code> or <code>floats</code>, and with a list of dimensions <var>Dims</var>.
The matrix will be initialised to zeros.
</p>
<div class="example">
<pre class="example">?- matrix_new(ints,[2,3],Matrix).
Matrix = 0
</pre></div>
<p>Notice that currently YAP will always write a matrix as <code>0</code>.
</p>
</dd>
<dt><code>matrix_new(+<var>Type</var>,+<var>Dims</var>,+<var>List</var>,-<var>Matrix</var>)</code></dt>
<dd><a name="index-matrix_005fnew_002f4"></a>
<a name="index-matrix_005fnew_002f4-1"></a>
<a name="index-matrix_005fnew_002f4-2"></a>
<p>Create a new matrix <var>Matrix</var> of type <var>Type</var>, which may be one of
<code>ints</code> or <code>floats</code>, with dimensions <var>Dims</var>, and
initialised from list <var>List</var>.
</p>
</dd>
<dt><code>matrix_new_set(?<var>Dims</var>,+<var>OldMatrix</var>,+<var>Value</var>,-<var>NewMatrix</var>)</code></dt>
<dd><a name="index-matrix_005fnew_005fset_002f4"></a>
<a name="index-matrix_005fnew_005fset_002f4-1"></a>
<a name="index-matrix_005fnew_005fset_002f4-2"></a>
<p>Create a new matrix <var>NewMatrix</var> of type <var>Type</var>, with dimensions
<var>Dims</var>. The elements of <var>NewMatrix</var> are set to <var>Value</var>.
</p>
</dd>
<dt><code>matrix_dims(+<var>Matrix</var>,-<var>Dims</var>)</code></dt>
<dd><a name="index-matrix_005fdims_002f2"></a>
<a name="index-matrix_005fdims_002f2-1"></a>
<a name="index-matrix_005fdims_002f2-2"></a>
<p>Unify <var>Dims</var> with a list of dimensions for <var>Matrix</var>.
</p>
</dd>
<dt><code>matrix_ndims(+<var>Matrix</var>,-<var>Dims</var>)</code></dt>
<dd><a name="index-matrix_005fndims_002f2"></a>
<a name="index-matrix_005fndims_002f2-1"></a>
<a name="index-matrix_005fndims_002f2-2"></a>
<p>Unify <var>NDims</var> with the number of dimensions for <var>Matrix</var>.
</p>
</dd>
<dt><code>matrix_size(+<var>Matrix</var>,-<var>NElems</var>)</code></dt>
<dd><a name="index-matrix_005fsize_002f2"></a>
<a name="index-matrix_005fsize_002f2-1"></a>
<a name="index-matrix_005fsize_002f2-2"></a>
<p>Unify <var>NElems</var> with the number of elements for <var>Matrix</var>.
</p>
</dd>
<dt><code>matrix_type(+<var>Matrix</var>,-<var>Type</var>)</code></dt>
<dd><a name="index-matrix_005ftype_002f2"></a>
<a name="index-matrix_005ftype_002f2-1"></a>
<a name="index-matrix_005ftype_002f2-2"></a>
<p>Unify <var>NElems</var> with the type of the elements in <var>Matrix</var>.
</p>
</dd>
<dt><code>matrix_to_list(+<var>Matrix</var>,-<var>Elems</var>)</code></dt>
<dd><a name="index-matrix_005fto_005flist_002f2"></a>
<a name="index-matrix_005fto_005flist_002f2-1"></a>
<a name="index-matrix_005fto_005flist_002f2-2"></a>
<p>Unify <var>Elems</var> with the list including all the elements in <var>Matrix</var>.
</p>
</dd>
<dt><code>matrix_get(+<var>Matrix</var>,+<var>Position</var>,-<var>Elem</var>)</code></dt>
<dd><a name="index-matrix_005fget_002f3"></a>
<a name="index-matrix_005fget_002f3-1"></a>
<a name="index-matrix_005fget_002f3-2"></a>
<p>Unify <var>Elem</var> with the element of <var>Matrix</var> at position
<var>Position</var>.
</p>
</dd>
<dt><code>matrix_set(+<var>Matrix</var>,+<var>Position</var>,+<var>Elem</var>)</code></dt>
<dd><a name="index-matrix_005fset_002f3"></a>
<a name="index-matrix_005fset_002f3-1"></a>
<a name="index-matrix_005fset_002f3-2"></a>
<p>Set the element of <var>Matrix</var> at position
<var>Position</var> to <var>Elem</var>.
</p>
</dd>
<dt><code>matrix_set_all(+<var>Matrix</var>,+<var>Elem</var>)</code></dt>
<dd><a name="index-matrix_005fset_005fall_002f2"></a>
<a name="index-matrix_005fset_005fall_002f2-1"></a>
<a name="index-matrix_005fset_005fall_002f2-2"></a>
<p>Set all element of <var>Matrix</var> to <var>Elem</var>.
</p>
</dd>
<dt><code>matrix_add(+<var>Matrix</var>,+<var>Position</var>,+<var>Operand</var>)</code></dt>
<dd><a name="index-matrix_005fadd_002f3"></a>
<a name="index-matrix_005fadd_002f3-1"></a>
<a name="index-matrix_005fadd_002f3-2"></a>
<p>Add <var>Operand</var> to the element of <var>Matrix</var> at position
<var>Position</var>.
</p>
</dd>
<dt><code>matrix_inc(+<var>Matrix</var>,+<var>Position</var>)</code></dt>
<dd><a name="index-matrix_005finc_002f2"></a>
<a name="index-matrix_005finc_002f2-1"></a>
<a name="index-matrix_005finc_002f2-2"></a>
<p>Increment the element of <var>Matrix</var> at position <var>Position</var>.
</p>
</dd>
<dt><code>matrix_inc(+<var>Matrix</var>,+<var>Position</var>,-<var>Element</var>)</code></dt>
<dd><a name="index-matrix_005finc_002f3"></a>
<a name="index-matrix_005finc_002f3-1"></a>
<a name="index-matrix_005finc_002f3-2"></a>
<p>Increment the element of <var>Matrix</var> at position <var>Position</var> and
unify with <var>Element</var>.
</p>
</dd>
<dt><code>matrix_dec(+<var>Matrix</var>,+<var>Position</var>)</code></dt>
<dd><a name="index-matrix_005fdec_002f2"></a>
<a name="index-matrix_005fdec_002f2-1"></a>
<a name="index-matrix_005fdec_002f2-2"></a>
<p>Decrement the element of <var>Matrix</var> at position <var>Position</var>.
</p>
</dd>
<dt><code>matrix_dec(+<var>Matrix</var>,+<var>Position</var>,-<var>Element</var>)</code></dt>
<dd><a name="index-matrix_005fdec_002f3"></a>
<a name="index-matrix_005fdec_002f3-1"></a>
<a name="index-matrix_005fdec_002f3-2"></a>
<p>Decrement the element of <var>Matrix</var> at position <var>Position</var> and
unify with <var>Element</var>.
</p>
</dd>
<dt><code>matrix_arg_to_offset(+<var>Matrix</var>,+<var>Position</var>,-<var>Offset</var>)</code></dt>
<dd><a name="index-matrix_005farg_005fto_005foffset_002f3"></a>
<a name="index-matrix_005farg_005fto_005foffset_002f3-1"></a>
<a name="index-matrix_005farg_005fto_005foffset_002f3-2"></a>
<p>Given matrix <var>Matrix</var> return what is the numerical <var>Offset</var> of
the element at <var>Position</var>.
</p>
</dd>
<dt><code>matrix_offset_to_arg(+<var>Matrix</var>,-<var>Offset</var>,+<var>Position</var>)</code></dt>
<dd><a name="index-matrix_005foffset_005fto_005farg_002f3"></a>
<a name="index-matrix_005foffset_005fto_005farg_002f3-1"></a>
<a name="index-matrix_005foffset_005fto_005farg_002f3-2"></a>
<p>Given a position <var>Position </var> for matrix <var>Matrix</var> return the
corresponding numerical <var>Offset</var> from the beginning of the matrix.
</p>
</dd>
<dt><code>matrix_max(+<var>Matrix</var>,+<var>Max</var>)</code></dt>
<dd><a name="index-matrix_005fmax_002f2"></a>
<a name="index-matrix_005fmax_002f2-1"></a>
<a name="index-matrix_005fmax_002f2-2"></a>
<p>Unify <var>Max</var> with the maximum in matrix <var>Matrix</var>.
</p>
</dd>
<dt><code>matrix_maxarg(+<var>Matrix</var>,+<var>Maxarg</var>)</code></dt>
<dd><a name="index-matrix_005fmaxarg_002f2"></a>
<a name="index-matrix_005fmaxarg_002f2-1"></a>
<a name="index-matrix_005fmaxarg_002f2-2"></a>
<p>Unify <var>Max</var> with the position of the maximum in matrix <var>Matrix</var>.
</p>
</dd>
<dt><code>matrix_min(+<var>Matrix</var>,+<var>Min</var>)</code></dt>
<dd><a name="index-matrix_005fmin_002f2"></a>
<a name="index-matrix_005fmin_002f2-1"></a>
<a name="index-matrix_005fmin_002f2-2"></a>
<p>Unify <var>Min</var> with the minimum in matrix <var>Matrix</var>.
</p>
</dd>
<dt><code>matrix_minarg(+<var>Matrix</var>,+<var>Minarg</var>)</code></dt>
<dd><a name="index-matrix_005fminarg_002f2"></a>
<a name="index-matrix_005fminarg_002f2-1"></a>
<a name="index-matrix_005fminarg_002f2-2"></a>
<p>Unify <var>Min</var> with the position of the minimum in matrix <var>Matrix</var>.
</p>
</dd>
<dt><code>matrix_sum(+<var>Matrix</var>,+<var>Sum</var>)</code></dt>
<dd><a name="index-matrix_005fsum_002f2"></a>
<a name="index-matrix_005fsum_002f2-1"></a>
<a name="index-matrix_005fsum_002f2-2"></a>
<p>Unify <var>Sum</var> with the sum of all elements in matrix <var>Matrix</var>.
</p>
</dd>
<dt><code>matrix_agg_lines(+<var>Matrix</var>,+<var>Aggregate</var>)</code></dt>
<dd><a name="index-matrix_005fagg_005flines_002f2"></a>
<a name="index-matrix_005fagg_005flines_002f2-1"></a>
<a name="index-matrix_005fagg_005flines_002f2-2"></a>
<p>If <var>Matrix</var> is a n-dimensional matrix, unify <var>Aggregate</var> with
the n-1 dimensional matrix where each element is obtained by adding all
Matrix elements with same last n-1 index.
</p>
</dd>
<dt><code>matrix_agg_cols(+<var>Matrix</var>,+<var>Aggregate</var>)</code></dt>
<dd><a name="index-matrix_005fagg_005fcols_002f2"></a>
<a name="index-matrix_005fagg_005fcols_002f2-1"></a>
<a name="index-matrix_005fagg_005fcols_002f2-2"></a>
<p>If <var>Matrix</var> is a n-dimensional matrix, unify <var>Aggregate</var> with
the one dimensional matrix where each element is obtained by adding all
Matrix elements with same first index.
</p>
</dd>
<dt><code>matrix_op(+<var>Matrix1</var>,+<var>Matrix2</var>,+<var>Op</var>,-<var>Result</var>)</code></dt>
<dd><a name="index-matrix_005fop_002f4"></a>
<a name="index-matrix_005fop_002f4-1"></a>
<a name="index-matrix_005fop_002f4-2"></a>
<p><var>Result</var> is the result of applying <var>Op</var> to matrix <var>Matrix1</var>
and <var>Matrix2</var>. Currently, only addition (<code>+</code>) is supported.
</p>
</dd>
<dt><code>matrix_op_to_all(+<var>Matrix1</var>,+<var>Op</var>,+<var>Operand</var>,-<var>Result</var>)</code></dt>
<dd><a name="index-matrix_005fop_002f4-3"></a>
<a name="index-matrix_005fop_002f4-4"></a>
<a name="index-matrix_005fop_002f4-5"></a>
<p><var>Result</var> is the result of applying <var>Op</var> to all elements of
<var>Matrix1</var>, with <var>Operand</var> as the second argument. Currently,
only addition (<code>+</code>), multiplication (<code>+</code>), and division
(<code>/</code>) are supported.
</p>
</dd>
<dt><code>matrix_op_to_lines(+<var>Matrix1</var>,+<var>Lines</var>,+<var>Op</var>,-<var>Result</var>)</code></dt>
<dd><a name="index-matrix_005fop_005fto_005flines_002f4"></a>
<a name="index-matrix_005fop_005fto_005flines_002f4-1"></a>
<a name="index-matrix_005fop_005fto_005flines_002f4-2"></a>
<p><var>Result</var> is the result of applying <var>Op</var> to all elements of
<var>Matrix1</var>, with the corresponding element in <var>Lines</var> as the
second argument. Currently, only division (<code>/</code>) is supported.
</p>
</dd>
<dt><code>matrix_op_to_cols(+<var>Matrix1</var>,+<var>Cols</var>,+<var>Op</var>,-<var>Result</var>)</code></dt>
<dd><a name="index-matrix_005fop_005fto_005fcols_002f4"></a>
<a name="index-matrix_005fop_005fto_005fcols_002f4-1"></a>
<a name="index-matrix_005fop_005fto_005fcols_002f4-2"></a>
<p><var>Result</var> is the result of applying <var>Op</var> to all elements of
<var>Matrix1</var>, with the corresponding element in <var>Cols</var> as the
second argument. Currently, only addition (<code>+</code>) is
supported. Notice that <var>Cols</var> will have n-1 dimensions.
</p>
</dd>
<dt><code>matrix_shuffle(+<var>Matrix</var>,+<var>NewOrder</var>,-<var>Shuffle</var>)</code></dt>
<dd><a name="index-matrix_005fshuffle_002f3"></a>
<a name="index-matrix_005fshuffle_002f3-1"></a>
<a name="index-matrix_005fshuffle_002f3-2"></a>
<p>Shuffle the dimensions of matrix <var>Matrix</var> according to
<var>NewOrder</var>. The list <var>NewOrder</var> must have all the dimensions of
<var>Matrix</var>, starting from 0.
</p>
</dd>
<dt><code>matrix_transpose(+<var>Matrix</var>,-<var>Transpose</var>)</code></dt>
<dd><a name="index-matrix_005freorder_002f3"></a>
<a name="index-matrix_005freorder_002f3-1"></a>
<a name="index-matrix_005freorder_002f3-2"></a>
<p>Transpose matrix <var>Matrix</var> to <var>Transpose</var>. Equivalent to:
</p><div class="example">
<pre class="example">matrix_transpose(Matrix,Transpose) :-
matrix_shuffle(Matrix,[1,0],Transpose).
</pre></div>
</dd>
<dt><code>matrix_expand(+<var>Matrix</var>,+<var>NewDimensions</var>,-<var>New</var>)</code></dt>
<dd><a name="index-matrix_005fexpand_002f3"></a>
<a name="index-matrix_005fexpand_002f3-1"></a>
<a name="index-matrix_005fexpand_002f3-2"></a>
<p>Expand <var>Matrix</var> to occupy new dimensions. The elements in
<var>NewDimensions</var> are either 0, for an existing dimension, or a
positive integer with the size of the new dimension.
</p>
</dd>
<dt><code>matrix_select(+<var>Matrix</var>,+<var>Dimension</var>,+<var>Index</var>,-<var>New</var>)</code></dt>
<dd><a name="index-matrix_005fselect_002f4"></a>
<a name="index-matrix_005fselect_002f4-1"></a>
<a name="index-matrix_005fselect_002f4-2"></a>
<p>Select from <var>Matrix</var> the elements who have <var>Index</var> at
<var>Dimension</var>.
</p>
</dd>
<dt><code>matrix_row(+<var>Matrix</var>,+<var>Column</var>,-<var>NewMatrix</var>)</code></dt>
<dd><a name="index-matrix_005frow_002f3"></a>
<a name="index-matrix_005frow_002f3-1"></a>
<a name="index-matrix_005frow_002f3-2"></a>
<p>Select from <var>Matrix</var> the row matching <var>Column</var> as new matrix <var>NewMatrix</var>. <var>Column</var> must have one less dimension than the original matrix.
<var>Dimension</var>.
</p>
</dd>
</dl>
<hr>
<a name="MATLAB"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#matrix" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Non_002dBacktrackable-Data-Structures" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="MATLAB-Package-Interface"></a>
<h2 class="section">7.10 MATLAB Package Interface</h2>
<a name="index-Matlab-Interface"></a>
<p>The MathWorks MATLAB is a widely used package for array
processing. YAP now includes a straightforward interface to MATLAB. To
actually use it, you need to install YAP calling <code>configure</code> with
the <code>--with-matlab=DIR</code> option, and you need to call
<code>use_module(library(lists))</code> command.
</p>
<p>Accessing the matlab dynamic libraries can be complicated. In Linux
machines, to use this interface, you may have to set the environment
variable <tt>LD_LIBRARY_PATH</tt>. Next, follows an example using bash in a
64-bit Linux PC:
</p><div class="example">
<pre class="example">export LD_LIBRARY_PATH=''$MATLAB_HOME&quot;/sys/os/glnxa64:''$MATLAB_HOME&quot;/bin/glnxa64:''$LD_LIBRARY_PATH&quot;
</pre></div>
<p>where <code>MATLAB_HOME</code> is the directory where matlab is installed
at. Please replace <code>ax64</code> for <code>x86</code> on a 32-bit PC.
</p>
<dl compact="compact">
<dt><code>start_matlab(+<var>Options</var>)</code></dt>
<dd><a name="index-start_005fmatlab_002f1"></a>
<a name="index-start_005fmatlab_002f1-1"></a>
<a name="index-start_005fmatlab_002f1-2"></a>
<p>Start a matlab session. The argument <var>Options</var> may either be the
empty string/atom or the command to call matlab. The command may fail.
</p>
</dd>
<dt><code>close_matlab</code></dt>
<dd><a name="index-close_005fmatlab_002f0"></a>
<a name="index-close_005fmatlab_002f0-1"></a>
<a name="index-close_005fmatlab_002f0-2"></a>
<p>Stop the current matlab session.
</p>
</dd>
<dt><code>matlab_on</code></dt>
<dd><a name="index-matlab_005fon_002f0"></a>
<a name="index-matlab_005fon_002f0-1"></a>
<a name="index-matlab_005fon_002f0-2"></a>
<p>Holds if a matlab session is on.
</p>
</dd>
<dt><code>matlab_eval_string(+<var>Command</var>)</code></dt>
<dd><a name="index-matlab_005feval_005fstring_002f1"></a>
<a name="index-matlab_005feval_005fstring_002f1-1"></a>
<a name="index-matlab_005feval_005fstring_002f1-2"></a>
<p>Holds if matlab evaluated successfully the command <var>Command</var>.
</p>
</dd>
<dt><code>matlab_eval_string(+<var>Command</var>, -<var>Answer</var>)</code></dt>
<dd><a name="index-matlab_005feval_005fstring_002f2"></a>
<a name="index-matlab_005feval_005fstring_002f2-1"></a>
<a name="index-matlab_005feval_005fstring_002f2-2"></a>
<p>MATLAB will evaluate the command <var>Command</var> and unify <var>Answer</var>
with a string reporting the result.
</p>
</dd>
<dt><code>matlab_cells(+<var>Size</var>, ?<var>Array</var>)</code></dt>
<dd><a name="index-matlab_005fcells_002f2"></a>
<a name="index-matlab_005fcells_002f2-1"></a>
<a name="index-matlab_005fcells_002f2-2"></a>
<p>MATLAB will create an empty vector of cells of size <var>Size</var>, and if
<var>Array</var> is bound to an atom, store the array in the matlab
variable with name <var>Array</var>. Corresponds to the MATLAB command <code>cells</code>.
</p>
</dd>
<dt><code>matlab_cells(+<var>SizeX</var>, +<var>SizeY</var>, ?<var>Array</var>)</code></dt>
<dd><a name="index-matlab_005fcells_002f3"></a>
<a name="index-matlab_005fcells_002f3-1"></a>
<a name="index-matlab_005fcells_002f3-2"></a>
<p>MATLAB will create an empty array of cells of size <var>SizeX</var> and
<var>SizeY</var>, and if <var>Array</var> is bound to an atom, store the array
in the matlab variable with name <var>Array</var>. Corresponds to the
MATLAB command <code>cells</code>.
</p>
</dd>
<dt><code>matlab_initialized_cells(+<var>SizeX</var>, +<var>SizeY</var>, +<var>List</var>, ?<var>Array</var>)</code></dt>
<dd><a name="index-matlab_005finitialized_005fcells_002f4"></a>
<a name="index-matlab_005finitialized_005fcells_002f4-1"></a>
<a name="index-matlab_005finitialized_005fcells_002f4-2"></a>
<p>MATLAB will create an array of cells of size <var>SizeX</var> and
<var>SizeY</var>, initialized from the list <var>List</var>, and if <var>Array</var>
is bound to an atom, store the array in the matlab variable with name
<var>Array</var>.
</p>
</dd>
<dt><code>matlab_matrix(+<var>SizeX</var>, +<var>SizeY</var>, +<var>List</var>, ?<var>Array</var>)</code></dt>
<dd><a name="index-matlab_005fmatrix_002f4"></a>
<a name="index-matlab_005fmatrix_002f4-1"></a>
<a name="index-matlab_005fmatrix_002f4-2"></a>
<p>MATLAB will create an array of floats of size <var>SizeX</var> and <var>SizeY</var>,
initialized from the list <var>List</var>, and if <var>Array</var> is bound to
an atom, store the array in the matlab variable with name <var>Array</var>.
</p>
</dd>
<dt><code>matlab_set(+<var>MatVar</var>, +<var>X</var>, +<var>Y</var>, +<var>Value</var>)</code></dt>
<dd><a name="index-matlab_005fset_002f4"></a>
<a name="index-matlab_005fset_002f4-1"></a>
<a name="index-matlab_005fset_002f4-2"></a>
<p>Call MATLAB to set element <var>MatVar</var>(<var>X</var>, <var>Y</var>) to
<var>Value</var>. Notice that this command uses the MATLAB array access
convention.
</p>
</dd>
<dt><code>matlab_get_variable(+<var>MatVar</var>, -<var>List</var>)</code></dt>
<dd><a name="index-matlab_005fget_005fvariable_002f2"></a>
<a name="index-matlab_005fget_005fvariable_002f2-1"></a>
<a name="index-matlab_005fget_005fvariable_002f2-2"></a>
<p>Unify MATLAB variable <var>MatVar</var> with the List <var>List</var>.
</p>
</dd>
<dt><code>matlab_item(+<var>MatVar</var>, +<var>X</var>, ?<var>Val</var>)</code></dt>
<dd><a name="index-matlab_005fitem_002f3"></a>
<a name="index-matlab_005fitem_002f3-1"></a>
<a name="index-matlab_005fitem_002f3-2"></a>
<p>Read or set MATLAB <var>MatVar</var>(<var>X</var>) from/to <var>Val</var>. Use
<code>C</code> notation for matrix access (ie, starting from 0).
</p>
</dd>
<dt><code>matlab_item(+<var>MatVar</var>, +<var>X</var>, +<var>Y</var>, ?<var>Val</var>)</code></dt>
<dd><a name="index-matlab_005fitem_002f4"></a>
<a name="index-matlab_005fitem_002f4-1"></a>
<a name="index-matlab_005fitem_002f4-2"></a>
<p>Read or set MATLAB <var>MatVar</var>(<var>X</var>,<var>Y</var>) from/to <var>Val</var>. Use
<code>C</code> notation for matrix access (ie, starting from 0).
</p>
</dd>
<dt><code>matlab_item1(+<var>MatVar</var>, +<var>X</var>, ?<var>Val</var>)</code></dt>
<dd><a name="index-matlab_005fitem_002f3-3"></a>
<a name="index-matlab_005fitem_002f3-4"></a>
<a name="index-matlab_005fitem_002f3-5"></a>
<p>Read or set MATLAB <var>MatVar</var>(<var>X</var>) from/to <var>Val</var>. Use
MATLAB notation for matrix access (ie, starting from 1).
</p>
</dd>
<dt><code>matlab_item1(+<var>MatVar</var>, +<var>X</var>, +<var>Y</var>, ?<var>Val</var>)</code></dt>
<dd><a name="index-matlab_005fitem_002f4-3"></a>
<a name="index-matlab_005fitem_002f4-4"></a>
<a name="index-matlab_005fitem_002f4-5"></a>
<p>Read or set MATLAB <var>MatVar</var>(<var>X</var>,<var>Y</var>) from/to <var>Val</var>. Use
MATLAB notation for matrix access (ie, starting from 1).
</p>
</dd>
<dt><code>matlab_sequence(+<var>Min</var>, +<var>Max</var>, ?<var>Array</var>)</code></dt>
<dd><a name="index-matlab_005fsequence_002f3"></a>
<a name="index-matlab_005fsequence_002f3-1"></a>
<a name="index-matlab_005fsequence_002f3-2"></a>
<p>MATLAB will create a sequence going from <var>Min</var> to <var>Max</var>, and
if <var>Array</var> is bound to an atom, store the sequence in the matlab
variable with name <var>Array</var>.
</p>
</dd>
<dt><code>matlab_vector(+<var>Size</var>, +<var>List</var>, ?<var>Array</var>)</code></dt>
<dd><a name="index-matlab_005fvector_002f4"></a>
<a name="index-matlab_005fvector_002f4-1"></a>
<a name="index-matlab_005fvector_002f4-2"></a>
<p>MATLAB will create a vector of floats of size <var>Size</var>, initialized
from the list <var>List</var>, and if <var>Array</var> is bound to an atom,
store the array in the matlab variable with name <var>Array</var>.
</p>
</dd>
<dt><code>matlab_zeros(+<var>Size</var>, ?<var>Array</var>)</code></dt>
<dd><a name="index-matlab_005fzeros_002f2"></a>
<a name="index-matlab_005fzeros_002f2-1"></a>
<a name="index-matlab_005fzeros_002f2-2"></a>
<p>MATLAB will create a vector of zeros of size <var>Size</var>, and if
<var>Array</var> is bound to an atom, store the array in the matlab
variable with name <var>Array</var>. Corresponds to the MATLAB command
<code>zeros</code>.
</p>
</dd>
<dt><code>matlab_zeros(+<var>SizeX</var>, +<var>SizeY</var>, ?<var>Array</var>)</code></dt>
<dd><a name="index-matlab_005fzeros_002f3"></a>
<a name="index-matlab_005fzeros_002f3-1"></a>
<a name="index-matlab_005fzeros_002f3-2"></a>
<p>MATLAB will create an array of zeros of size <var>SizeX</var> and
<var>SizeY</var>, and if <var>Array</var> is bound to an atom, store the array
in the matlab variable with name <var>Array</var>. Corresponds to the
MATLAB command <code>zeros</code>.
</p>
</dd>
<dt><code>matlab_zeros(+<var>SizeX</var>, +<var>SizeY</var>, +<var>SizeZ</var>, ?<var>Array</var>)</code></dt>
<dd><a name="index-matlab_005fzeros_002f4"></a>
<a name="index-matlab_005fzeros_002f4-1"></a>
<a name="index-matlab_005fzeros_002f4-2"></a>
<p>MATLAB will create an array of zeros of size <var>SizeX</var>, <var>SizeY</var>,
and <var>SizeZ</var>. If <var>Array</var> is bound to an atom, store the array
in the matlab variable with name <var>Array</var>. Corresponds to the
MATLAB command <code>zeros</code>.
</p>
</dd>
<dt><code>matlab_zeros(+<var>SizeX</var>, +<var>SizeY</var>, +<var>SizeZ</var>, ?<var>Array</var>)</code></dt>
<dd><a name="index-matlab_005fzeros_002f4-3"></a>
<a name="index-matlab_005fzeros_002f4-4"></a>
<a name="index-matlab_005fzeros_002f4-5"></a>
<p>MATLAB will create an array of zeros of size <var>SizeX</var>, <var>SizeY</var>,
and <var>SizeZ</var>. If <var>Array</var> is bound to an atom, store the array
in the matlab variable with name <var>Array</var>. Corresponds to the
MATLAB command <code>zeros</code>.
</p>
</dd>
</dl>
<hr>
<a name="Non_002dBacktrackable-Data-Structures"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MATLAB" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Ordered-Sets" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Non_002dBacktrackable-Data-Structures-1"></a>
<h2 class="section">7.11 Non-Backtrackable Data Structures</h2>
<p>The following routines implement well-known data-structures using global
non-backtrackable variables (implemented on the Prolog stack). The
data-structures currently supported are Queues, Heaps, and Beam for Beam
search. They are allowed through <code>library(nb)</code>.
</p>
<dl compact="compact">
<dt><code>nb_queue(-<var>Queue</var>)</code></dt>
<dd><a name="index-nb_005fqueue_002f1"></a>
<a name="index-nb_005fqueue_002f1-1"></a>
<a name="index-nb_005fqueue_002f1-2"></a>
<p>Create a <var>Queue</var>.
</p>
</dd>
<dt><code>nb_queue_close(+<var>Queue</var>, -<var>Head</var>, ?<var>Tail</var>)</code></dt>
<dd><a name="index-nb_005fqueue_005fclose_002f3"></a>
<a name="index-nb_005fqueue_005fclose_002f3-1"></a>
<a name="index-nb_005fqueue_005fclose_002f3-2"></a>
<p>Unify the queue <var>Queue</var> with a difference list
<var>Head</var>-<var>Tail</var>. The queue will now be empty and no further
elements can be added.
</p>
</dd>
<dt><code>nb_queue_enqueue(+<var>Queue</var>, +<var>Element</var>)</code></dt>
<dd><a name="index-nb_005fqueue_005fenqueue_002f2"></a>
<a name="index-nb_005fqueue_005fenqueue_002f2-1"></a>
<a name="index-nb_005fqueue_005fenqueue_002f2-2"></a>
<p>Add <var>Element</var> to the front of the queue <var>Queue</var>.
</p>
</dd>
<dt><code>nb_queue_dequeue(+<var>Queue</var>, -<var>Element</var>)</code></dt>
<dd><a name="index-nb_005fqueue_005fdequeue_002f2"></a>
<a name="index-nb_005fqueue_005fdequeue_002f2-1"></a>
<a name="index-nb_005fqueue_005fdequeue_002f2-2"></a>
<p>Remove <var>Element</var> from the front of the queue <var>Queue</var>. Fail if
the queue is empty.
</p>
</dd>
<dt><code>nb_queue_peek(+<var>Queue</var>, -<var>Element</var>)</code></dt>
<dd><a name="index-nb_005fqueue_005fpeek_002f2"></a>
<a name="index-nb_005fqueue_005fpeek_002f2-1"></a>
<a name="index-nb_005fqueue_005fpeek_002f2-2"></a>
<p><var>Element</var> is the front of the queue <var>Queue</var>. Fail if
the queue is empty.
</p>
</dd>
<dt><code>nb_queue_size(+<var>Queue</var>, -<var>Size</var>)</code></dt>
<dd><a name="index-nb_005fqueue_005fsize_002f2"></a>
<a name="index-nb_005fqueue_005fsize_002f2-1"></a>
<a name="index-nb_005fqueue_005fsize_002f2-2"></a>
<p>Unify <var>Size</var> with the number of elements in the queue <var>Queue</var>.
</p>
</dd>
<dt><code>nb_queue_empty(+<var>Queue</var>)</code></dt>
<dd><a name="index-nb_005fqueue_005fempty_002f1"></a>
<a name="index-nb_005fqueue_005fempty_002f1-1"></a>
<a name="index-nb_005fqueue_005fempty_002f1-2"></a>
<p>Succeeds if <var>Queue</var> is empty.
</p>
</dd>
<dt><code>nb_heap(+<var>DefaultSize</var>,-<var>Heap</var>)</code></dt>
<dd><a name="index-nb_005fheap_002f1"></a>
<a name="index-nb_005fheap_002f1-1"></a>
<a name="index-nb_005fheap_002f1-2"></a>
<p>Create a <var>Heap</var> with default size <var>DefaultSize</var>. Note that size
will expand as needed.
</p>
</dd>
<dt><code>nb_heap_close(+<var>Heap</var>)</code></dt>
<dd><a name="index-nb_005fheap_005fclose_002f1"></a>
<a name="index-nb_005fheap_005fclose_002f1-1"></a>
<a name="index-nb_005fheap_005fclose_002f1-2"></a>
<p>Close the heap <var>Heap</var>: no further elements can be added.
</p>
</dd>
<dt><code>nb_heap_add(+<var>Heap</var>, +<var>Key</var>, +<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fheap_005fadd_002f3"></a>
<a name="index-nb_005fheap_005fadd_002f3-1"></a>
<a name="index-nb_005fheap_005fadd_002f3-2"></a>
<p>Add <var>Key</var>-<var>Value</var> to the heap <var>Heap</var>. The key is sorted on
<var>Key</var> only.
</p>
</dd>
<dt><code>nb_heap_del(+<var>Heap</var>, -<var>Key</var>, -<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fheap_005fdel_002f3"></a>
<a name="index-nb_005fheap_005fdel_002f3-1"></a>
<a name="index-nb_005fheap_005fdel_002f3-2"></a>
<p>Remove element <var>Key</var>-<var>Value</var> with smallest <var>Value</var> in heap
<var>Heap</var>. Fail if the heap is empty.
</p>
</dd>
<dt><code>nb_heap_peek(+<var>Heap</var>, -<var>Key</var>, -<var>Value</var>))</code></dt>
<dd><a name="index-nb_005fheap_005fpeek_002f3"></a>
<a name="index-nb_005fheap_005fpeek_002f3-1"></a>
<a name="index-nb_005fheap_005fpeek_002f3-2"></a>
<p><var>Key</var>-<var>Value</var> is the element with smallest <var>Key</var> in the heap
<var>Heap</var>. Fail if the heap is empty.
</p>
</dd>
<dt><code>nb_heap_size(+<var>Heap</var>, -<var>Size</var>)</code></dt>
<dd><a name="index-nb_005fheap_005fsize_002f2"></a>
<a name="index-nb_005fheap_005fsize_002f2-1"></a>
<a name="index-nb_005fheap_005fsize_002f2-2"></a>
<p>Unify <var>Size</var> with the number of elements in the heap <var>Heap</var>.
</p>
</dd>
<dt><code>nb_heap_empty(+<var>Heap</var>)</code></dt>
<dd><a name="index-nb_005fheap_005fempty_002f1"></a>
<a name="index-nb_005fheap_005fempty_002f1-1"></a>
<a name="index-nb_005fheap_005fempty_002f1-2"></a>
<p>Succeeds if <var>Heap</var> is empty.
</p>
</dd>
<dt><code>nb_beam(+<var>DefaultSize</var>,-<var>Beam</var>)</code></dt>
<dd><a name="index-nb_005fbeam_002f1"></a>
<a name="index-nb_005fbeam_002f1-1"></a>
<a name="index-nb_005fbeam_002f1-2"></a>
<p>Create a <var>Beam</var> with default size <var>DefaultSize</var>. Note that size
is fixed throughout.
</p>
</dd>
<dt><code>nb_beam_close(+<var>Beam</var>)</code></dt>
<dd><a name="index-nb_005fbeam_005fclose_002f1"></a>
<a name="index-nb_005fbeam_005fclose_002f1-1"></a>
<a name="index-nb_005fbeam_005fclose_002f1-2"></a>
<p>Close the beam <var>Beam</var>: no further elements can be added.
</p>
</dd>
<dt><code>nb_beam_add(+<var>Beam</var>, +<var>Key</var>, +<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fbeam_005fadd_002f3"></a>
<a name="index-nb_005fbeam_005fadd_002f3-1"></a>
<a name="index-nb_005fbeam_005fadd_002f3-2"></a>
<p>Add <var>Key</var>-<var>Value</var> to the beam <var>Beam</var>. The key is sorted on
<var>Key</var> only.
</p>
</dd>
<dt><code>nb_beam_del(+<var>Beam</var>, -<var>Key</var>, -<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fbeam_005fdel_002f3"></a>
<a name="index-nb_005fbeam_005fdel_002f3-1"></a>
<a name="index-nb_005fbeam_005fdel_002f3-2"></a>
<p>Remove element <var>Key</var>-<var>Value</var> with smallest <var>Value</var> in beam
<var>Beam</var>. Fail if the beam is empty.
</p>
</dd>
<dt><code>nb_beam_peek(+<var>Beam</var>, -<var>Key</var>, -<var>Value</var>))</code></dt>
<dd><a name="index-nb_005fbeam_005fpeek_002f3"></a>
<a name="index-nb_005fbeam_005fpeek_002f3-1"></a>
<a name="index-nb_005fbeam_005fpeek_002f3-2"></a>
<p><var>Key</var>-<var>Value</var> is the element with smallest <var>Key</var> in the beam
<var>Beam</var>. Fail if the beam is empty.
</p>
</dd>
<dt><code>nb_beam_size(+<var>Beam</var>, -<var>Size</var>)</code></dt>
<dd><a name="index-nb_005fbeam_005fsize_002f2"></a>
<a name="index-nb_005fbeam_005fsize_002f2-1"></a>
<a name="index-nb_005fbeam_005fsize_002f2-2"></a>
<p>Unify <var>Size</var> with the number of elements in the beam <var>Beam</var>.
</p>
</dd>
<dt><code>nb_beam_empty(+<var>Beam</var>)</code></dt>
<dd><a name="index-nb_005fbeam_005fempty_002f1"></a>
<a name="index-nb_005fbeam_005fempty_002f1-1"></a>
<a name="index-nb_005fbeam_005fempty_002f1-2"></a>
<p>Succeeds if <var>Beam</var> is empty.
</p>
</dd>
</dl>
<hr>
<a name="Ordered-Sets"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Non_002dBacktrackable-Data-Structures" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Pseudo-Random" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Ordered-Sets-1"></a>
<h2 class="section">7.12 Ordered Sets</h2>
<a name="index-ordered-set"></a>
<p>The following ordered set manipulation routines are available once
included with the <code>use_module(library(ordsets))</code> command. An
ordered set is represented by a list having unique and ordered
elements. Output arguments are guaranteed to be ordered sets, if the
relevant inputs are. This is a slightly patched version of Richard
O&rsquo;Keefe&rsquo;s original library.
</p>
<dl compact="compact">
<dt><code>list_to_ord_set(+<var>List</var>, ?<var>Set</var>)</code></dt>
<dd><a name="index-list_005fto_005ford_005fset_002f2"></a>
<a name="index-list_005fto_005ford_005fset_002f2-1"></a>
<a name="index-list_005fto_005ford_005fset_002f2-2"></a>
<p>Holds when <var>Set</var> is the ordered representation of the set
represented by the unordered representation <var>List</var>.
</p>
</dd>
<dt><code>merge(+<var>List1</var>, +<var>List2</var>, -<var>Merged</var>)</code></dt>
<dd><a name="index-merge_002f3"></a>
<a name="index-merge_002f3-1"></a>
<a name="index-merge_002f3-2"></a>
<p>Holds when <var>Merged</var> is the stable merge of the two given lists.
</p>
<p>Notice that <code>merge/3</code> will not remove duplicates, so merging
ordered sets will not necessarily result in an ordered set. Use
<code>ord_union/3</code> instead.
</p>
</dd>
<dt><code>ord_add_element(+<var>Set1</var>, +<var>Element</var>, ?<var>Set2</var>)</code></dt>
<dd><a name="index-ord_005fadd_005felement_002f3"></a>
<a name="index-ord_005fadd_005felement_002f3-1"></a>
<a name="index-ord_005fadd_005felement_002f3-2"></a>
<p>Inserting <var>Element</var> in <var>Set1</var> returns <var>Set2</var>. It should give
exactly the same result as <code>merge(Set1, [Element], Set2)</code>, but a
bit faster, and certainly more clearly. The same as <code>ord_insert/3</code>.
</p>
</dd>
<dt><code>ord_del_element(+<var>Set1</var>, +<var>Element</var>, ?<var>Set2</var>)</code></dt>
<dd><a name="index-ord_005fdel_005felement_002f3"></a>
<a name="index-ord_005fdel_005felement_002f3-1"></a>
<a name="index-ord_005fdel_005felement_002f3-2"></a>
<p>Removing <var>Element</var> from <var>Set1</var> returns <var>Set2</var>.
</p>
</dd>
<dt><code>ord_disjoint(+<var>Set1</var>, +<var>Set2</var>)</code></dt>
<dd><a name="index-ord_005fdisjoint_002f2"></a>
<a name="index-ord_005fdisjoint_002f2-1"></a>
<a name="index-ord_005fdisjoint_002f2-2"></a>
<p>Holds when the two ordered sets have no element in common.
</p>
</dd>
<dt><code>ord_member(+<var>Element</var>, +<var>Set</var>)</code></dt>
<dd><a name="index-ord_005fmember_002f2"></a>
<a name="index-ord_005fmember_002f2-1"></a>
<a name="index-ord_005fmember_002f2-2"></a>
<p>Holds when <var>Element</var> is a member of <var>Set</var>.
</p>
</dd>
<dt><code>ord_insert(+<var>Set1</var>, +<var>Element</var>, ?<var>Set2</var>)</code></dt>
<dd><a name="index-ord_005finsert_002f3"></a>
<a name="index-ord_005finsert_002f3-1"></a>
<a name="index-ord_005finsert_002f3-2"></a>
<p>Inserting <var>Element</var> in <var>Set1</var> returns <var>Set2</var>. It should give
exactly the same result as <code>merge(Set1, [Element], Set2)</code>, but a
bit faster, and certainly more clearly. The same as <code>ord_add_element/3</code>.
</p>
</dd>
<dt><code>ord_intersect(+<var>Set1</var>, +<var>Set2</var>)</code></dt>
<dd><a name="index-ord_005fintersect_002f2"></a>
<a name="index-ord_005fintersect_002f2-1"></a>
<a name="index-ord_005fintersect_002f2-2"></a>
<p>Holds when the two ordered sets have at least one element in common.
</p>
</dd>
<dt><code>ord_intersection(+<var>Set1</var>, +<var>Set2</var>, ?<var>Intersection</var>)</code></dt>
<dd><a name="index-ord_005fintersect_002f3"></a>
<a name="index-ord_005fintersect_002f3-1"></a>
<a name="index-ord_005fintersect_002f3-2"></a>
<p>Holds when Intersection is the ordered representation of <var>Set1</var>
and <var>Set2</var>.
</p>
</dd>
<dt><code>ord_intersection(+<var>Set1</var>, +<var>Set2</var>, ?<var>Intersection</var>, ?<var>Diff</var>)</code></dt>
<dd><a name="index-ord_005fintersect_002f4"></a>
<a name="index-ord_005fintersect_002f4-1"></a>
<a name="index-ord_005fintersect_002f4-2"></a>
<p>Holds when Intersection is the ordered representation of <var>Set1</var>
and <var>Set2</var>. <var>Diff</var> is the difference between <var>Set2</var> and <var>Set1</var>.
</p>
</dd>
<dt><code>ord_seteq(+<var>Set1</var>, +<var>Set2</var>)</code></dt>
<dd><a name="index-ord_005fseteq_002f2"></a>
<a name="index-ord_005fseteq_002f2-1"></a>
<a name="index-ord_005fseteq_002f2-2"></a>
<p>Holds when the two arguments represent the same set.
</p>
</dd>
<dt><code>ord_setproduct(+<var>Set1</var>, +<var>Set2</var>, -<var>Set</var>)</code></dt>
<dd><a name="index-ord_005fsetproduct_002f3"></a>
<a name="index-ord_005fsetproduct_002f3-1"></a>
<a name="index-ord_005fsetproduct_002f3-2"></a>
<p>If Set1 and Set2 are ordered sets, Product will be an ordered
set of x1-x2 pairs.
</p>
</dd>
<dt><code>ord_subset(+<var>Set1</var>, +<var>Set2</var>)</code></dt>
<dd><a name="index-ordsubset_002f2"></a>
<a name="index-ordsubset_002f2-1"></a>
<a name="index-ordsubset_002f2-2"></a>
<p>Holds when every element of the ordered set <var>Set1</var> appears in the
ordered set <var>Set2</var>.
</p>
</dd>
<dt><code>ord_subtract(+<var>Set1</var>, +<var>Set2</var>, ?<var>Difference</var>)</code></dt>
<dd><a name="index-ord_005fsubtract_002f3"></a>
<a name="index-ord_005fsubtract_002f3-1"></a>
<a name="index-ord_005fsubtract_002f3-2"></a>
<p>Holds when <var>Difference</var> contains all and only the elements of <var>Set1</var>
which are not also in <var>Set2</var>.
</p>
</dd>
<dt><code>ord_symdiff(+<var>Set1</var>, +<var>Set2</var>, ?<var>Difference</var>)</code></dt>
<dd><a name="index-ord_005fsymdiff_002f3"></a>
<a name="index-ord_005fsymdiff_002f3-1"></a>
<a name="index-ord_005fsymdiff_002f3-2"></a>
<p>Holds when <var>Difference</var> is the symmetric difference of <var>Set1</var>
and <var>Set2</var>.
</p>
</dd>
<dt><code>ord_union(+<var>Sets</var>, ?<var>Union</var>)</code></dt>
<dd><a name="index-ord_005funion_002f2"></a>
<a name="index-ord_005funion_002f2-1"></a>
<a name="index-ord_005funion_002f2-2"></a>
<p>Holds when <var>Union</var> is the union of the lists <var>Sets</var>.
</p>
</dd>
<dt><code>ord_union(+<var>Set1</var>, +<var>Set2</var>, ?<var>Union</var>)</code></dt>
<dd><a name="index-ord_005funion_002f3"></a>
<a name="index-ord_005funion_002f3-1"></a>
<a name="index-ord_005funion_002f3-2"></a>
<p>Holds when <var>Union</var> is the union of <var>Set1</var> and <var>Set2</var>.
</p>
</dd>
<dt><code>ord_union(+<var>Set1</var>, +<var>Set2</var>, ?<var>Union</var>, ?<var>Diff</var>)</code></dt>
<dd><a name="index-ord_005funion_002f4"></a>
<a name="index-ord_005funion_002f4-1"></a>
<a name="index-ord_005funion_002f4-2"></a>
<p>Holds when <var>Union</var> is the union of <var>Set1</var> and <var>Set2</var> and
<var>Diff</var> is the difference.
</p>
</dd>
</dl>
<hr>
<a name="Pseudo-Random"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Ordered-Sets" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Queues" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Pseudo-Random-Number-Integer-Generator"></a>
<h2 class="section">7.13 Pseudo Random Number Integer Generator</h2>
<a name="index-pseudo-random"></a>
<p>The following routines produce random non-negative integers in the range
0 .. 2^(w-1) -1, where w is the word size available for integers, e.g.
32 for Intel machines and 64 for Alpha machines. Note that the numbers
generated by this random number generator are repeatable. This generator
was originally written by Allen Van Gelder and is based on Knuth Vol 2.
</p>
<dl compact="compact">
<dt><code>rannum(-<var>I</var>)</code></dt>
<dd><a name="index-rannum_002f1"></a>
<a name="index-rannum_002f1-1"></a>
<a name="index-rannum_002f1-2"></a>
<p>Produces a random non-negative integer <var>I</var> whose low bits are not
all that random, so it should be scaled to a smaller range in general.
The integer <var>I</var> is in the range 0 .. 2^(w-1) - 1. You can use:
</p><div class="example">
<pre class="example">rannum(X) :- yap_flag(max_integer,MI), rannum(R), X is R/MI.
</pre></div>
<p>to obtain a floating point number uniformly distributed between 0 and 1.
</p>
</dd>
<dt><code>ranstart</code></dt>
<dd><a name="index-ranstart_002f0"></a>
<a name="index-ranstart_002f0-1"></a>
<a name="index-ranstart_002f0-2"></a>
<p>Initialize the random number generator using a built-in seed. The
<code>ranstart/0</code> built-in is always called by the system when loading
the package.
</p>
</dd>
<dt><code>ranstart(+<var>Seed</var>)</code></dt>
<dd><a name="index-ranstart_002f1"></a>
<a name="index-ranstart_002f1-1"></a>
<a name="index-ranstart_002f1-2"></a>
<p>Initialize the random number generator with user-defined <var>Seed</var>. The
same <var>Seed</var> always produces the same sequence of numbers.
</p>
</dd>
<dt><code>ranunif(+<var>Range</var>,-<var>I</var>)</code></dt>
<dd><a name="index-ranunif_002f2"></a>
<a name="index-ranunif_002f2-1"></a>
<a name="index-ranunif_002f2-2"></a>
<p><code>ranunif/2</code> produces a uniformly distributed non-negative random
integer <var>I</var> over a caller-specified range <var>R</var>. If range is <var>R</var>,
the result is in 0 .. <var>R</var>-1.
</p>
</dd>
</dl>
<hr>
<a name="Queues"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Pseudo-Random" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Random" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Queues-1"></a>
<h2 class="section">7.14 Queues</h2>
<a name="index-queue"></a>
<p>The following queue manipulation routines are available once
included with the <code>use_module(library(queues))</code> command. Queues are
implemented with difference lists.
</p>
<dl compact="compact">
<dt><code>make_queue(+<var>Queue</var>)</code></dt>
<dd><a name="index-make_005fqueue_002f1"></a>
<a name="index-make_005fqueue_002f1-1"></a>
<a name="index-make_005fqueue_002f1-2"></a>
<p>Creates a new empty queue. It should only be used to create a new queue.
</p>
</dd>
<dt><code>join_queue(+<var>Element</var>, +<var>OldQueue</var>, -<var>NewQueue</var>)</code></dt>
<dd><a name="index-join_005fqueue_002f3"></a>
<a name="index-join_005fqueue_002f3-1"></a>
<a name="index-join_005fqueue_002f3-2"></a>
<p>Adds the new element at the end of the queue.
</p>
</dd>
<dt><code>list_join_queue(+<var>List</var>, +<var>OldQueue</var>, -<var>NewQueue</var>)</code></dt>
<dd><a name="index-list_005fjoin_005fqueue_002f3"></a>
<a name="index-list_005fjoin_005fqueue_002f3-1"></a>
<a name="index-list_005fjoin_005fqueue_002f3-2"></a>
<p>Ads the new elements at the end of the queue.
</p>
</dd>
<dt><code>jump_queue(+<var>Element</var>, +<var>OldQueue</var>, -<var>NewQueue</var>)</code></dt>
<dd><a name="index-jump_005fqueue_002f3"></a>
<a name="index-jump_005fqueue_002f3-1"></a>
<a name="index-jump_005fqueue_002f3-2"></a>
<p>Adds the new element at the front of the list.
</p>
</dd>
<dt><code>list_jump_queue(+<var>List</var>, +<var>OldQueue</var>, +<var>NewQueue</var>)</code></dt>
<dd><a name="index-list_005fjump_005fqueue_002f3"></a>
<a name="index-list_005fjump_005fqueue_002f3-1"></a>
<a name="index-list_005fjump_005fqueue_002f3-2"></a>
<p>Adds all the elements of <var>List</var> at the front of the queue.
</p>
</dd>
<dt><code>head_queue(+<var>Queue</var>, ?<var>Head</var>)</code></dt>
<dd><a name="index-head_005fqueue_002f2"></a>
<a name="index-head_005fqueue_002f2-1"></a>
<a name="index-head_005fqueue_002f2-2"></a>
<p>Unifies Head with the first element of the queue.
</p>
</dd>
<dt><code>serve_queue(+<var>OldQueue</var>, +<var>Head</var>, -<var>NewQueue</var>)</code></dt>
<dd><a name="index-serve_005fqueue_002f3"></a>
<a name="index-serve_005fqueue_002f3-1"></a>
<a name="index-serve_005fqueue_002f3-2"></a>
<p>Removes the first element of the queue for service.
</p>
</dd>
<dt><code>empty_queue(+<var>Queue</var>)</code></dt>
<dd><a name="index-empty_005fqueue_002f1"></a>
<a name="index-empty_005fqueue_002f1-1"></a>
<a name="index-empty_005fqueue_002f1-2"></a>
<p>Tests whether the queue is empty.
</p>
</dd>
<dt><code>length_queue(+<var>Queue</var>, -<var>Length</var>)</code></dt>
<dd><a name="index-length_005fqueue_002f2"></a>
<a name="index-length_005fqueue_002f2-1"></a>
<a name="index-length_005fqueue_002f2-2"></a>
<p>Counts the number of elements currently in the queue.
</p>
</dd>
<dt><code>list_to_queue(+<var>List</var>, -<var>Queue</var>)</code></dt>
<dd><a name="index-list_005fto_005fqueue_002f2"></a>
<a name="index-list_005fto_005fqueue_002f2-1"></a>
<a name="index-list_005fto_005fqueue_002f2-2"></a>
<p>Creates a new queue with the same elements as <var>List.</var>
</p>
</dd>
<dt><code>queue_to_list(+<var>Queue</var>, -<var>List</var>)</code></dt>
<dd><a name="index-queue_005fto_005flist_002f2"></a>
<a name="index-queue_005fto_005flist_002f2-1"></a>
<a name="index-queue_005fto_005flist_002f2-2"></a>
<p>Creates a new list with the same elements as <var>Queue</var>.
</p>
</dd>
</dl>
<hr>
<a name="Random"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Queues" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Read-Utilities" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Random-Number-Generator"></a>
<h2 class="section">7.15 Random Number Generator</h2>
<a name="index-queue-1"></a>
<p>The following random number operations are included with the
<code>use_module(library(random))</code> command. Since YAP-4.3.19 YAP uses
the O&rsquo;Keefe public-domain algorithm, based on the &quot;Applied Statistics&quot;
algorithm AS183.
</p>
<dl compact="compact">
<dt><code>getrand(-<var>Key</var>)</code></dt>
<dd><a name="index-getrand_002f1"></a>
<a name="index-getrand_002f1-1"></a>
<a name="index-getrand_002f1-2"></a>
<p>Unify <var>Key</var> with a term of the form <code>rand(X,Y,Z)</code> describing the
current state of the random number generator.
</p>
</dd>
<dt><code>random(-<var>Number</var>)</code></dt>
<dd><a name="index-random_002f1"></a>
<a name="index-random_002f1-1"></a>
<a name="index-random_002f1-2"></a>
<p>Unify <var>Number</var> with a floating-point number in the range <code>[0...1)</code>.
</p>
</dd>
<dt><code>random(+<var>LOW</var>, +<var>HIGH</var>, -<var>NUMBER</var>)</code></dt>
<dd><a name="index-random_002f3"></a>
<a name="index-random_002f3-1"></a>
<a name="index-random_002f3-2"></a>
<p>Unify <var>Number</var> with a number in the range
<code>[LOW...HIGH)</code>. If both <var>LOW</var> and <var>HIGH</var> are
integers then <var>NUMBER</var> will also be an integer, otherwise
<var>NUMBER</var> will be a floating-point number.
</p>
</dd>
<dt><code>randseq(+<var>LENGTH</var>, +<var>MAX</var>, -<var>Numbers</var>)</code></dt>
<dd><a name="index-randseq_002f3"></a>
<a name="index-randseq_002f3-1"></a>
<a name="index-randseq_002f3-2"></a>
<p>Unify <var>Numbers</var> with a list of <var>LENGTH</var> unique random integers
in the range <code>[1<>...<var>MAX</var>)</code>.
</p>
</dd>
<dt><code>randset(+<var>LENGTH</var>, +<var>MAX</var>, -<var>Numbers</var>)</code></dt>
<dd><a name="index-randset_002f3"></a>
<a name="index-randset_002f3-1"></a>
<a name="index-randset_002f3-2"></a>
<p>Unify <var>Numbers</var> with an ordered list of <var>LENGTH</var> unique random
integers in the range <code>[1<>...<var>MAX</var>)</code>.
</p>
</dd>
<dt><code>setrand(+<var>Key</var>)</code></dt>
<dd><a name="index-setrand_002f1"></a>
<a name="index-setrand_002f1-1"></a>
<a name="index-setrand_002f1-2"></a>
<p>Use a term of the form <code>rand(X,Y,Z)</code> to set a new state for the
random number generator. The integer <code>X</code> must be in the range
<code>[1...30269)</code>, the integer <code>Y</code> must be in the range
<code>[1...30307)</code>, and the integer <code>Z</code> must be in the range
<code>[1...30323)</code>.
</p>
</dd>
</dl>
<hr>
<a name="Read-Utilities"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Random" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Red_002dBlack-Trees" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Read-Utilities-1"></a>
<h2 class="section">7.16 Read Utilities</h2>
<p>The <code>readutil</code> library contains primitives to read lines, files,
multiple terms, etc.
</p>
<dl compact="compact">
<dt><code>read_line_to_codes(+<var>Stream</var>, -<var>Codes</var>)</code></dt>
<dd><a name="index-read_005fline_005fto_005fcodes_002f2"></a>
<a name="index-read_005fline_005fto_005fcodes_002f2-1"></a>
<a name="index-read_005fline_005fto_005fcodes_002f2-2"></a>
<p>Read the next line of input from <var>Stream</var> and unify the result with
<var>Codes</var> <em>after</em> the line has been read. A line is ended by a
newline character or end-of-file. Unlike <code>read_line_to_codes/3</code>,
this predicate removes trailing newline character.
</p>
<p>On end-of-file the atom <code>end_of_file</code> is returned. See also
<code>at_end_of_stream/[0,1]</code>.
</p>
</dd>
<dt><code>read_line_to_codes(+<var>Stream</var>, -<var>Codes</var>, ?<var>Tail</var>)</code></dt>
<dd><a name="index-read_005fline_005fto_005fcodes_002f3"></a>
<a name="index-read_005fline_005fto_005fcodes_002f3-1"></a>
<a name="index-read_005fline_005fto_005fcodes_002f3-2"></a>
<p>Difference-list version to read an input line to a list of character
codes. Reading stops at the newline or end-of-file character, but
unlike <code>read_line_to_codes/2</code>, the newline is retained in the
output. This predicate is especially useful for reading a block of
lines upto some delimiter. The following example reads an HTTP header
ended by a blank line:
</p>
<div class="example">
<pre class="example">read_header_data(Stream, Header) :-
read_line_to_codes(Stream, Header, Tail),
read_header_data(Header, Stream, Tail).
read_header_data(&quot;\r\n&quot;, _, _) :- !.
read_header_data(&quot;\n&quot;, _, _) :- !.
read_header_data(&quot;&quot;, _, _) :- !.
read_header_data(_, Stream, Tail) :-
read_line_to_codes(Stream, Tail, NewTail),
read_header_data(Tail, Stream, NewTail).
</pre></div>
</dd>
<dt><code>read_stream_to_codes(+<var>Stream</var>, -<var>Codes</var>)</code></dt>
<dd><a name="index-read_005fstream_005fto_005fcodes_002f3"></a>
<a name="index-read_005fstream_005fto_005fcodes_002f3-1"></a>
<a name="index-read_005fstream_005fto_005fcodes_002f3-2"></a>
<p>Read all input until end-of-file and unify the result to <var>Codes</var>.
</p>
</dd>
<dt><code>read_stream_to_codes(+<var>Stream</var>, -<var>Codes</var>, ?<var>Tail</var>)</code></dt>
<dd><a name="index-read_005fstream_005fto_005fcodes_002f3-3"></a>
<a name="index-read_005fstream_005fto_005fcodes_002f3-4"></a>
<a name="index-read_005fstream_005fto_005fcodes_002f3-5"></a>
<p>Difference-list version of <code>read_stream_to_codes/2</code>.
</p>
</dd>
<dt><code>read_file_to_codes(+<var>Spec</var>, -<var>Codes</var>, +<var>Options</var>)</code></dt>
<dd><a name="index-read_005ffile_005fto_005fcodes_002f3"></a>
<a name="index-read_005ffile_005fto_005fcodes_002f3-1"></a>
<a name="index-read_005ffile_005fto_005fcodes_002f3-2"></a>
<p>Read a file to a list of character codes. Currently ignores
<var>Options</var>.
</p>
</dd>
<dt><code>read_file_to_terms(+<var>Spec</var>, -<var>Terms</var>, +<var>Options</var>)</code></dt>
<dd><a name="index-read_005ffile_005fto_005fterms_002f3"></a>
<a name="index-read_005ffile_005fto_005fterms_002f3-1"></a>
<a name="index-read_005ffile_005fto_005fterms_002f3-2"></a>
<p>Read a file to a list of Prolog terms (see read/1). </p>
</dd>
</dl>
<hr>
<a name="Red_002dBlack-Trees"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Read-Utilities" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#RegExp" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Red_002dBlack-Trees-1"></a>
<h2 class="section">7.17 Red-Black Trees</h2>
<a name="index-Red_002dBlack-Trees"></a>
<p>Red-Black trees are balanced search binary trees. They are named because
nodes can be classified as either red or black. The code we include is
based on &quot;Introduction to Algorithms&quot;, second edition, by Cormen,
Leiserson, Rivest and Stein. The library includes routines to insert,
lookup and delete elements in the tree.
</p>
<dl compact="compact">
<dt><code>rb_new(?<var>T</var>)</code></dt>
<dd><a name="index-rb_005fnew_002f1"></a>
<a name="index-rb_005fnew_002f1-1"></a>
<a name="index-rb_005fnew_002f1-2"></a>
<p>Create a new tree.
</p>
</dd>
<dt><code>rb_empty(?<var>T</var>)</code></dt>
<dd><a name="index-rb_005fempty_002f1"></a>
<a name="index-rb_005fempty_002f1-1"></a>
<a name="index-rb_005fempty_002f1-2"></a>
<p>Succeeds if tree <var>T</var> is empty.
</p>
</dd>
<dt><code>is_rbtree(+<var>T</var>)</code></dt>
<dd><a name="index-is_005frbtree_002f1"></a>
<a name="index-is_005frbtree_002f1-1"></a>
<a name="index-is_005frbtree_002f1-2"></a>
<p>Check whether <var>T</var> is a valid red-black tree.
</p>
</dd>
<dt><code>rb_insert(+<var>T0</var>,+<var>Key</var>,?<var>Value</var>,+<var>TF</var>)</code></dt>
<dd><a name="index-rb_005finsert_002f4"></a>
<a name="index-rb_005finsert_002f4-1"></a>
<a name="index-rb_005finsert_002f4-2"></a>
<p>Add an element with key <var>Key</var> and <var>Value</var> to the tree
<var>T0</var> creating a new red-black tree <var>TF</var>. Duplicated elements are not
allowed.
</p>
<a name="index-rb_005finsert_005fnew_002f4"></a>
<a name="index-rb_005finsert_005fnew_002f4-1"></a>
<p>Add a new element with key <var>Key</var> and <var>Value</var> to the tree
<var>T0</var> creating a new red-black tree <var>TF</var>. Fails is an element
with <var>Key</var> exists in the tree.
</p>
</dd>
<dt><code>rb_lookup(+<var>Key</var>,-<var>Value</var>,+<var>T</var>)</code></dt>
<dd><a name="index-rb_005flookup_002f3"></a>
<a name="index-rb_005flookup_002f3-1"></a>
<a name="index-rb_005flookup_002f3-2"></a>
<p>Backtrack through all elements with key <var>Key</var> in the red-black tree
<var>T</var>, returning for each the value <var>Value</var>.
</p>
</dd>
<dt><code>rb_lookupall(+<var>Key</var>,-<var>Value</var>,+<var>T</var>)</code></dt>
<dd><a name="index-rb_005flookupall_002f3"></a>
<a name="index-rb_005flookupall_002f3-1"></a>
<a name="index-rb_005flookupall_002f3-2"></a>
<p>Lookup all elements with key <var>Key</var> in the red-black tree
<var>T</var>, returning the value <var>Value</var>.
</p>
</dd>
<dt><code>rb_delete(+<var>T</var>,+<var>Key</var>,-<var>TN</var>)</code></dt>
<dd><a name="index-rb_005fdelete_002f3"></a>
<a name="index-rb_005fdelete_002f3-1"></a>
<a name="index-rb_005fdelete_002f3-2"></a>
<p>Delete element with key <var>Key</var> from the tree <var>T</var>, returning a new
tree <var>TN</var>.
</p>
</dd>
<dt><code>rb_delete(+<var>T</var>,+<var>Key</var>,-<var>Val</var>,-<var>TN</var>)</code></dt>
<dd><a name="index-rb_005fdelete_002f4"></a>
<a name="index-rb_005fdelete_002f4-1"></a>
<a name="index-rb_005fdelete_002f4-2"></a>
<p>Delete element with key <var>Key</var> from the tree <var>T</var>, returning the
value <var>Val</var> associated with the key and a new tree <var>TN</var>.
</p>
</dd>
<dt><code>rb_del_min(+<var>T</var>,-<var>Key</var>,-<var>Val</var>,-<var>TN</var>)</code></dt>
<dd><a name="index-rb_005fdel_005fmin_002f4"></a>
<a name="index-rb_005fdel_005fmin_002f4-1"></a>
<a name="index-rb_005fdel_005fmin_002f4-2"></a>
<p>Delete the least element from the tree <var>T</var>, returning the key
<var>Key</var>, the value <var>Val</var> associated with the key and a new tree
<var>TN</var>.
</p>
</dd>
<dt><code>rb_del_max(+<var>T</var>,-<var>Key</var>,-<var>Val</var>,-<var>TN</var>)</code></dt>
<dd><a name="index-rb_005fdel_005fmax_002f4"></a>
<a name="index-rb_005fdel_005fmax_002f4-1"></a>
<a name="index-rb_005fdel_005fmax_002f4-2"></a>
<p>Delete the largest element from the tree <var>T</var>, returning the key
<var>Key</var>, the value <var>Val</var> associated with the key and a new tree
<var>TN</var>.
</p>
</dd>
<dt><code>rb_update(+<var>T</var>,+<var>Key</var>,+<var>NewVal</var>,-<var>TN</var>)</code></dt>
<dd><a name="index-rb_005fupdate_002f4"></a>
<a name="index-rb_005fupdate_002f4-1"></a>
<a name="index-rb_005fupdate_002f4-2"></a>
<p>Tree <var>TN</var> is tree <var>T</var>, but with value for <var>Key</var> associated
with <var>NewVal</var>. Fails if it cannot find <var>Key</var> in <var>T</var>.
</p>
</dd>
<dt><code>rb_apply(+<var>T</var>,+<var>Key</var>,+<var>G</var>,-<var>TN</var>)</code></dt>
<dd><a name="index-rb_005fapply_002f4"></a>
<a name="index-rb_005fapply_002f4-1"></a>
<a name="index-rb_005fapply_002f4-2"></a>
<p>If the value associated with key <var>Key</var> is <var>Val0</var> in <var>T</var>, and
if <code>call(G,Val0,ValF)</code> holds, then <var>TN</var> differs from
<var>T</var> only in that <var>Key</var> is associated with value <var>ValF</var> in
tree <var>TN</var>. Fails if it cannot find <var>Key</var> in <var>T</var>, or if
<code>call(G,Val0,ValF)</code> is not satisfiable.
</p>
</dd>
<dt><code>rb_visit(+<var>T</var>,-<var>Pairs</var>)</code></dt>
<dd><a name="index-rb_005fvisit_002f2"></a>
<a name="index-rb_005fvisit_002f2-1"></a>
<a name="index-rb_005fvisit_002f2-2"></a>
<p><var>Pairs</var> is an infix visit of tree <var>T</var>, where each element of
<var>Pairs</var> is of the form <var>K</var>-<var>Val</var>.
</p>
</dd>
<dt><code>rb_size(+<var>T</var>,-<var>Size</var>)</code></dt>
<dd><a name="index-rb_005fsize_002f2"></a>
<a name="index-rb_005fsize_002f2-1"></a>
<a name="index-rb_005fsize_002f2-2"></a>
<p><var>Size</var> is the number of elements in <var>T</var>.
</p>
</dd>
<dt><code>rb_keys(+<var>T</var>,+<var>Keys</var>)</code></dt>
<dd><a name="index-rb_005fkeys_002f2"></a>
<a name="index-rb_005fkeys_002f2-1"></a>
<a name="index-rb_005fkeys_002f2-2"></a>
<p><var>Keys</var> is an infix visit with all keys in tree <var>T</var>. Keys will be
sorted, but may be duplicate.
</p>
</dd>
<dt><code>rb_map(+<var>T</var>,+<var>G</var>,-<var>TN</var>)</code></dt>
<dd><a name="index-rb_005fmap_002f3"></a>
<a name="index-rb_005fmap_002f3-1"></a>
<a name="index-rb_005fmap_002f3-2"></a>
<p>For all nodes <var>Key</var> in the tree <var>T</var>, if the value associated with
key <var>Key</var> is <var>Val0</var> in tree <var>T</var>, and if
<code>call(G,Val0,ValF)</code> holds, then the value associated with <var>Key</var>
in <var>TN</var> is <var>ValF</var>. Fails if or if <code>call(G,Val0,ValF)</code> is not
satisfiable for all <var>Var0</var>.
</p>
</dd>
<dt><code>rb_partial_map(+<var>T</var>,+<var>Keys</var>,+<var>G</var>,-<var>TN</var>)</code></dt>
<dd><a name="index-rb_005fpartial_005fmap_002f4"></a>
<a name="index-rb_005fpartial_005fmap_002f4-1"></a>
<a name="index-rb_005fpartial_005fmap_002f4-2"></a>
<p>For all nodes <var>Key</var> in <var>Keys</var>, if the value associated with key
<var>Key</var> is <var>Val0</var> in tree <var>T</var>, and if <code>call(G,Val0,ValF)</code>
holds, then the value associated with <var>Key</var> in <var>TN</var> is
<var>ValF</var>. Fails if or if <code>call(G,Val0,ValF)</code> is not satisfiable
for all <var>Var0</var>. Assumes keys are not repeated.
</p>
</dd>
<dt><code>rb_clone(+<var>T</var>,+<var>NT</var>,+<var>Nodes</var>)</code></dt>
<dd><a name="index-rb_005fclone_002f3"></a>
<a name="index-rb_005fclone_002f3-1"></a>
<a name="index-rb_005fclone_002f3-2"></a>
<p>&ldquo;Clone&rdquo; 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 <var>K-V</var>.
</p>
</dd>
<dt><code>rb_min(+<var>T</var>,-<var>Key</var>,-<var>Value</var>)</code></dt>
<dd><a name="index-rb_005fmin_002f3"></a>
<a name="index-rb_005fmin_002f3-1"></a>
<a name="index-rb_005fmin_002f3-2"></a>
<p><var>Key</var> is the minimum key in <var>T</var>, and is associated with <var>Val</var>.
</p>
</dd>
<dt><code>rb_max(+<var>T</var>,-<var>Key</var>,-<var>Value</var>)</code></dt>
<dd><a name="index-rb_005fmax_002f3"></a>
<a name="index-rb_005fmax_002f3-1"></a>
<a name="index-rb_005fmax_002f3-2"></a>
<p><var>Key</var> is the maximal key in <var>T</var>, and is associated with <var>Val</var>.
</p>
</dd>
<dt><code>rb_next(+<var>T</var>, +<var>Key</var>,-<var>Next</var>,-<var>Value</var>)</code></dt>
<dd><a name="index-rb_005fnext_002f4"></a>
<a name="index-rb_005fnext_002f4-1"></a>
<a name="index-rb_005fnext_002f4-2"></a>
<p><var>Next</var> is the next element after <var>Key</var> in <var>T</var>, and is
associated with <var>Val</var>.
</p>
</dd>
<dt><code>rb_previous(+<var>T</var>, +<var>Key</var>,-<var>Previous</var>,-<var>Value</var>)</code></dt>
<dd><a name="index-rb_005fprevious_002f4"></a>
<a name="index-rb_005fprevious_002f4-1"></a>
<a name="index-rb_005fprevious_002f4-2"></a>
<p><var>Previous</var> is the previous element after <var>Key</var> in <var>T</var>, and is
associated with <var>Val</var>.
</p>
</dd>
<dt><code>list_to_rbtree(+<var>L</var>, -<var>T</var>)</code></dt>
<dd><a name="index-list_005fto_005frbtree_002f2"></a>
<a name="index-list_005fto_005frbtree_002f2-1"></a>
<a name="index-list_005fto_005frbtree_002f2-2"></a>
<p><var>T</var> is the red-black tree corresponding to the mapping in list <var>L</var>.
</p>
</dd>
<dt><code>ord_list_to_rbtree(+<var>L</var>, -<var>T</var>)</code></dt>
<dd><a name="index-list_005fto_005frbtree_002f2-3"></a>
<a name="index-list_005fto_005frbtree_002f2-4"></a>
<a name="index-list_005fto_005frbtree_002f2-5"></a>
<p><var>T</var> is the red-black tree corresponding to the mapping in ordered
list <var>L</var>.
</p></dd>
</dl>
<hr>
<a name="RegExp"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Red_002dBlack-Trees" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#shlib" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Regular-Expressions"></a>
<h2 class="section">7.18 Regular Expressions</h2>
<a name="index-regular-expressions"></a>
<p>This library includes routines to determine whether a regular expression
matches part or all of a string. The routines can also return which
parts parts of the string matched the expression or subexpressions of
it. This library relies on Henry Spencer&rsquo;s <code>C</code>-package and is only
available in operating systems that support dynamic loading. The
<code>C</code>-code has been obtained from the sources of FreeBSD-4.0 and is
protected by copyright from Henry Spencer and from the Regents of the
University of California (see the file library/regex/COPYRIGHT for
further details).
</p>
<p>Much of the description of regular expressions below is copied verbatim
from Henry Spencer&rsquo;s manual page.
</p>
<p>A regular expression is zero or more branches, separated by &ldquo;|&rdquo;. It
matches anything that matches one of the branches.
</p>
<p>A branch is zero or more pieces, concatenated. It matches a match for
the first, followed by a match for the second, etc.
</p>
<p>A piece is an atom possibly followed by &ldquo;*&rdquo;, &ldquo;+&rdquo;, or &ldquo;?&rdquo;. An atom
followed by &ldquo;*&rdquo; matches a sequence of 0 or more matches of the atom.
An atom followed by &ldquo;+&rdquo; matches a sequence of 1 or more matches of the
atom. An atom followed by &ldquo;?&rdquo; matches a match of the atom, or the
null string.
</p>
<p>An atom is a regular expression in parentheses (matching a match for the
regular expression), a range (see below), &ldquo;.&rdquo; (matching any single
character), &ldquo;^&rdquo; (matching the null string at the beginning of the
input string), &ldquo;$&rdquo; (matching the null string at the end of the input
string), a &ldquo;\&rdquo; followed by a single character (matching that
character), or a single character with no other significance (matching
that character).
</p>
<p>A range is a sequence of characters enclosed in &ldquo;[]&rdquo;. It normally
matches any single character from the sequence. If the sequence begins
with &ldquo;^&rdquo;, it matches any single character not from the rest of the
sequence. If two characters in the sequence are separated by &ldquo;-&rdquo;,
this is shorthand for the full list of ASCII characters between them
(e.g. &ldquo;[0-9]&rdquo; matches any decimal digit). To include a literal &ldquo;]&rdquo;
in the sequence, make it the first character (following a possible
&ldquo;^&rdquo;). To include a literal &ldquo;-&rdquo;, make it the first or last
character.
</p>
<dl compact="compact">
<dt><code>regexp(+<var>RegExp</var>,+<var>String</var>,+<var>Opts</var>)</code></dt>
<dd><a name="index-regexp_002f3"></a>
<a name="index-regexp_002f3-1"></a>
<a name="index-regexp_002f3-2"></a>
<p>Match regular expression <var>RegExp</var> to input string <var>String</var>
according to options <var>Opts</var>. The options may be:
</p><ul>
<li> <code>nocase</code>: Causes upper-case characters in <var>String</var> to
be treated as lower case during the matching process.
</li></ul>
</dd>
<dt><code>regexp(+<var>RegExp</var>,+<var>String</var>,+<var>Opts</var>,?<var>SubMatchVars</var>)</code></dt>
<dd><a name="index-regexp_002f4"></a>
<a name="index-regexp_002f4-1"></a>
<a name="index-regexp_002f4-2"></a>
<p>Match regular expression <var>RegExp</var> to input string <var>String</var>
according to options <var>Opts</var>. The variable <var>SubMatchVars</var> should
be originally unbound or a list of unbound variables all will contain a
sequence of matches, that is, the head of <var>SubMatchVars</var> will
contain the characters in <var>String</var> that matched the leftmost
parenthesized subexpression within <var>RegExp</var>, the next head of list
will contain the characters that matched the next parenthesized
subexpression to the right in <var>RegExp</var>, and so on.
</p>
<p>The options may be:
</p><ul>
<li> <code>nocase</code>: Causes upper-case characters in <var>String</var> to
be treated as lower case during the matching process.
</li><li> <code>indices</code>: Changes what is stored in
<var>SubMatchVars</var>. Instead of storing the matching characters from
<var>String</var>, each variable will contain a term of the form <var>IO-IF</var>
giving the indices in <var>String</var> of the first and last characters in
the matching range of characters.
</li></ul>
<p>In general there may be more than one way to match a regular expression
to an input string. For example, consider the command
</p><div class="example">
<pre class="example"> regexp(&quot;(a*)b*&quot;,&quot;aabaaabb&quot;, [], [X,Y])
</pre></div>
<p>Considering only the rules given so far, <var>X</var> and <var>Y</var> could end up
with the values <code>&quot;aabb&quot;</code> and <code>&quot;aa&quot;</code>, <code>&quot;aaab&quot;</code> and
<code>&quot;aaa&quot;</code>, <code>&quot;ab&quot;</code> and <code>&quot;a&quot;</code>, or any of several other
combinations. To resolve this potential ambiguity <code>regexp</code> chooses among
alternatives using the rule &ldquo;first then longest&rdquo;. In other words, it
considers the possible matches in order working from left to right
across the input string and the pattern, and it attempts to match longer
pieces of the input string before shorter ones. More specifically, the
following rules apply in decreasing order of priority:
</p>
<ol>
<li> If a regular expression could match two different parts of an
input string then it will match the one that begins earliest.
</li><li> If a regular expression contains &quot;|&quot; operators then the leftmost matching sub-expression is chosen.
</li><li> In *, +, and ? constructs, longer matches are chosen in preference to shorter ones.
</li><li> In sequences of expression components the components are considered from left to right.
</li></ol>
<p>In the example from above, <code>&quot;(a*)b*&quot;</code> matches <code>&quot;aab&quot;</code>: the
<code>&quot;(a*)&quot;</code> portion of the pattern is matched first and it consumes
the leading <code>&quot;aa&quot;</code>; then the <code>&quot;b*&quot;</code> portion of the pattern
consumes the next <code>&quot;b&quot;</code>. Or, consider the following example:
</p><div class="example">
<pre class="example"> regexp(&quot;(ab|a)(b*)c&quot;, &quot;abc&quot;, [], [X,Y,Z])
</pre></div>
<p>After this command <var>X</var> will be <code>&quot;abc&quot;</code>, <var>Y</var> will be
<code>&quot;ab&quot;</code>, and <var>Z</var> will be an empty string. Rule 4 specifies that
<code>&quot;(ab|a)&quot;</code> gets first shot at the input string and Rule 2 specifies
that the <code>&quot;ab&quot;</code> sub-expression is checked before the <code>&quot;a&quot;</code>
sub-expression. Thus the <code>&quot;b&quot;</code> has already been claimed before the
<code>&quot;(b*)&quot;</code> component is checked and <code>(b*)</code> must match an empty string.
</p>
</dd>
</dl>
<hr>
<a name="shlib"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#RegExp" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Splay-Trees" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="SWI_002dProlog_0027s-shlib-library"></a>
<h2 class="section">7.19 SWI-Prolog&rsquo;s shlib library</h2>
<a name="index-SWI_002dCompatible-foreign-file-loading"></a>
<p>This section discusses the functionality of the (autoload)
<code>library(shlib)</code>, providing an interface to manage shared
libraries.
</p>
<p>One of the files provides a global function <code>install_mylib()</code> that
initialises the module using calls to <code>PL_register_foreign()</code>. Here is a
simple example file <code>mylib.c</code>, which creates a Windows MessageBox:
</p>
<div class="example">
<pre class="example">#include &lt;windows.h&gt;
#include &lt;SWI-Prolog.h&gt;
static foreign_t
pl_say_hello(term_t to)
{ char *a;
if ( PL_get_atom_chars(to, &amp;a) )
{ MessageBox(NULL, a, &quot;DLL test&quot;, MB_OK|MB_TASKMODAL);
PL_succeed;
}
PL_fail;
}
install_t
install_mylib()
{ PL_register_foreign(&quot;say_hello&quot;, 1, pl_say_hello, 0);
}
</pre></div>
<p>Now write a file mylib.pl:
</p>
<div class="example">
<pre class="example">:- module(mylib, [ say_hello/1 ]).
:- use_foreign_library(foreign(mylib)).
</pre></div>
<p>The file mylib.pl can be loaded as a normal Prolog file and provides the predicate defined in C.
</p>
<dl compact="compact">
<dt><code>[det]load_foreign_library(:<var>FileSpec</var>)</code></dt>
<dt><code>[det]load_foreign_library(:<var>FileSpec</var>, +<var>Entry</var>:atom)</code></dt>
<dd><a name="index-load_005fforeign_005flibrary_002f1"></a>
<a name="index-load_005fforeign_005flibrary_002f1-1"></a>
<a name="index-load_005fforeign_005flibrary_002f1-2"></a>
<a name="index-load_005fforeign_005flibrary_002f2"></a>
<a name="index-load_005fforeign_005flibrary_002f2-1"></a>
<a name="index-load_005fforeign_005flibrary_002f2-2"></a>
<p> Load a shared object or DLL. After loading the <var>Entry</var> function is
called without arguments. The default entry function is composed
from <code>install_</code>, followed by the file base-name. E.g., the
load-call below calls the function <code>install_mylib()</code>. If the platform
prefixes extern functions with <code>_</code>, this prefix is added before
calling.
</p>
<div class="example">
<pre class="example"> ...
load_foreign_library(foreign(mylib)),
...
</pre></div>
<p> <var>FileSpec</var> is a specification for
<code>absolute_file_name/3</code>. If searching the file fails, the plain
name is passed to the OS to try the default method of the OS for
locating foreign objects. The default definition of
<code>file_search_path/2</code> searches &lt;prolog home&gt;/lib/Yap.
</p>
<p> See also
<code>use_foreign_library/1,2</code> are intended for use in
directives.
</p>
</dd>
<dt><code>[det]use_foreign_library(+<var>FileSpec</var>)</code></dt>
<dt><code>[det]use_foreign_library(+<var>FileSpec</var>, +<var>Entry</var>:atom)</code></dt>
<dd><a name="index-use_005fforeign_005flibrary_002f1"></a>
<a name="index-use_005fforeign_005flibrary_002f1-1"></a>
<a name="index-use_005fforeign_005flibrary_002f1-2"></a>
<a name="index-use_005fforeign_005flibrary_002f2"></a>
<a name="index-use_005fforeign_005flibrary_002f2-1"></a>
<a name="index-use_005fforeign_005flibrary_002f2-2"></a>
<p> Load and install a foreign library as load_foreign_library/1,2 and
register the installation using <code>initialization/2</code> with the option
now. This is similar to using:
</p>
<div class="example">
<pre class="example"> :- initialization(load_foreign_library(foreign(mylib))).
</pre></div>
<p> but using the <code>initialization/1</code> wrapper causes the library to
be loaded after loading of the file in which it appears is
completed, while <code>use_foreign_library/1</code> loads the library
immediately. I.e. the difference is only relevant if the remainder
of the file uses functionality of the <code>C</code>-library.
</p>
</dd>
<dt><code>[det]unload_foreign_library(+<var>FileSpec</var>)</code></dt>
<dt><code>[det]unload_foreign_library(+<var>FileSpec</var>, +<var>Exit</var>:atom)</code></dt>
<dd><a name="index-unload_005fforeign_005flibrary_002f1"></a>
<a name="index-unload_005fforeign_005flibrary_002f1-1"></a>
<a name="index-unload_005fforeign_005flibrary_002f1-2"></a>
<a name="index-unload_005fforeign_005flibrary_002f2"></a>
<a name="index-unload_005fforeign_005flibrary_002f2-1"></a>
<a name="index-unload_005fforeign_005flibrary_002f2-2"></a>
<p>Unload a shared
object or DLL. After calling the <var>Exit</var> function, the shared object is
removed from the process. The default exit function is composed from
<code>uninstall_</code>, followed by the file base-name.
</p>
</dd>
<dt><code>current_foreign_library(?<var>File</var>, ?<var>Public</var>)</code></dt>
<dd><a name="index-current_005fforeign_005flibrary_002f2"></a>
<a name="index-current_005fforeign_005flibrary_002f2-1"></a>
<a name="index-current_005fforeign_005flibrary_002f2-2"></a>
<p>Query currently
loaded shared libraries.
</p>
</dd>
</dl>
<hr>
<a name="Splay-Trees"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#shlib" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#String-I_002fO" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Splay-Trees-1"></a>
<h2 class="section">7.20 Splay Trees</h2>
<a name="index-splay-trees"></a>
<p>Splay trees are explained in the paper &quot;Self-adjusting Binary Search
Trees&quot;, by D.D. Sleator and R.E. Tarjan, JACM, vol. 32, No.3, July 1985,
p. 668. They are designed to support fast insertions, deletions and
removals in binary search trees without the complexity of traditional
balanced trees. The key idea is to allow the tree to become
unbalanced. To make up for this, whenever we find a node, we move it up
to the top. We use code by Vijay Saraswat originally posted to the Prolog
mailing-list.
</p>
<dl compact="compact">
<dt><code>splay_access(-<var>Return</var>,+<var>Key</var>,?<var>Val</var>,+<var>Tree</var>,-<var>NewTree</var>)</code></dt>
<dd><a name="index-splay_005faccess_002f5"></a>
<a name="index-splay_005faccess_002f5-1"></a>
<a name="index-splay_005faccess_002f5-2"></a>
<p>If item <var>Key</var> is in tree <var>Tree</var>, return its <var>Val</var> and
unify <var>Return</var> with <code>true</code>. Otherwise unify <var>Return</var> with
<code>null</code>. The variable <var>NewTree</var> unifies with the new tree.
</p>
</dd>
<dt><code>splay_delete(+<var>Key</var>,?<var>Val</var>,+<var>Tree</var>,-<var>NewTree</var>)</code></dt>
<dd><a name="index-splay_005fdelete_002f4"></a>
<a name="index-splay_005fdelete_002f4-1"></a>
<a name="index-splay_005fdelete_002f4-2"></a>
<p>Delete item <var>Key</var> from tree <var>Tree</var>, assuming that it is present
already. The variable <var>Val</var> unifies with a value for key <var>Key</var>,
and the variable <var>NewTree</var> unifies with the new tree. The predicate
will fail if <var>Key</var> is not present.
</p>
</dd>
<dt><code>splay_init(-<var>NewTree</var>)</code></dt>
<dd><a name="index-splay_005finit_002f3"></a>
<a name="index-splay_005finit_002f3-1"></a>
<a name="index-splay_005finit_002f3-2"></a>
<p>Initialize a new splay tree.
</p>
</dd>
<dt><code>splay_insert(+<var>Key</var>,?<var>Val</var>,+<var>Tree</var>,-<var>NewTree</var>)</code></dt>
<dd><a name="index-splay_005finsert_002f4"></a>
<a name="index-splay_005finsert_002f4-1"></a>
<a name="index-splay_005finsert_002f4-2"></a>
<p>Insert item <var>Key</var> in tree <var>Tree</var>, assuming that it is not
there already. The variable <var>Val</var> unifies with a value for key
<var>Key</var>, and the variable <var>NewTree</var> unifies with the new
tree. In our implementation, <var>Key</var> is not inserted if it is
already there: rather it is unified with the item already in the tree.
</p>
</dd>
<dt><code>splay_join(+<var>LeftTree</var>,+<var>RighTree</var>,-<var>NewTree</var>)</code></dt>
<dd><a name="index-splay_005fjoin_002f3"></a>
<a name="index-splay_005fjoin_002f3-1"></a>
<a name="index-splay_005fjoin_002f3-2"></a>
<p>Combine trees <var>LeftTree</var> and <var>RighTree</var> into a single
tree<var>NewTree</var> containing all items from both trees. This operation
assumes that all items in <var>LeftTree</var> are less than all those in
<var>RighTree</var> and destroys both <var>LeftTree</var> and <var>RighTree</var>.
</p>
</dd>
<dt><code>splay_split(+<var>Key</var>,?<var>Val</var>,+<var>Tree</var>,-<var>LeftTree</var>,-<var>RightTree</var>)</code></dt>
<dd><a name="index-splay_005fsplit_002f5"></a>
<a name="index-splay_005fsplit_002f5-1"></a>
<a name="index-splay_005fsplit_002f5-2"></a>
<p>Construct and return two trees <var>LeftTree</var> and <var>RightTree</var>,
where <var>LeftTree</var> contains all items in <var>Tree</var> less than
<var>Key</var>, and <var>RightTree</var> contains all items in <var>Tree</var>
greater than <var>Key</var>. This operations destroys <var>Tree</var>.
</p>
</dd>
</dl>
<hr>
<a name="String-I_002fO"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Splay-Trees" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#System" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Reading-From-and-Writing-To-Strings"></a>
<h2 class="section">7.21 Reading From and Writing To Strings</h2>
<a name="index-string-I_002fO"></a>
<p>From Version 4.3.2 onwards YAP implements SICStus Prolog compatible
String I/O. The library allows users to read from and write to a memory
buffer as if it was a file. The memory buffer is built from or converted
to a string of character codes by the routines in library. Therefore, if
one wants to read from a string the string must be fully instantiated
before the library built-in opens the string for reading. These commands
are available through the <code>use_module(library(charsio))</code> command.
</p>
<dl compact="compact">
<dt><code>format_to_chars(+<var>Form</var>, +<var>Args</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-format_005fto_005fchars_002f3"></a>
<a name="index-format_005fto_005fchars_002f3-1"></a>
<a name="index-format_005fto_005fchars_002f3-2"></a>
<p>Execute the built-in procedure <code>format/2</code> with form <var>Form</var> and
arguments <var>Args</var> outputting the result to the string of character
codes <var>Result</var>.
</p>
</dd>
<dt><code>format_to_chars(+<var>Form</var>, +<var>Args</var>, -<var>Result</var>, -<var>Result0</var>)</code></dt>
<dd><a name="index-format_005fto_005fchars_002f4"></a>
<a name="index-format_005fto_005fchars_002f4-1"></a>
<a name="index-format_005fto_005fchars_002f4-2"></a>
<p>Execute the built-in procedure <code>format/2</code> with form <var>Form</var> and
arguments <var>Args</var> outputting the result to the difference list of
character codes <var>Result-Result0</var>.
</p>
</dd>
<dt><code>write_to_chars(+<var>Term</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-write_005fto_005fchars_002f2"></a>
<a name="index-write_005fto_005fchars_002f2-1"></a>
<a name="index-write_005fto_005fchars_002f2-2"></a>
<p>Execute the built-in procedure <code>write/1</code> with argument <var>Term</var>
outputting the result to the string of character codes <var>Result</var>.
</p>
</dd>
<dt><code>write_to_chars(+<var>Term</var>, -<var>Result0</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-write_005fto_005fchars_002f3"></a>
<a name="index-write_005fto_005fchars_002f3-1"></a>
<a name="index-write_005fto_005fchars_002f3-2"></a>
<p>Execute the built-in procedure <code>write/1</code> with argument <var>Term</var>
outputting the result to the difference list of character codes
<var>Result-Result0</var>.
</p>
</dd>
<dt><code>atom_to_chars(+<var>Atom</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-atom_005fto_005fchars_002f2"></a>
<a name="index-atom_005fto_005fchars_002f2-1"></a>
<a name="index-atom_005fto_005fchars_002f2-2"></a>
<p>Convert the atom <var>Atom</var> to the string of character codes
<var>Result</var>.
</p>
</dd>
<dt><code>atom_to_chars(+<var>Atom</var>, -<var>Result0</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-atom_005fto_005fchars_002f3"></a>
<a name="index-atom_005fto_005fchars_002f3-1"></a>
<a name="index-atom_005fto_005fchars_002f3-2"></a>
<p>Convert the atom <var>Atom</var> to the difference list of character codes
<var>Result-Result0</var>.
</p>
</dd>
<dt><code>number_to_chars(+<var>Number</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-number_005fto_005fchars_002f2"></a>
<a name="index-number_005fto_005fchars_002f2-1"></a>
<a name="index-number_005fto_005fchars_002f2-2"></a>
<p>Convert the number <var>Number</var> to the string of character codes
<var>Result</var>.
</p>
</dd>
<dt><code>number_to_chars(+<var>Number</var>, -<var>Result0</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-number_005fto_005fchars_002f3"></a>
<a name="index-number_005fto_005fchars_002f3-1"></a>
<a name="index-number_005fto_005fchars_002f3-2"></a>
<p>Convert the atom <var>Number</var> to the difference list of character codes
<var>Result-Result0</var>.
</p>
</dd>
<dt><code>atom_to_term(+<var>Atom</var>, -<var>Term</var>, -<var>Bindings</var>)</code></dt>
<dd><a name="index-atom_005fto_005fterm_002f3"></a>
<a name="index-atom_005fto_005fterm_002f3-1"></a>
<a name="index-atom_005fto_005fterm_002f3-2"></a>
<p>Use <var>Atom</var> as input to <code>read_term/2</code> using the option <code>variable_names</code> and return the read term in <var>Term</var> and the variable bindings in <var>Bindings</var>. <var>Bindings</var> is a list of <code>Name = Var</code> couples, thus providing access to the actual variable names. See also <code>read_term/2</code>. If Atom has no valid syntax, a syntax_error exception is raised.
</p>
</dd>
<dt><code>term_to_atom(?<var>Term</var>, ?<var>Atom</var>)</code></dt>
<dd><a name="index-term_005fto_005fatom_002f2"></a>
<a name="index-term_005fto_005fatom_002f2-1"></a>
<a name="index-term_005fto_005fatom_002f2-2"></a>
<p>True if <var>Atom</var> describes a term that unifies with <var>Term</var>. When
<var>Atom</var> is instantiated <var>Atom</var> is converted and then unified with
<var>Term</var>. If <var>Atom</var> has no valid syntax, a syntax_error exception
is raised. Otherwise <var>Term</var> is &ldquo;written&rdquo; on <var>Atom</var> using
<code>write_term/2</code> with the option quoted(true).
</p>
</dd>
<dt><code>read_from_chars(+<var>Chars</var>, -<var>Term</var>)</code></dt>
<dd><a name="index-read_005ffrom_005fchars_002f2"></a>
<a name="index-read_005ffrom_005fchars_002f2-1"></a>
<a name="index-read_005ffrom_005fchars_002f2-2"></a>
<p>Parse the list of character codes <var>Chars</var> and return the result in
the term <var>Term</var>. 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.
</p>
</dd>
<dt><code>open_chars_stream(+<var>Chars</var>, -<var>Stream</var>)</code></dt>
<dd><a name="index-open_005fchars_005fstream_002f2"></a>
<a name="index-open_005fchars_005fstream_002f2-1"></a>
<a name="index-open_005fchars_005fstream_002f2-2"></a>
<p>Open the list of character codes <var>Chars</var> as a stream <var>Stream</var>.
</p>
</dd>
<dt><code>with_output_to_chars(?<var>Goal</var>, -<var>Chars</var>)</code></dt>
<dd><a name="index-with_005foutput_005fto_005fchars_002f2"></a>
<a name="index-with_005foutput_005fto_005fchars_002f2-1"></a>
<a name="index-with_005foutput_005fto_005fchars_002f2-2"></a>
<p>Execute goal <var>Goal</var> 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 <var>Chars</var>.
</p>
</dd>
<dt><code>with_output_to_chars(?<var>Goal</var>, ?<var>Chars0</var>, -<var>Chars</var>)</code></dt>
<dd><a name="index-with_005foutput_005fto_005fchars_002f3"></a>
<a name="index-with_005foutput_005fto_005fchars_002f3-1"></a>
<a name="index-with_005foutput_005fto_005fchars_002f3-2"></a>
<p>Execute goal <var>Goal</var> 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
<var>Chars-Chars0</var>.
</p>
</dd>
<dt><code>with_output_to_chars(?<var>Goal</var>, -<var>Stream</var>, ?<var>Chars0</var>, -<var>Chars</var>)</code></dt>
<dd><a name="index-with_005foutput_005fto_005fchars_002f4"></a>
<a name="index-with_005foutput_005fto_005fchars_002f4-1"></a>
<a name="index-with_005foutput_005fto_005fchars_002f4-2"></a>
<p>Execute goal <var>Goal</var> 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
<var>Chars-Chars0</var> and <var>Stream</var> receives the stream corresponding to
the memory buffer.
</p>
</dd>
</dl>
<p>The implementation of the character IO operations relies on three YAP
built-ins:
</p><dl compact="compact">
<dt><code>charsio:open_mem_read_stream(+<var>String</var>, -<var>Stream</var>)</code></dt>
<dd><p>Store a string in a memory buffer and output a stream that reads from this
memory buffer.
</p>
</dd>
<dt><code>charsio:open_mem_write_stream(-<var>Stream</var>)</code></dt>
<dd><p>Create a new memory buffer and output a stream that writes to it.
</p>
</dd>
<dt><code>charsio:peek_mem_write_stream(-<var>Stream</var>, L0, L)</code></dt>
<dd><p>Convert the memory buffer associated with stream <var>Stream</var> to the
difference list of character codes <var>L-L0</var>.
</p>
</dd>
</dl>
<p>These built-ins are initialized to belong to the module <code>charsio</code> in
<code>init.yap</code>. Novel procedures for manipulating strings by explicitly
importing these built-ins.
</p>
<p>YAP does not currently support opening a <code>charsio</code> stream in
<code>append</code> mode, or seeking in such a stream.
</p>
<hr>
<a name="System"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#String-I_002fO" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Terms" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Calling-The-Operating-System-from-YAP"></a>
<h2 class="section">7.22 Calling The Operating System from YAP</h2>
<a name="index-Operating-System-Utilities"></a>
<p>YAP now provides a library of system utilities compatible with the
SICStus Prolog system library. This library extends and to some point
replaces the functionality of Operating System access routines. The
library includes Unix/Linux and Win32 <code>C</code> code. They
are available through the <code>use_module(library(system))</code> command.
</p>
<dl compact="compact">
<dt><code>datime(datime(-<var>Year</var>, -<var>Month</var>, -<var>DayOfTheMonth</var>,</code></dt>
<dd><p>-<var>Hour</var>, -<var>Minute</var>, -<var>Second</var>)
<a name="index-datime_002f1"></a>
<a name="index-datime_002f1-1"></a>
<a name="index-datime_002f1-2"></a>
The <code>datime/1</code> procedure returns the current date and time, with
information on <var>Year</var>, <var>Month</var>, <var>DayOfTheMonth</var>,
<var>Hour</var>, <var>Minute</var>, and <var>Second</var>. The <var>Hour</var> is returned
on local time. This function uses the WIN32
<code>GetLocalTime</code> function or the Unix <code>localtime</code> function.
</p>
<div class="example">
<pre class="example"> ?- datime(X).
X = datime(2001,5,28,15,29,46) ?
</pre></div>
</dd>
<dt><code>mktime(datime(+<var>Year</var>, +<var>Month</var>, +<var>DayOfTheMonth</var>,</code></dt>
<dd><p>+<var>Hour</var>, +<var>Minute</var>, +<var>Second</var>), -<var>Seconds</var>)
<a name="index-mktime_002f2"></a>
<a name="index-mktime_002f2-1"></a>
<a name="index-mktime_002f2-2"></a>
The <code>mktime/1</code> procedure returns the number of <var>Seconds</var>
elapsed since 00:00:00 on January 1, 1970, Coordinated Universal Time
(UTC). The user provides information on <var>Year</var>, <var>Month</var>,
<var>DayOfTheMonth</var>, <var>Hour</var>, <var>Minute</var>, and <var>Second</var>. The
<var>Hour</var> is given on local time. This function uses the WIN32
<code>GetLocalTime</code> function or the Unix <code>mktime</code> function.
</p>
<div class="example">
<pre class="example"> ?- mktime(datime(2001,5,28,15,29,46),X).
X = 991081786 ? ;
</pre></div>
</dd>
<dt><code>delete_file(+<var>File</var>)</code></dt>
<dd><a name="index-delete_005ffile_002f1"></a>
<a name="index-delete_005ffile_002f1-1"></a>
<a name="index-delete_005ffile_002f1-2"></a>
<p>The <code>delete_file/1</code> procedure removes file <var>File</var>. If
<var>File</var> is a directory, remove the directory <em>and all its
subdirectories</em>.
</p>
<div class="example">
<pre class="example"> ?- delete_file(x).
</pre></div>
</dd>
<dt><code>delete_file(+<var>File</var>,+<var>Opts</var>)</code></dt>
<dd><a name="index-delete_005ffile_002f2"></a>
<a name="index-delete_005ffile_002f2-1"></a>
<a name="index-delete_005ffile_002f2-2"></a>
<p>The <code>delete_file/2</code> procedure removes file <var>File</var> according to
options <var>Opts</var>. These options are <code>directory</code> if one should
remove directories, <code>recursive</code> if one should remove directories
recursively, and <code>ignore</code> if errors are not to be reported.
</p>
<p>This example is equivalent to using the <code>delete_file/1</code> predicate:
</p><div class="example">
<pre class="example"> ?- delete_file(x, [recursive]).
</pre></div>
</dd>
<dt><code>directory_files(+<var>Dir</var>,+<var>List</var>)</code></dt>
<dd><a name="index-directory_005ffiles_002f2"></a>
<a name="index-directory_005ffiles_002f2-1"></a>
<a name="index-directory_005ffiles_002f2-2"></a>
<p>Given a directory <var>Dir</var>, <code>directory_files/2</code> procedures a
listing of all files and directories in the directory:
</p><div class="example">
<pre class="example"> ?- directory_files('.',L), writeq(L).
['Makefile.~1~','sys.so','Makefile','sys.o',x,..,'.']
</pre></div>
<p>The predicates uses the <code>dirent</code> family of routines in Unix
environments, and <code>findfirst</code> in WIN32.
</p>
</dd>
<dt><code>file_exists(+<var>File</var>)</code></dt>
<dd><a name="index-file_005fexists_002f1"></a>
<a name="index-file_005fexists_002f1-1"></a>
<a name="index-file_005fexists_002f1-2"></a>
<p>The atom <var>File</var> corresponds to an existing file.
</p>
</dd>
<dt><code>file_exists(+<var>File</var>,+<var>Permissions</var>)</code></dt>
<dd><a name="index-file_005fexists_002f2"></a>
<a name="index-file_005fexists_002f2-1"></a>
<a name="index-file_005fexists_002f2-2"></a>
<p>The atom <var>File</var> corresponds to an existing file with permissions
compatible with <var>Permissions</var>. YAP currently only accepts for
permissions to be described as a number. The actual meaning of this
number is Operating System dependent.
</p>
</dd>
<dt><code>file_property(+<var>File</var>,?<var>Property</var>)</code></dt>
<dd><a name="index-file_005fproperty_002f2"></a>
<a name="index-file_005fproperty_002f2-1"></a>
<a name="index-file_005fproperty_002f2-2"></a>
<p>The atom <var>File</var> corresponds to an existing file, and <var>Property</var>
will be unified with a property of this file. The properties are of the
form <code>type(<var>Type</var>)</code>, which gives whether the file is a regular
file, a directory, a fifo file, or of unknown type;
<code>size(<var>Size</var>)</code>, with gives the size for a file, and
<code>mod_time(<var>Time</var>)</code>, which gives the last time a file was
modified according to some Operating System dependent
timestamp; <code>mode(<var>mode</var>)</code>, gives the permission flags for the
file, and <code>linkto(<var>FileName</var>)</code>, gives the file pointed to by a
symbolic link. Properties can be obtained through backtracking:
</p>
<div class="example">
<pre class="example"> ?- file_property('Makefile',P).
P = type(regular) ? ;
P = size(2375) ? ;
P = mod_time(990826911) ? ;
no
</pre></div>
</dd>
<dt><code>make_directory(+<var>Dir</var>)</code></dt>
<dd><a name="index-make_005fdirectory_002f2"></a>
<a name="index-make_005fdirectory_002f2-1"></a>
<a name="index-make_005fdirectory_002f2-2"></a>
<p>Create a directory <var>Dir</var>. The name of the directory must be an atom.
</p>
</dd>
<dt><code>rename_file(+<var>OldFile</var>,+<var>NewFile</var>)</code></dt>
<dd><a name="index-rename_005ffile_002f2"></a>
<a name="index-rename_005ffile_002f2-1"></a>
<a name="index-rename_005ffile_002f2-2"></a>
<p>Create file <var>OldFile</var> to <var>NewFile</var>. This predicate uses the
<code>C</code> built-in function <code>rename</code>.
</p>
</dd>
<dt><code>environ(?<var>EnvVar</var>,+<var>EnvValue</var>)</code></dt>
<dd><a name="index-environ_002f2-3"></a>
<a name="index-environ_002f2-4"></a>
<a name="index-environ_002f2-5"></a>
<p>Unify environment variable <var>EnvVar</var> with its value <var>EnvValue</var>,
if there is one. This predicate is backtrackable in Unix systems, but
not currently in Win32 configurations.
</p>
<div class="example">
<pre class="example"> ?- environ('HOME',X).
X = 'C:\\cygwin\\home\\administrator' ?
</pre></div>
</dd>
<dt><code>host_id(-<var>Id</var>)</code></dt>
<dd><a name="index-host_005fid_002f1"></a>
<a name="index-host_005fid_002f1-1"></a>
<a name="index-host_005fid_002f1-2"></a>
<p>Unify <var>Id</var> with an identifier of the current host. YAP uses the
<code>hostid</code> function when available,
</p>
</dd>
<dt><code>host_name(-<var>Name</var>)</code></dt>
<dd><a name="index-host_005fname_002f1"></a>
<a name="index-host_005fname_002f1-1"></a>
<a name="index-host_005fname_002f1-2"></a>
<p>Unify <var>Name</var> with a name for the current host. YAP uses the
<code>hostname</code> function in Unix systems when available, and the
<code>GetComputerName</code> function in WIN32 systems.
</p>
</dd>
<dt><code>kill(<var>Id</var>,+<var>SIGNAL</var>)</code></dt>
<dd><a name="index-kill_002f2"></a>
<a name="index-kill_002f2-1"></a>
<a name="index-kill_002f2-2"></a>
<p>Send signal <var>SIGNAL</var> to process <var>Id</var>. In Unix this predicate is
a direct interface to <code>kill</code> so one can send signals to groups of
processes. In WIN32 the predicate is an interface to
<code>TerminateProcess</code>, so it kills <var>Id</var> independently of <var>SIGNAL</var>.
</p>
</dd>
<dt><code>mktemp(<var>Spec</var>,-<var>File</var>)</code></dt>
<dd><a name="index-mktemp_002f2"></a>
<a name="index-mktemp_002f2-1"></a>
<a name="index-mktemp_002f2-2"></a>
<p>Direct interface to <code>mktemp</code>: given a <var>Spec</var>, that is a file
name with six <var>X</var> to it, create a file name <var>File</var>. Use
<code>tmpnam/1</code> instead.
</p>
</dd>
<dt><code>pid(-<var>Id</var>)</code></dt>
<dd><a name="index-pid_002f1"></a>
<a name="index-pid_002f1-1"></a>
<a name="index-pid_002f1-2"></a>
<p>Unify <var>Id</var> with the process identifier for the current
process. An interface to the <tt>getpid</tt> function.
</p>
</dd>
<dt><code>tmpnam(-<var>File</var>)</code></dt>
<dd><a name="index-tmpnam_002f1"></a>
<a name="index-tmpnam_002f1-1"></a>
<a name="index-tmpnam_002f1-2"></a>
<p>Interface with <var>tmpnam</var>: obtain a new, unique file name <var>File</var>.
</p>
</dd>
<dt><code>tmp_file(-<var>File</var>)</code></dt>
<dd><a name="index-tmp_005ffile_002f2"></a>
<a name="index-tmp_005ffile_002f2-1"></a>
<a name="index-tmp_005ffile_002f2-2"></a>
<p>Create a name for a temporary file. <var>Base</var> is an user provided
identifier for the category of file. The <var>TmpName</var> is guaranteed to
be unique. If the system halts, it will automatically remove all created
temporary files.
</p>
</dd>
<dt><code>exec(+<var>Command</var>,[+<var>InputStream</var>,+<var>OutputStream</var>,+<var>ErrorStream</var>],-<var>PID</var>)</code></dt>
<dd><a name="index-exec_002f3"></a>
<a name="index-exec_002f3-1"></a>
<a name="index-exec_002f3-2"></a>
<p>Execute command <var>Command</var> with its streams connected to
<var>InputStream</var>, <var>OutputStream</var>, and <var>ErrorStream</var>. The
process that executes the command is returned as <var>PID</var>. The
command is executed by the default shell <code>bin/sh -c</code> in Unix.
</p>
<p>The following example demonstrates the use of <code>exec/3</code> to send a
command and process its output:
</p>
<div class="example">
<pre class="example">exec(ls,[std,pipe(S),null],P),repeat, get0(S,C), (C = -1, close(S) ! ; put(C)).
</pre></div>
<p>The streams may be one of standard stream, <code>std</code>, null stream,
<code>null</code>, or <code>pipe(S)</code>, where <var>S</var> is a pipe stream. Note
that it is up to the user to close the pipe.
</p>
</dd>
<dt><code>working_directory(-<var>CurDir</var>,?<var>NextDir</var>)</code></dt>
<dd><a name="index-working_005fdirectory_002f2"></a>
<a name="index-working_005fdirectory_002f2-1"></a>
<a name="index-working_005fdirectory_002f2-2"></a>
<p>Fetch the current directory at <var>CurDir</var>. If <var>NextDir</var> is bound
to an atom, make its value the current working directory.
</p>
</dd>
<dt><code>popen(+<var>Command</var>, +<var>TYPE</var>, -<var>Stream</var>)</code></dt>
<dd><a name="index-popen_002f3"></a>
<a name="index-popen_002f3-1"></a>
<a name="index-popen_002f3-2"></a>
<p>Interface to the <tt>popen</tt> function. It opens a process by creating a
pipe, forking and invoking <var>Command</var> on the current shell. Since a
pipe is by definition unidirectional the <var>Type</var> argument may be
<code>read</code> or <code>write</code>, not both. The stream should be closed
using <code>close/1</code>, there is no need for a special <code>pclose</code>
command.
</p>
<p>The following example demonstrates the use of <code>popen/3</code> to process
the output of a command, as <code>exec/3</code> would do:
</p>
<div class="example">
<pre class="example"> ?- popen(ls,read,X),repeat, get0(X,C), (C = -1, ! ; put(C)).
X = 'C:\\cygwin\\home\\administrator' ?
</pre></div>
<p>The WIN32 implementation of <code>popen/3</code> relies on <code>exec/3</code>.
</p>
</dd>
<dt><code>shell</code></dt>
<dd><a name="index-shell_002f0"></a>
<a name="index-shell_002f0-1"></a>
<a name="index-shell_002f0-2"></a>
<p>Start a new shell and leave YAP in background until the shell
completes. YAP uses the shell given by the environment variable
<code>SHELL</code>. In WIN32 environment YAP will use <code>COMSPEC</code> if
<code>SHELL</code> is undefined.
</p>
</dd>
<dt><code>shell(+<var>Command</var>)</code></dt>
<dd><a name="index-shell_002f1"></a>
<a name="index-shell_002f1-1"></a>
<a name="index-shell_002f1-2"></a>
<p>Execute command <var>Command</var> 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 <code>SHELL</code> with the option
<code>&quot; -c &quot;</code>. In WIN32 environment YAP will use <code>COMSPEC</code> if
<code>SHELL</code> is undefined, in this case with the option <code>&quot; /c &quot;</code>.
</p>
</dd>
<dt><code>shell(+<var>Command</var>,-<var>Status</var>)</code></dt>
<dd><a name="index-shell_002f1-3"></a>
<a name="index-shell_002f1-4"></a>
<a name="index-shell_002f1-5"></a>
<p>Execute command <var>Command</var> under a new shell and unify <var>Status</var>
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 <code>SHELL</code> with the option <code>&quot; -c &quot;</code>. In
WIN32 environment YAP will use <code>COMSPEC</code> if <code>SHELL</code> is
undefined, in this case with the option <code>&quot; /c &quot;</code>.
</p>
</dd>
<dt><code>sleep(+<var>Time</var>)</code></dt>
<dd><a name="index-sleep_002f1"></a>
<a name="index-sleep_002f1-1"></a>
<a name="index-sleep_002f1-2"></a>
<p>Block the current thread for <var>Time</var> seconds. When YAP is compiled
without multi-threading support, this predicate blocks the YAP process.
The number of seconds must be a positive number, and it may an integer
or a float. The Unix implementation uses <code>usleep</code> if the number of
seconds is below one, and <code>sleep</code> if it is over a second. The WIN32
implementation uses <code>Sleep</code> for both cases.
</p>
</dd>
<dt><code>system</code></dt>
<dd><a name="index-system_002f0"></a>
<a name="index-system_002f0-1"></a>
<a name="index-system_002f0-2"></a>
<p>Start a new default shell and leave YAP in background until the shell
completes. YAP uses <code>/bin/sh</code> in Unix systems and <code>COMSPEC</code> in
WIN32.
</p>
</dd>
<dt><code>system(+<var>Command</var>,-<var>Res</var>)</code></dt>
<dd><a name="index-system_002f2"></a>
<a name="index-system_002f2-1"></a>
<a name="index-system_002f2-2"></a>
<p>Interface to <code>system</code>: execute command <var>Command</var> and unify
<var>Res</var> with the result.
</p>
</dd>
<dt><code>wait(+<var>PID</var>,-<var>Status</var>)</code></dt>
<dd><a name="index-wait_002f2"></a>
<a name="index-wait_002f2-1"></a>
<a name="index-wait_002f2-2"></a>
<p>Wait until process <var>PID</var> terminates, and return its exits <var>Status</var>.
</p>
</dd>
</dl>
<hr>
<a name="Terms"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#System" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Tries" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Utilities-On-Terms"></a>
<h2 class="section">7.23 Utilities On Terms</h2>
<a name="index-utilities-on-terms"></a>
<p>The next routines provide a set of commonly used utilities to manipulate
terms. Most of these utilities have been implemented in <code>C</code> for
efficiency. They are available through the
<code>use_module(library(terms))</code> command.
</p>
<dl compact="compact">
<dt><code>cyclic_term(?<var>Term</var>)</code></dt>
<dd><a name="index-cyclic_005fterm_002f1-3"></a>
<a name="index-cyclic_005fterm_002f1-4"></a>
<a name="index-cyclic_005fterm_002f1-5"></a>
<p>Succeed if the argument <var>Term</var> is a cyclic term.
</p>
</dd>
<dt><code>term_hash(+<var>Term</var>, ?<var>Hash</var>)</code></dt>
<dd><a name="index-term_005fhash_002f2"></a>
<a name="index-term_005fhash_002f2-1"></a>
<a name="index-term_005fhash_002f2-2"></a>
<p>If <var>Term</var> is ground unify <var>Hash</var> with a positive integer
calculated from the structure of the term. Otherwise the argument
<var>Hash</var> is left unbound. The range of the positive integer is from
<code>0</code> to, but not including, <code>33554432</code>.
</p>
</dd>
<dt><code>term_hash(+<var>Term</var>, +<var>Depth</var>, +<var>Range</var>, ?<var>Hash</var>)</code></dt>
<dd><a name="index-term_005fhash_002f4"></a>
<a name="index-term_005fhash_002f4-1"></a>
<a name="index-term_005fhash_002f4-2"></a>
<p>Unify <var>Hash</var> with a positive integer calculated from the structure
of the term. The range of the positive integer is from <code>0</code> to, but
not including, <var>Range</var>. If <var>Depth</var> is <code>-1</code> the whole term
is considered. Otherwise, the term is considered only up to depth
<code>1</code>, where the constants and the principal functor have depth
<code>1</code>, and an argument of a term with depth <var>I</var> has depth <var>I+1</var>.
</p>
</dd>
<dt><code>term_variables(?<var>Term</var>, -<var>Variables</var>)</code></dt>
<dd><a name="index-term_005fvariables_002f2"></a>
<a name="index-term_005fvariables_002f2-1"></a>
<a name="index-term_005fvariables_002f2-2"></a>
<p>Unify <var>Variables</var> with the list of all variables of term
<var>Term</var>. The variables occur in the order of their first
appearance when traversing the term depth-first, left-to-right.
</p>
</dd>
<dt><code>variables_within_term(+<var>Variables</var>,?<var>Term</var>, -<var>OutputVariables</var>)</code></dt>
<dd><a name="index-variables_005fwithin_005fterm_002f3"></a>
<a name="index-variables_005fwithin_005fterm_002f3-1"></a>
<a name="index-variables_005fwithin_005fterm_002f3-2"></a>
<p>Unify <var>OutputVariables</var> with the subset of the variables <var>Variables</var> that occurs in <var>Term</var>.
</p>
</dd>
<dt><code>new_variables_in_term(+<var>Variables</var>,?<var>Term</var>, -<var>OutputVariables</var>)</code></dt>
<dd><a name="index-new_005fvariables_005fin_005fterm_002f3"></a>
<a name="index-new_005fvariables_005fin_005fterm_002f3-1"></a>
<a name="index-new_005fvariables_005fin_005fterm_002f3-2"></a>
<p>Unify <var>OutputVariables</var> with all variables occurring in <var>Term</var> that are not in the list <var>Variables</var>.
</p>
</dd>
<dt><code>variant(?<var>Term1</var>, ?<var>Term2</var>)</code></dt>
<dd><a name="index-variant_002f2"></a>
<a name="index-variant_002f2-1"></a>
<a name="index-variant_002f2-2"></a>
<p>Succeed if <var>Term1</var> and <var>Term2</var> are variant terms.
</p>
</dd>
<dt><code>subsumes(?<var>Term1</var>, ?<var>Term2</var>)</code></dt>
<dd><a name="index-subsumes_002f2"></a>
<a name="index-subsumes_002f2-1"></a>
<a name="index-subsumes_002f2-2"></a>
<p>Succeed if <var>Term1</var> subsumes <var>Term2</var>. Variables in term
<var>Term1</var> are bound so that the two terms become equal.
</p>
</dd>
<dt><code>subsumes_chk(?<var>Term1</var>, ?<var>Term2</var>)</code></dt>
<dd><a name="index-subsumes_005fchk_002f2"></a>
<a name="index-subsumes_005fchk_002f2-1"></a>
<a name="index-subsumes_005fchk_002f2-2"></a>
<p>Succeed if <var>Term1</var> subsumes <var>Term2</var> but does not bind any
variable in <var>Term1</var>.
</p>
</dd>
<dt><code>variable_in_term(?<var>Term</var>,?<var>Var</var>)</code></dt>
<dd><a name="index-variable_005fin_005fterm_002f2"></a>
<a name="index-variable_005fin_005fterm_002f2-1"></a>
<a name="index-variable_005fin_005fterm_002f2-2"></a>
<p>Succeed if the second argument <var>Var</var> is a variable and occurs in
term <var>Term</var>.
</p>
</dd>
<dt><code>unifiable(?<var>Term1</var>, ?<var>Term2</var>, -<var>Bindings</var>)</code></dt>
<dd><a name="index-unifiable_002f3"></a>
<a name="index-unifiable_002f3-1"></a>
<a name="index-unifiable_002f3-2"></a>
<p>Succeed if <var>Term1</var> and <var>Term2</var> are unifiable with substitution
<var>Bindings</var>.
</p>
</dd>
</dl>
<hr>
<a name="Tries"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Terms" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Cleanup" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Trie-DataStructure"></a>
<h2 class="section">7.24 Trie DataStructure</h2>
<a name="index-tries"></a>
<p>The next routines provide a set of utilities to create and manipulate
prefix trees of Prolog terms. Tries were originally proposed to
implement tabling in Logic Programming, but can be used for other
purposes. The tries will be stored in the Prolog database and can seen
as alternative to <code>assert</code> and <code>record</code> family of
primitives. Most of these utilities have been implemented in <code>C</code>
for efficiency. They are available through the
<code>use_module(library(tries))</code> command.
</p>
<dl compact="compact">
<dt><code>trie_open(-<var>Id</var>)</code></dt>
<dd><a name="index-trie_005fopen_002f1"></a>
<a name="index-trie_005fopen_002f1-1"></a>
<a name="index-trie_005fopen_002f1-2"></a>
<p>Open a new trie with identifier <var>Id</var>.
</p>
</dd>
<dt><code>trie_close(+<var>Id</var>)</code></dt>
<dd><a name="index-trie_005fclose_002f1"></a>
<a name="index-trie_005fclose_002f1-1"></a>
<a name="index-trie_005fclose_002f1-2"></a>
<p>Close trie with identifier <var>Id</var>.
</p>
</dd>
<dt><code>trie_close_all</code></dt>
<dd><a name="index-trie_005fclose_005fall_002f0"></a>
<a name="index-trie_005fclose_005fall_002f0-1"></a>
<a name="index-trie_005fclose_005fall_002f0-2"></a>
<p>Close all available tries.
</p>
</dd>
<dt><code>trie_mode(?<var>Mode</var>)</code></dt>
<dd><a name="index-trie_005fmode_002f1"></a>
<a name="index-trie_005fmode_002f1-1"></a>
<a name="index-trie_005fmode_002f1-2"></a>
<p>Unify <var>Mode</var> with trie operation mode. Allowed values are either
<code>std</code> (default) or <code>rev</code>.
</p>
</dd>
<dt><code>trie_put_entry(+<var>Trie</var>,+<var>Term</var>,-<var>Ref</var>)</code></dt>
<dd><a name="index-trie_005fput_005fentry_002f3"></a>
<a name="index-trie_005fput_005fentry_002f3-1"></a>
<a name="index-trie_005fput_005fentry_002f3-2"></a>
<p>Add term <var>Term</var> to trie <var>Trie</var>. The handle <var>Ref</var> gives
a reference to the term.
</p>
</dd>
<dt><code>trie_check_entry(+<var>Trie</var>,+<var>Term</var>,-<var>Ref</var>)</code></dt>
<dd><a name="index-trie_005fcheck_005fentry_002f3"></a>
<a name="index-trie_005fcheck_005fentry_002f3-1"></a>
<a name="index-trie_005fcheck_005fentry_002f3-2"></a>
<p>Succeeds if a variant of term <var>Term</var> is in trie <var>Trie</var>. An handle
<var>Ref</var> gives a reference to the term.
</p>
</dd>
<dt><code>trie_get_entry(+<var>Ref</var>,-<var>Term</var>)</code></dt>
<dd><a name="index-trie_005fget_005fentry_002f2"></a>
<a name="index-trie_005fget_005fentry_002f2-1"></a>
<a name="index-trie_005fget_005fentry_002f2-2"></a>
<p>Unify <var>Term</var> with the entry for handle <var>Ref</var>.
</p>
</dd>
<dt><code>trie_remove_entry(+<var>Ref</var>)</code></dt>
<dd><a name="index-trie_005fremove_005fentry_002f1"></a>
<a name="index-trie_005fremove_005fentry_002f1-1"></a>
<a name="index-trie_005fremove_005fentry_002f1-2"></a>
<p>Remove entry for handle <var>Ref</var>.
</p>
</dd>
<dt><code>trie_remove_subtree(+<var>Ref</var>)</code></dt>
<dd><a name="index-trie_005fremove_005fsubtree_002f1"></a>
<a name="index-trie_005fremove_005fsubtree_002f1-1"></a>
<a name="index-trie_005fremove_005fsubtree_002f1-2"></a>
<p>Remove subtree rooted at handle <var>Ref</var>.
</p>
</dd>
<dt><code>trie_save(+<var>Trie</var>,+<var>FileName</var>)</code></dt>
<dd><a name="index-trie_005fsave_002f2"></a>
<a name="index-trie_005fsave_002f2-1"></a>
<a name="index-trie_005fsave_002f2-2"></a>
<p>Dump trie <var>Trie</var> into file <var>FileName</var>.
</p>
</dd>
<dt><code>trie_load(+<var>Trie</var>,+<var>FileName</var>)</code></dt>
<dd><a name="index-trie_005fload_002f2"></a>
<a name="index-trie_005fload_002f2-1"></a>
<a name="index-trie_005fload_002f2-2"></a>
<p>Load trie <var>Trie</var> from the contents of file <var>FileName</var>.
</p>
</dd>
<dt><code>trie_stats(-<var>Memory</var>,-<var>Tries</var>,-<var>Entries</var>,-<var>Nodes</var>)</code></dt>
<dd><a name="index-trie_005fstats_002f4"></a>
<a name="index-trie_005fstats_002f4-1"></a>
<a name="index-trie_005fstats_002f4-2"></a>
<p>Give generic statistics on tries, including the amount of memory,
<var>Memory</var>, the number of tries, <var>Tries</var>, the number of entries,
<var>Entries</var>, and the total number of nodes, <var>Nodes</var>.
</p>
</dd>
<dt><code>trie_max_stats(-<var>Memory</var>,-<var>Tries</var>,-<var>Entries</var>,-<var>Nodes</var>)</code></dt>
<dd><a name="index-trie_005fmax_005fstats_002f4"></a>
<a name="index-trie_005fmax_005fstats_002f4-1"></a>
<a name="index-trie_005fmax_005fstats_002f4-2"></a>
<p>Give maximal statistics on tries, including the amount of memory,
<var>Memory</var>, the number of tries, <var>Tries</var>, the number of entries,
<var>Entries</var>, and the total number of nodes, <var>Nodes</var>.
</p>
</dd>
<dt><code>trie_usage(+<var>Trie</var>,-<var>Entries</var>,-<var>Nodes</var>,-<var>VirtualNodes</var>)</code></dt>
<dd><a name="index-trie_005fusage_002f4"></a>
<a name="index-trie_005fusage_002f4-1"></a>
<a name="index-trie_005fusage_002f4-2"></a>
<p>Give statistics on trie <var>Trie</var>, the number of entries,
<var>Entries</var>, and the total number of nodes, <var>Nodes</var>, and the
number of <var>VirtualNodes</var>.
</p>
</dd>
<dt><code>trie_print(+<var>Trie</var>)</code></dt>
<dd><a name="index-trie_005fprint_002f1"></a>
<a name="index-trie_005fprint_002f1-1"></a>
<a name="index-trie_005fprint_002f1-2"></a>
<p>Print trie <var>Trie</var> on standard output.
</p>
</dd>
</dl>
<hr>
<a name="Cleanup"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tries" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Timeout" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Call-Cleanup"></a>
<h2 class="section">7.25 Call Cleanup</h2>
<a name="index-cleanup"></a>
<p><tt>call_cleanup/1</tt> and <tt>call_cleanup/2</tt> allow predicates to register
code for execution after the call is finished. Predicates can be
declared to be <tt>fragile</tt> to ensure that <tt>call_cleanup</tt> is called
for any Goal which needs it. This library is loaded with the
<code>use_module(library(cleanup))</code> command.
</p>
<dl compact="compact">
<dt><code>:- fragile <var>P</var>,....,<var>Pn</var></code></dt>
<dd><a name="index-fragile"></a>
<a name="index-fragile-1"></a>
<a name="index-fragile-2"></a>
<p>Declares the predicate <var>P</var>=<tt>[module:]name/arity</tt> as a fragile
predicate, module is optional, default is the current
typein_module. Whenever such a fragile predicate is used in a query
it will be called through call_cleanup/1.
</p><div class="example">
<pre class="example">:- fragile foo/1,bar:baz/2.
</pre></div>
</dd>
<dt><code>call_cleanup(:<var>Goal</var>)</code></dt>
<dd><a name="index-call_005fcleanup_002f1"></a>
<a name="index-call_005fcleanup_002f1-1"></a>
<a name="index-call_005fcleanup_002f1-2"></a>
<p>Execute goal <var>Goal</var> within a cleanup-context. Called predicates
might register cleanup Goals which are called right after the end of
the call to <var>Goal</var>. Cuts and exceptions inside Goal do not prevent the
execution of the cleanup calls. <tt>call_cleanup</tt> might be nested.
</p>
</dd>
<dt><code>call_cleanup(:<var>Goal</var>, :<var>CleanUpGoal</var>)</code></dt>
<dd><a name="index-call_005fcleanup_002f2"></a>
<a name="index-call_005fcleanup_002f2-1"></a>
<a name="index-call_005fcleanup_002f2-2"></a>
<p>This is similar to <tt>call_cleanup/1</tt> with an additional
<var>CleanUpGoal</var> which gets called after <var>Goal</var> is finished.
</p>
</dd>
<dt><code>setup_call_cleanup(:<var>Setup</var>,:<var>Goal</var>, :<var>CleanUpGoal</var>)</code></dt>
<dd><a name="index-setup_005fcall_005fcleanup_002f3"></a>
<a name="index-setup_005fcall_005fcleanup_002f3-1"></a>
<a name="index-setup_005fcall_005fcleanup_002f3-2"></a>
<p>Calls <code>(Setup, Goal)</code>. For each sucessful execution of <var>Setup</var>, calling <var>Goal</var>, the
cleanup handler <var>Cleanup</var> is guaranteed to be called exactly once.
This will happen after <var>Goal</var> completes, either through failure,
deterministic success, commit, or an exception. <var>Setup</var> will
contain the goals that need to be protected from asynchronous interrupts
such as the ones received from <code>call_with_time_limit/2</code> or <code>thread_signal/2</code>. In
most uses, <var>Setup</var> will perform temporary side-effects required by
<var>Goal</var> that are finally undone by <var>Cleanup</var>.
</p>
<p>Success or failure of <var>Cleanup</var> is ignored and choice-points it
created are destroyed (as <code>once/1</code>). If <var>Cleanup</var> throws an exception,
this is executed as normal.
</p>
<p>Typically, this predicate is used to cleanup permanent data storage
required to execute <var>Goal</var>, close file-descriptors, etc. The example
below provides a non-deterministic search for a term in a file, closing
the stream as needed.
</p>
<div class="example">
<pre class="example">term_in_file(Term, File) :-
setup_call_cleanup(open(File, read, In),
term_in_stream(Term, In),
close(In) ).
term_in_stream(Term, In) :-
repeat,
read(In, T),
( T == end_of_file
-&gt; !, fail
; T = Term
).
</pre></div>
<p>Note that it is impossible to implement this predicate in Prolog other than
by reading all terms into a list, close the file and call <code>member/2</code>.
Without <code>setup_call_cleanup/3</code> there is no way to gain control if the
choice-point left by <code>repeat</code> is removed by a cut or an exception.
</p>
<p><code>setup_call_cleanup/2</code> can also be used to test determinism of a goal:
</p>
<div class="example">
<pre class="example">?- setup_call_cleanup(true,(X=1;X=2), Det=yes).
X = 1 ;
X = 2,
Det = yes ;
</pre></div>
<p>This predicate is under consideration for inclusion into the ISO standard.
For compatibility with other Prolog implementations see <code>call_cleanup/2</code>.
</p>
</dd>
<dt><code>setup_call_catcher_cleanup(:<var>Setup</var>,:<var>Goal</var>, +<var>Catcher</var>,:<var>CleanUpGoal</var>)</code></dt>
<dd><a name="index-setup_005fcall_005fcatcher_005fcleanup_002f4"></a>
<a name="index-setup_005fcall_005fcatcher_005fcleanup_002f4-1"></a>
<a name="index-setup_005fcall_005fcatcher_005fcleanup_002f4-2"></a>
<p>Similar to <code>setup_call_cleanup(<var>Setup</var>, <var>Goal</var>, <var>Cleanup</var>)</code> with
additional information on the reason of calling <var>Cleanup</var>. Prior
to calling <var>Cleanup</var>, <var>Catcher</var> unifies with the termination
code. If this unification fails, <var>Cleanup</var> is
<strong>not</strong> called.
</p>
</dd>
<dt><code>on_cleanup(+<var>CleanUpGoal</var>)</code></dt>
<dd><a name="index-on_005fcleanup_002f1"></a>
<a name="index-on_005fcleanup_002f1-1"></a>
<a name="index-on_005fcleanup_002f1-2"></a>
<p>Any Predicate might registers a <var>CleanUpGoal</var>. The
<var>CleanUpGoal</var> is put onto the current cleanup context. All such
CleanUpGoals are executed in reverse order of their registration when
the surrounding cleanup-context ends. This call will throw an exception
if a predicate tries to register a <var>CleanUpGoal</var> outside of any
cleanup-context.
</p>
</dd>
<dt><code>cleanup_all</code></dt>
<dd><a name="index-cleanup_005fall_002f0"></a>
<a name="index-cleanup_005fall_002f0-1"></a>
<a name="index-cleanup_005fall_002f0-2"></a>
<p>Calls all pending CleanUpGoals and resets the cleanup-system to an
initial state. Should only be used as one of the last calls in the
main program.
</p>
</dd>
</dl>
<p>There are some private predicates which could be used in special
cases, such as manually setting up cleanup-contexts and registering
CleanUpGoals for other than the current cleanup-context.
Read the Source Luke.
</p>
<hr>
<a name="Timeout"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Cleanup" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Trees" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Calls-With-Timeout"></a>
<h2 class="section">7.26 Calls With Timeout</h2>
<a name="index-timeout"></a>
<p>The <tt>time_out/3</tt> command relies on the <tt>alarm/3</tt> built-in to
implement a call with a maximum time of execution. The command is
available with the <code>use_module(library(timeout))</code> command.
</p>
<dl compact="compact">
<dt><code>time_out(+<var>Goal</var>, +<var>Timeout</var>, -<var>Result</var>)</code></dt>
<dd><a name="index-time_005fout_002f3"></a>
<a name="index-time_005fout_002f3-1"></a>
<a name="index-time_005fout_002f3-2"></a>
<p>Execute goal <var>Goal</var> with time limited <var>Timeout</var>, where
<var>Timeout</var> is measured in milliseconds. If the goal succeeds, unify
<var>Result</var> with success. If the timer expires before the goal
terminates, unify <var>Result</var> with <tt>time_out</tt>.
</p>
<p>This command is implemented by activating an alarm at procedure
entry. If the timer expires before the goal completes, the alarm will
throw an exception <var>timeout</var>.
</p>
<p>One should note that <code>time_out/3</code> is not reentrant, that is, a goal
called from <code>time_out</code> should never itself call
<code>time_out/3</code>. Moreover, <code>time_out/3</code> will deactivate any previous
alarms set by <code>alarm/3</code> and vice-versa, hence only one of these
calls should be used in a program.
</p>
<p>Last, even though the timer is set in milliseconds, the current
implementation relies on <tt>alarm/3</tt>, and therefore can only offer
precision on the scale of seconds.
</p>
</dd>
</dl>
<hr>
<a name="Trees"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Timeout" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#UGraphs" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Updatable-Binary-Trees"></a>
<h2 class="section">7.27 Updatable Binary Trees</h2>
<a name="index-updatable-tree"></a>
<p>The following queue manipulation routines are available once
included with the <code>use_module(library(trees))</code> command.
</p>
<dl compact="compact">
<dt><code>get_label(+<var>Index</var>, +<var>Tree</var>, ?<var>Label</var>)</code></dt>
<dd><a name="index-get_005flabel_002f3"></a>
<a name="index-get_005flabel_002f3-1"></a>
<a name="index-get_005flabel_002f3-2"></a>
<p>Treats the tree as an array of <var>N</var> elements and returns the
<var>Index</var>-th.
</p>
</dd>
<dt><code>list_to_tree(+<var>List</var>, -<var>Tree</var>)</code></dt>
<dd><a name="index-list_005fto_005ftree_002f2"></a>
<a name="index-list_005fto_005ftree_002f2-1"></a>
<a name="index-list_005fto_005ftree_002f2-2"></a>
<p>Takes a given <var>List</var> of <var>N</var> elements and constructs a binary
<var>Tree</var>.
</p>
</dd>
<dt><code>map_tree(+<var>Pred</var>, +<var>OldTree</var>, -<var>NewTree</var>)</code></dt>
<dd><a name="index-map_005ftree_002f3"></a>
<a name="index-map_005ftree_002f3-1"></a>
<a name="index-map_005ftree_002f3-2"></a>
<p>Holds when <var>OldTree</var> and <var>NewTree</var> are binary trees of the same shape
and <code>Pred(Old,New)</code> is true for corresponding elements of the two trees.
</p>
</dd>
<dt><code>put_label(+<var>Index</var>, +<var>OldTree</var>, +<var>Label</var>, -<var>NewTree</var>)</code></dt>
<dd><a name="index-put_005flabel_002f4"></a>
<a name="index-put_005flabel_002f4-1"></a>
<a name="index-put_005flabel_002f4-2"></a>
<p>constructs a new tree the same shape as the old which moreover has the
same elements except that the <var>Index</var>-th one is <var>Label</var>.
</p>
</dd>
<dt><code>tree_size(+<var>Tree</var>, -<var>Size</var>)</code></dt>
<dd><a name="index-tree_005fsize_002f2"></a>
<a name="index-tree_005fsize_002f2-1"></a>
<a name="index-tree_005fsize_002f2-2"></a>
<p>Calculates the number of elements in the <var>Tree</var>.
</p>
</dd>
<dt><code>tree_to_list(+<var>Tree</var>, -<var>List</var>)</code></dt>
<dd><a name="index-tree_005fto_005flist_002f2"></a>
<a name="index-tree_005fto_005flist_002f2-1"></a>
<a name="index-tree_005fto_005flist_002f2-2"></a>
<p>Is the converse operation to list_to_tree.
</p>
</dd>
</dl>
<hr>
<a name="UGraphs"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Trees" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#DGraphs" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Unweighted-Graphs"></a>
<h2 class="section">7.28 Unweighted Graphs</h2>
<a name="index-unweighted-graphs"></a>
<p>The following graph manipulation routines are based in code originally
written by Richard O&rsquo;Keefe. The code was then extended to be compatible
with the SICStus Prolog ugraphs library. The routines assume directed
graphs, undirected graphs may be implemented by using two edges. Graphs
are represented in one of two ways:
</p>
<ul>
<li> The P-representation of a graph is a list of (from-to) vertex
pairs, where the pairs can be in any old order. This form is
convenient for input/output.
</li><li> The S-representation of a graph is a list of (vertex-neighbors)
pairs, where the pairs are in standard order (as produced by keysort)
and the neighbors of each vertex are also in standard order (as
produced by sort). This form is convenient for many calculations.
</li></ul>
<p>These built-ins are available once included with the
<code>use_module(library(ugraphs))</code> command.
</p>
<dl compact="compact">
<dt><code>vertices_edges_to_ugraph(+<var>Vertices</var>, +<var>Edges</var>, -<var>Graph</var>)</code></dt>
<dd><a name="index-vertices_005fedges_005fto_005fugraph_002f3"></a>
<a name="index-vertices_005fedges_005fto_005fugraph_002f3-1"></a>
<a name="index-vertices_005fedges_005fto_005fugraph_002f3-2"></a>
<p>Given a graph with a set of vertices <var>Vertices</var> and a set of edges
<var>Edges</var>, <var>Graph</var> must unify with the corresponding
s-representation. Note that the vertices without edges will appear in
<var>Vertices</var> but not in <var>Edges</var>. Moreover, it is sufficient for a
vertex to appear in <var>Edges</var>.
</p><div class="example">
<pre class="example">?- vertices_edges_to_ugraph([],[1-3,2-4,4-5,1-5],L).
L = [1-[3,5],2-[4],3-[],4-[5],5-[]] ?
</pre></div>
<p>In this case all edges are defined implicitly. The next example shows
three unconnected edges:
</p><div class="example">
<pre class="example">?- 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-[]] ?
</pre></div>
</dd>
<dt><code>vertices(+<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-vertices_002f2"></a>
<a name="index-vertices_002f2-1"></a>
<a name="index-vertices_002f2-2"></a>
<p>Unify <var>Vertices</var> with all vertices appearing in graph
<var>Graph</var>. In the next example:
</p><div class="example">
<pre class="example">?- vertices([1-[3,5],2-[4],3-[],4-[5],5-[]], V).
L = [1,2,3,4,5]
</pre></div>
</dd>
<dt><code>edges(+<var>Graph</var>, -<var>Edges</var>)</code></dt>
<dd><a name="index-edges_002f2"></a>
<a name="index-edges_002f2-1"></a>
<a name="index-edges_002f2-2"></a>
<p>Unify <var>Edges</var> with all edges appearing in graph
<var>Graph</var>. In the next example:
</p><div class="example">
<pre class="example">?- vertices([1-[3,5],2-[4],3-[],4-[5],5-[]], V).
L = [1,2,3,4,5]
</pre></div>
</dd>
<dt><code>add_vertices(+<var>Graph</var>, +<var>Vertices</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-add_005fvertices_002f3"></a>
<a name="index-add_005fvertices_002f3-1"></a>
<a name="index-add_005fvertices_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by adding the list of
vertices <var>Vertices</var> to the graph <var>Graph</var>. In the next example:
</p><div class="example">
<pre class="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-[]]
</pre></div>
</dd>
<dt><code>del_vertices(+<var>Graph</var>, +<var>Vertices</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-del_005fvertices_002f3"></a>
<a name="index-del_005fvertices_002f3-1"></a>
<a name="index-del_005fvertices_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by deleting the list of
vertices <var>Vertices</var> and all the edges that start from or go to a
vertex in <var>Vertices</var> to the graph <var>Graph</var>. In the next example:
</p><div class="example">
<pre class="example">?- del_vertices([2,1],[1-[3,5],2-[4],3-[],
4-[5],5-[],6-[],7-[2,6],8-[]],NL).
NL = [3-[],4-[5],5-[],6-[],7-[6],8-[]]
</pre></div>
</dd>
<dt><code>add_edges(+<var>Graph</var>, +<var>Edges</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-add_005fedges_002f3"></a>
<a name="index-add_005fedges_002f3-1"></a>
<a name="index-add_005fedges_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by adding the list of
edges <var>Edges</var> to the graph <var>Graph</var>. In the next example:
</p><div class="example">
<pre class="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-[]]
</pre></div>
</dd>
<dt><code>del_edges(+<var>Graph</var>, +<var>Edges</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-del_005fedges_002f3"></a>
<a name="index-del_005fedges_002f3-1"></a>
<a name="index-del_005fedges_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by removing the list of
edges <var>Edges</var> from the graph <var>Graph</var>. Notice that no vertices
are deleted. In the next example:
</p><div class="example">
<pre class="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-[]]
</pre></div>
</dd>
<dt><code>transpose(+<var>Graph</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-transpose_002f3"></a>
<a name="index-transpose_002f3-1"></a>
<a name="index-transpose_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained from <var>Graph</var> by
replacing all edges of the form <var>V1-V2</var> by edges of the form
<var>V2-V1</var>. The cost is <code>O(|V|^2)</code>. In the next example:
</p><div class="example">
<pre class="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-[]]
</pre></div>
<p>Notice that an undirected graph is its own transpose.
</p>
</dd>
<dt><code>neighbors(+<var>Vertex</var>, +<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-neighbors_002f3"></a>
<a name="index-neighbors_002f3-1"></a>
<a name="index-neighbors_002f3-2"></a>
<p>Unify <var>Vertices</var> with the list of neighbors of vertex <var>Vertex</var>
in <var>Graph</var>. If the vertice is not in the graph fail. In the next
example:
</p><div class="example">
<pre class="example">?- neighbors(4,[1-[3,5],2-[4],3-[],
4-[1,2,7,5],5-[],6-[],7-[],8-[]],
NL).
NL = [1,2,7,5]
</pre></div>
</dd>
<dt><code>neighbours(+<var>Vertex</var>, +<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-neighbours_002f3"></a>
<a name="index-neighbours_002f3-1"></a>
<a name="index-neighbours_002f3-2"></a>
<p>Unify <var>Vertices</var> with the list of neighbours of vertex <var>Vertex</var>
in <var>Graph</var>. In the next example:
</p><div class="example">
<pre class="example">?- neighbours(4,[1-[3,5],2-[4],3-[],
4-[1,2,7,5],5-[],6-[],7-[],8-[]], NL).
NL = [1,2,7,5]
</pre></div>
</dd>
<dt><code>complement(+<var>Graph</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-complement_002f2"></a>
<a name="index-complement_002f2-1"></a>
<a name="index-complement_002f2-2"></a>
<p>Unify <var>NewGraph</var> with the graph complementary to <var>Graph</var>.
In the next example:
</p><div class="example">
<pre class="example">?- 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]]
</pre></div>
</dd>
<dt><code>compose(+<var>LeftGraph</var>, +<var>RightGraph</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-compose_002f3"></a>
<a name="index-compose_002f3-1"></a>
<a name="index-compose_002f3-2"></a>
<p>Compose the graphs <var>LeftGraph</var> and <var>RightGraph</var> to form <var>NewGraph</var>.
In the next example:
</p><div class="example">
<pre class="example">?- compose([1-[2],2-[3]],[2-[4],3-[1,2,4]],L).
L = [1-[4],2-[1,2,4],3-[]]
</pre></div>
</dd>
<dt><code>top_sort(+<var>Graph</var>, -<var>Sort</var>)</code></dt>
<dd><a name="index-top_005fsort_002f2"></a>
<a name="index-top_005fsort_002f2-1"></a>
<a name="index-top_005fsort_002f2-2"></a>
<p>Generate the set of nodes <var>Sort</var> as a topological sorting of graph
<var>Graph</var>, if one is possible.
In the next example we show how topological sorting works for a linear graph:
</p><div class="example">
<pre class="example">?- top_sort([_138-[_219],_219-[_139], _139-[]],L).
L = [_138,_219,_139]
</pre></div>
</dd>
<dt><code>top_sort(+<var>Graph</var>, -<var>Sort0</var>, -<var>Sort</var>)</code></dt>
<dd><a name="index-top_005fsort_002f3"></a>
<a name="index-top_005fsort_002f3-1"></a>
<a name="index-top_005fsort_002f3-2"></a>
<p>Generate the difference list <var>Sort</var>-<var>Sort0</var> as a topological
sorting of graph <var>Graph</var>, if one is possible.
</p>
</dd>
<dt><code>transitive_closure(+<var>Graph</var>, +<var>Closure</var>)</code></dt>
<dd><a name="index-transitive_005fclosure_002f2"></a>
<a name="index-transitive_005fclosure_002f2-1"></a>
<a name="index-transitive_005fclosure_002f2-2"></a>
<p>Generate the graph <var>Closure</var> as the transitive closure of graph
<var>Graph</var>.
In the next example:
</p><div class="example">
<pre class="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]]
</pre></div>
</dd>
<dt><code>reachable(+<var>Node</var>, +<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-reachable_002f3"></a>
<a name="index-reachable_002f3-1"></a>
<a name="index-reachable_002f3-2"></a>
<p>Unify <var>Vertices</var> with the set of all vertices in graph
<var>Graph</var> that are reachable from <var>Node</var>. In the next example:
</p><div class="example">
<pre class="example">?- reachable(1,[1-[3,5],2-[4],3-[],4-[5],5-[]],V).
V = [1,3,5]
</pre></div>
</dd>
</dl>
<hr>
<a name="DGraphs"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#UGraphs" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#UnDGraphs" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Directed-Graphs"></a>
<h2 class="section">7.29 Directed Graphs</h2>
<a name="index-Efficient-Directed-Graphs"></a>
<p>The following graph manipulation routines use the red-black tree library
to try to avoid linear-time scans of the graph for all graph
operations. Graphs are represented as a red-black tree, where the key is
the vertex, and the associated value is a list of vertices reachable
from that vertex through an edge (ie, a list of edges).
</p>
<dl compact="compact">
<dt><code>dgraph_new(+<var>Graph</var>)</code></dt>
<dd><a name="index-dgraph_005fnew_002f1"></a>
<a name="index-dgraph_005fnew_002f1-1"></a>
<a name="index-dgraph_005fnew_002f1-2"></a>
<p>Create a new directed graph. This operation must be performed before
trying to use the graph.
</p>
</dd>
<dt><code>dgraph_vertices(+<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-dgraph_005fvertices_002f2"></a>
<a name="index-dgraph_005fvertices_002f2-1"></a>
<a name="index-dgraph_005fvertices_002f2-2"></a>
<p>Unify <var>Vertices</var> with all vertices appearing in graph
<var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_edge(+<var>N1</var>, +<var>N2</var>, +<var>Graph</var>)</code></dt>
<dd><a name="index-dgraph_005fedge_002f2"></a>
<a name="index-dgraph_005fedge_002f2-1"></a>
<a name="index-dgraph_005fedge_002f2-2"></a>
<p>Edge <var>N1</var>-<var>N2</var> is an edge in directed graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_edges(+<var>Graph</var>, -<var>Edges</var>)</code></dt>
<dd><a name="index-dgraph_005fedges_002f2"></a>
<a name="index-dgraph_005fedges_002f2-1"></a>
<a name="index-dgraph_005fedges_002f2-2"></a>
<p>Unify <var>Edges</var> with all edges appearing in graph
<var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_add_vertices(+<var>Graph</var>, +<var>Vertex</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fadd_005fvertex_002f3"></a>
<a name="index-dgraph_005fadd_005fvertex_002f3-1"></a>
<a name="index-dgraph_005fadd_005fvertex_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by adding
vertex <var>Vertex</var> to the graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_add_vertices(+<var>Graph</var>, +<var>Vertices</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fadd_005fvertices_002f3"></a>
<a name="index-dgraph_005fadd_005fvertices_002f3-1"></a>
<a name="index-dgraph_005fadd_005fvertices_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by adding the list of
vertices <var>Vertices</var> to the graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_del_vertex(+<var>Graph</var>, +<var>Vertex</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fdel_005fvertex_002f3"></a>
<a name="index-dgraph_005fdel_005fvertex_002f3-1"></a>
<a name="index-dgraph_005fdel_005fvertex_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by deleting vertex
<var>Vertex</var> and all the edges that start from or go to <var>Vertex</var> to
the graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_del_vertices(+<var>Graph</var>, +<var>Vertices</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fdel_005fvertices_002f3"></a>
<a name="index-dgraph_005fdel_005fvertices_002f3-1"></a>
<a name="index-dgraph_005fdel_005fvertices_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by deleting the list of
vertices <var>Vertices</var> and all the edges that start from or go to a
vertex in <var>Vertices</var> to the graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_add_edge(+<var>Graph</var>, +<var>N1</var>, +<var>N2</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fadd_005fedge_002f4"></a>
<a name="index-dgraph_005fadd_005fedge_002f4-1"></a>
<a name="index-dgraph_005fadd_005fedge_002f4-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by adding the edge
<var>N1</var>-<var>N2</var> to the graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_add_edges(+<var>Graph</var>, +<var>Edges</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fadd_005fedges_002f3"></a>
<a name="index-dgraph_005fadd_005fedges_002f3-1"></a>
<a name="index-dgraph_005fadd_005fedges_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by adding the list of
edges <var>Edges</var> to the graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_del_edge(+<var>Graph</var>, +<var>N1</var>, +<var>N2</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fdel_005fedge_002f4"></a>
<a name="index-dgraph_005fdel_005fedge_002f4-1"></a>
<a name="index-dgraph_005fdel_005fedge_002f4-2"></a>
<p>Succeeds if <var>NewGraph</var> unifies with a new graph obtained by
removing the edge <var>N1</var>-<var>N2</var> from the graph <var>Graph</var>. Notice
that no vertices are deleted.
</p>
</dd>
<dt><code>dgraph_del_edges(+<var>Graph</var>, +<var>Edges</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fdel_005fedges_002f3"></a>
<a name="index-dgraph_005fdel_005fedges_002f3-1"></a>
<a name="index-dgraph_005fdel_005fedges_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by removing the list of
edges <var>Edges</var> from the graph <var>Graph</var>. Notice that no vertices
are deleted.
</p>
</dd>
<dt><code>dgraph_to_ugraph(+<var>Graph</var>, -<var>UGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fto_005fugraph_002f2"></a>
<a name="index-dgraph_005fto_005fugraph_002f2-1"></a>
<a name="index-dgraph_005fto_005fugraph_002f2-2"></a>
<p>Unify <var>UGraph</var> with the representation used by the <var>ugraphs</var>
unweighted graphs library, that is, a list of the form
<var>V-Neighbors</var>, where <var>V</var> is a node and <var>Neighbors</var> the nodes
children.
</p>
</dd>
<dt><code>ugraph_to_dgraph( +<var>UGraph</var>, -<var>Graph</var>)</code></dt>
<dd><a name="index-ugraph_005fto_005fdgraph_002f2"></a>
<a name="index-ugraph_005fto_005fdgraph_002f2-1"></a>
<a name="index-ugraph_005fto_005fdgraph_002f2-2"></a>
<p>Unify <var>Graph</var> with the directed graph obtain from <var>UGraph</var>,
represented in the form used in the <var>ugraphs</var> unweighted graphs
library.
</p>
</dd>
<dt><code>dgraph_neighbors(+<var>Vertex</var>, +<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-dgraph_005fneighbors_002f3"></a>
<a name="index-dgraph_005fneighbors_002f3-1"></a>
<a name="index-dgraph_005fneighbors_002f3-2"></a>
<p>Unify <var>Vertices</var> with the list of neighbors of vertex <var>Vertex</var>
in <var>Graph</var>. If the vertice is not in the graph fail.
</p>
</dd>
<dt><code>dgraph_neighbours(+<var>Vertex</var>, +<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-dgraph_005fneighbours_002f3"></a>
<a name="index-dgraph_005fneighbours_002f3-1"></a>
<a name="index-dgraph_005fneighbours_002f3-2"></a>
<p>Unify <var>Vertices</var> with the list of neighbours of vertex <var>Vertex</var>
in <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_complement(+<var>Graph</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fcomplement_002f2"></a>
<a name="index-dgraph_005fcomplement_002f2-1"></a>
<a name="index-dgraph_005fcomplement_002f2-2"></a>
<p>Unify <var>NewGraph</var> with the graph complementary to <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_transpose(+<var>Graph</var>, -<var>Transpose</var>)</code></dt>
<dd><a name="index-dgraph_005ftranspose_002f2"></a>
<a name="index-dgraph_005ftranspose_002f2-1"></a>
<a name="index-dgraph_005ftranspose_002f2-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained from <var>Graph</var> by
replacing all edges of the form <var>V1-V2</var> by edges of the form
<var>V2-V1</var>.
</p>
</dd>
<dt><code>dgraph_compose(+<var>Graph1</var>, +<var>Graph2</var>, -<var>ComposedGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fcompose_002f3"></a>
<a name="index-dgraph_005fcompose_002f3-1"></a>
<a name="index-dgraph_005fcompose_002f3-2"></a>
<p>Unify <var>ComposedGraph</var> with a new graph obtained by composing
<var>Graph1</var> and <var>Graph2</var>, ie, <var>ComposedGraph</var> has an edge
<var>V1-V2</var> iff there is a <var>V</var> such that <var>V1-V</var> in <var>Graph1</var>
and <var>V-V2</var> in <var>Graph2</var>.
</p>
</dd>
<dt><code>dgraph_transitive_closure(+<var>Graph</var>, -<var>Closure</var>)</code></dt>
<dd><a name="index-dgraph_005ftransitive_005fclosure_002f2"></a>
<a name="index-dgraph_005ftransitive_005fclosure_002f2-1"></a>
<a name="index-dgraph_005ftransitive_005fclosure_002f2-2"></a>
<p>Unify <var>Closure</var> with the transitive closure of graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_symmetric_closure(+<var>Graph</var>, -<var>Closure</var>)</code></dt>
<dd><a name="index-dgraph_005fsymmetric_005fclosure_002f2"></a>
<a name="index-dgraph_005fsymmetric_005fclosure_002f2-1"></a>
<a name="index-dgraph_005fsymmetric_005fclosure_002f2-2"></a>
<p>Unify <var>Closure</var> with the symmetric closure of graph <var>Graph</var>,
that is, if <var>Closure</var> contains an edge <var>U-V</var> it must also
contain the edge <var>V-U</var>.
</p>
</dd>
<dt><code>dgraph_top_sort(+<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-dgraph_005ftop_005fsort_002f2"></a>
<a name="index-dgraph_005ftop_005fsort_002f2-1"></a>
<a name="index-dgraph_005ftop_005fsort_002f2-2"></a>
<p>Unify <var>Vertices</var> with the topological sort of graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_top_sort(+<var>Graph</var>, -<var>Vertices</var>, ?<var>Vertices0</var>)</code></dt>
<dd><a name="index-dgraph_005ftop_005fsort_002f3"></a>
<a name="index-dgraph_005ftop_005fsort_002f3-1"></a>
<a name="index-dgraph_005ftop_005fsort_002f3-2"></a>
<p>Unify the difference list <var>Vertices</var>-<var>Vertices0</var> with the
topological sort of graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_min_path(+<var>V1</var>, +<var>V1</var>, +<var>Graph</var>, -<var>Path</var>, ?<var>Costt</var>)</code></dt>
<dd><a name="index-dgraph_005fmin_005fpath_002f5"></a>
<a name="index-dgraph_005fmin_005fpath_002f5-1"></a>
<a name="index-dgraph_005fmin_005fpath_002f5-2"></a>
<p>Unify the list <var>Path</var> with the minimal cost path between nodes
<var>N1</var> and <var>N2</var> in graph <var>Graph</var>. Path <var>Path</var> has cost
<var>Cost</var>.
</p>
</dd>
<dt><code>dgraph_max_path(+<var>V1</var>, +<var>V1</var>, +<var>Graph</var>, -<var>Path</var>, ?<var>Costt</var>)</code></dt>
<dd><a name="index-dgraph_005fmax_005fpath_002f5"></a>
<a name="index-dgraph_005fmax_005fpath_002f5-1"></a>
<a name="index-dgraph_005fmax_005fpath_002f5-2"></a>
<p>Unify the list <var>Path</var> with the maximal cost path between nodes
<var>N1</var> and <var>N2</var> in graph <var>Graph</var>. Path <var>Path</var> has cost
<var>Cost</var>.
</p>
</dd>
<dt><code>dgraph_min_paths(+<var>V1</var>, +<var>Graph</var>, -<var>Paths</var>)</code></dt>
<dd><a name="index-dgraph_005fmin_005fpaths_002f3"></a>
<a name="index-dgraph_005fmin_005fpaths_002f3-1"></a>
<a name="index-dgraph_005fmin_005fpaths_002f3-2"></a>
<p>Unify the list <var>Paths</var> with the minimal cost paths from node
<var>N1</var> to the nodes in graph <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_isomorphic(+<var>Vs</var>, +<var>NewVs</var>, +<var>G0</var>, -<var>GF</var>)</code></dt>
<dd><a name="index-dgraph_005fisomorphic_002f4"></a>
<a name="index-dgraph_005fisomorphic_002f4-1"></a>
<a name="index-dgraph_005fisomorphic_002f4-2"></a>
<p>Unify the list <var>GF</var> with the graph isomorphic to <var>G0</var> where
vertices in <var>Vs</var> map to vertices in <var>NewVs</var>.
</p>
</dd>
<dt><code>dgraph_path(+<var>Vertex</var>, +<var>Graph</var>, ?<var>Path</var>)</code></dt>
<dd><a name="index-dgraph_005fpath_002f3"></a>
<a name="index-dgraph_005fpath_002f3-1"></a>
<a name="index-dgraph_005fpath_002f3-2"></a>
<p>The path <var>Path</var> is a path starting at vertex <var>Vertex</var> in graph
<var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_reachable(+<var>Vertex</var>, +<var>Graph</var>, ?<var>Edges</var>)</code></dt>
<dd><a name="index-dgraph_005fpath_002f3-3"></a>
<a name="index-dgraph_005fpath_002f3-4"></a>
<a name="index-dgraph_005fpath_002f3-5"></a>
<p>The path <var>Path</var> is a path starting at vertex <var>Vertex</var> in graph
<var>Graph</var>.
</p>
</dd>
</dl>
<hr>
<a name="UnDGraphs"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#DGraphs" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Lambda" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Undirected-Graphs"></a>
<h2 class="section">7.30 Undirected Graphs</h2>
<a name="index-undirected-graphs"></a>
<p>The following graph manipulation routines use the red-black tree graph
library to implement undirected graphs. Mostly, this is done by having
two directed edges per undirected edge.
</p>
<dl compact="compact">
<dt><code>undgraph_new(+<var>Graph</var>)</code></dt>
<dd><a name="index-undgraph_005fnew_002f1"></a>
<a name="index-undgraph_005fnew_002f1-1"></a>
<a name="index-undgraph_005fnew_002f1-2"></a>
<p>Create a new directed graph. This operation must be performed before
trying to use the graph.
</p>
</dd>
<dt><code>undgraph_vertices(+<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-undgraph_005fvertices_002f2"></a>
<a name="index-undgraph_005fvertices_002f2-1"></a>
<a name="index-undgraph_005fvertices_002f2-2"></a>
<p>Unify <var>Vertices</var> with all vertices appearing in graph
<var>Graph</var>.
</p>
</dd>
<dt><code>undgraph_edge(+<var>N1</var>, +<var>N2</var>, +<var>Graph</var>)</code></dt>
<dd><a name="index-undgraph_005fedge_002f2"></a>
<a name="index-undgraph_005fedge_002f2-1"></a>
<a name="index-undgraph_005fedge_002f2-2"></a>
<p>Edge <var>N1</var>-<var>N2</var> is an edge in undirected graph <var>Graph</var>.
</p>
</dd>
<dt><code>undgraph_edges(+<var>Graph</var>, -<var>Edges</var>)</code></dt>
<dd><a name="index-undgraph_005fedges_002f2"></a>
<a name="index-undgraph_005fedges_002f2-1"></a>
<a name="index-undgraph_005fedges_002f2-2"></a>
<p>Unify <var>Edges</var> with all edges appearing in graph
<var>Graph</var>.
</p>
</dd>
<dt><code>undgraph_add_vertices(+<var>Graph</var>, +<var>Vertices</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-undgraph_005fadd_005fvertices_002f3"></a>
<a name="index-undgraph_005fadd_005fvertices_002f3-1"></a>
<a name="index-undgraph_005fadd_005fvertices_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by adding the list of
vertices <var>Vertices</var> to the graph <var>Graph</var>.
</p>
</dd>
<dt><code>undgraph_del_vertices(+<var>Graph</var>, +<var>Vertices</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-undgraph_005fdel_005fvertices_002f3"></a>
<a name="index-undgraph_005fdel_005fvertices_002f3-1"></a>
<a name="index-undgraph_005fdel_005fvertices_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by deleting the list of
vertices <var>Vertices</var> and all the edges that start from or go to a
vertex in <var>Vertices</var> to the graph <var>Graph</var>.
</p>
</dd>
<dt><code>undgraph_add_edges(+<var>Graph</var>, +<var>Edges</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-undgraph_005fadd_005fedges_002f3"></a>
<a name="index-undgraph_005fadd_005fedges_002f3-1"></a>
<a name="index-undgraph_005fadd_005fedges_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by adding the list of
edges <var>Edges</var> to the graph <var>Graph</var>.
</p>
</dd>
<dt><code>undgraph_del_edges(+<var>Graph</var>, +<var>Edges</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-undgraph_005fdel_005fedges_002f3"></a>
<a name="index-undgraph_005fdel_005fedges_002f3-1"></a>
<a name="index-undgraph_005fdel_005fedges_002f3-2"></a>
<p>Unify <var>NewGraph</var> with a new graph obtained by removing the list of
edges <var>Edges</var> from the graph <var>Graph</var>. Notice that no vertices
are deleted.
</p>
</dd>
<dt><code>undgraph_neighbors(+<var>Vertex</var>, +<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-undgraph_005fneighbors_002f3"></a>
<a name="index-undgraph_005fneighbors_002f3-1"></a>
<a name="index-undgraph_005fneighbors_002f3-2"></a>
<p>Unify <var>Vertices</var> with the list of neighbors of vertex <var>Vertex</var>
in <var>Graph</var>. If the vertice is not in the graph fail.
</p>
</dd>
<dt><code>undgraph_neighbours(+<var>Vertex</var>, +<var>Graph</var>, -<var>Vertices</var>)</code></dt>
<dd><a name="index-undgraph_005fneighbours_002f3"></a>
<a name="index-undgraph_005fneighbours_002f3-1"></a>
<a name="index-undgraph_005fneighbours_002f3-2"></a>
<p>Unify <var>Vertices</var> with the list of neighbours of vertex <var>Vertex</var>
in <var>Graph</var>.
</p>
</dd>
<dt><code>undgraph_complement(+<var>Graph</var>, -<var>NewGraph</var>)</code></dt>
<dd><a name="index-undgraph_005fcomplement_002f2"></a>
<a name="index-undgraph_005fcomplement_002f2-1"></a>
<a name="index-undgraph_005fcomplement_002f2-2"></a>
<p>Unify <var>NewGraph</var> with the graph complementary to <var>Graph</var>.
</p>
</dd>
<dt><code>dgraph_to_undgraph( +<var>DGraph</var>, -<var>UndGraph</var>)</code></dt>
<dd><a name="index-dgraph_005fto_005fundgraph_002f2"></a>
<a name="index-dgraph_005fto_005fundgraph_002f2-1"></a>
<a name="index-dgraph_005fto_005fundgraph_002f2-2"></a>
<p>Unify <var>UndGraph</var> with the undirected graph obtained from the
directed graph <var>DGraph</var>.
</p>
</dd>
</dl>
<hr>
<a name="Lambda"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#UnDGraphs" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#LAM" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Lambda-Expressions"></a>
<h2 class="section">7.31 Lambda Expressions</h2>
<a name="index-Lambda-Expressions"></a>
<p>This library, designed and implemented by Ulrich Neumerkel, provides
lambda expressions to simplify higher order programming based on <code>call/N</code>.
</p>
<p>Lambda expressions are represented by ordinary Prolog terms. There are
two kinds of lambda expressions:
</p>
<div class="example">
<pre class="example"> Free+\X1^X2^ ..^XN^Goal
\X1^X2^ ..^XN^Goal
</pre></div>
<p>The second is a shorthand for<code> t+\X1^X2^..^XN^Goal</code>, where <code>Xi</code> are the parameters.
</p>
<p><var>Goal</var> is a goal or continuation (Syntax note: <var>Operators</var> within <var>Goal</var>
require parentheses due to the low precedence of the <code>^</code> operator).
</p>
<p>Free contains variables that are valid outside the scope of the lambda
expression. They are thus free variables within.
</p>
<p>All other variables of <var>Goal</var> are considered local variables. They must
not appear outside the lambda expression. This restriction is
currently not checked. Violations may lead to unexpected bindings.
</p>
<p>In the following example the parentheses around <code>X&gt;3</code> are necessary.
</p>
<div class="example">
<pre class="example">?- use_module(library(lambda)).
?- use_module(library(apply)).
?- maplist(\X^(X&gt;3),[4,5,9]).
true.
</pre></div>
<p>In the following <var>X</var> is a variable that is shared by both instances
of the lambda expression. The second query illustrates the cooperation
of continuations and lambdas. The lambda expression is in this case a
continuation expecting a further argument.
</p>
<div class="example">
<pre class="example">?- Xs = [A,B], maplist(X+\Y^dif(X,Y), Xs).
Xs = [A, B],
dif(X, A),
dif(X, B).
?- Xs = [A,B], maplist(X+\dif(X), Xs).
Xs = [A, B],
dif(X, A),
dif(X, B).
</pre></div>
<p>The following queries are all equivalent. To see this, use
the fact <code>f(x,y)</code>.
</p>
<div class="example">
<pre class="example">?- call(f,A1,A2).
?- call(\X^f(X),A1,A2).
?- call(\X^Y^f(X,Y), A1,A2).
?- call(\X^(X+\Y^f(X,Y)), A1,A2).
?- call(call(f, A1),A2).
?- call(f(A1),A2).
?- f(A1,A2).
A1 = x,
A2 = y.
</pre></div>
<p>Further discussions
at <a href="http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/ISO-Hiord">http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/ISO-Hiord</a>.
</p>
<hr>
<a name="LAM"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Lambda" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Library" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="LAM-1"></a>
<h2 class="section">7.32 LAM</h2>
<a name="index-lam"></a>
<p>This library provides a set of utilities for interfacing with LAM MPI.
The following routines are available once included with the
<code>use_module(library(lam_mpi))</code> command. The yap should be
invoked using the LAM mpiexec or mpirun commands (see LAM manual for
more details).
</p>
<dl compact="compact">
<dt><code>mpi_init</code></dt>
<dd><a name="index-mpi_005finit_002f0"></a>
<a name="index-mpi_005finit_002f0-1"></a>
<a name="index-mpi_005finit_002f0-2"></a>
<p> Sets up the mpi environment. This predicate should be called before any other MPI predicate.
</p>
</dd>
<dt><code>mpi_finalize</code></dt>
<dd><a name="index-mpi_005ffinalize_002f0"></a>
<a name="index-mpi_005ffinalize_002f0-1"></a>
<a name="index-mpi_005ffinalize_002f0-2"></a>
<p> Terminates the MPI execution environment. Every process must call this predicate before exiting.
</p>
</dd>
<dt><code>mpi_comm_size(-<var>Size</var>)</code></dt>
<dd><a name="index-mpi_005fcomm_005fsize_002f1"></a>
<a name="index-mpi_005fcomm_005fsize_002f1-1"></a>
<a name="index-mpi_005fcomm_005fsize_002f1-2"></a>
<p> Unifies <var>Size</var> with the number of processes in the MPI environment.
</p>
</dd>
<dt><code>mpi_comm_rank(-<var>Rank</var>)</code></dt>
<dd><a name="index-mpi_005fcomm_005frank_002f1"></a>
<a name="index-mpi_005fcomm_005frank_002f1-1"></a>
<a name="index-mpi_005fcomm_005frank_002f1-2"></a>
<p> Unifies <var>Rank</var> with the rank of the current process in the MPI environment.
</p>
</dd>
<dt><code>mpi_version(-<var>Major</var>,-<var>Minor</var>)</code></dt>
<dd><a name="index-mpi_005fversion_002f2"></a>
<a name="index-mpi_005fversion_002f2-1"></a>
<a name="index-mpi_005fversion_002f2-2"></a>
<p> Unifies <var>Major</var> and <var>Minor</var> with, respectively, the major and minor version of the MPI.
</p>
</dd>
<dt><code>mpi_send(+<var>Data</var>,+<var>Dest</var>,+<var>Tag</var>)</code></dt>
<dd><a name="index-mpi_005fsend_002f3"></a>
<a name="index-mpi_005fsend_002f3-1"></a>
<a name="index-mpi_005fsend_002f3-2"></a>
<p>Blocking communication predicate. The message in <var>Data</var>, with tag
<var>Tag</var>, is sent immediately to the processor with rank <var>Dest</var>.
The predicate succeeds after the message being sent.
</p>
</dd>
<dt><code>mpi_isend(+<var>Data</var>,+<var>Dest</var>,+<var>Tag</var>,-<var>Handle</var>)</code></dt>
<dd><a name="index-mpi_005fisend_002f4"></a>
<a name="index-mpi_005fisend_002f4-1"></a>
<a name="index-mpi_005fisend_002f4-2"></a>
<p>Non blocking communication predicate. The message in <var>Data</var>, with
tag <var>Tag</var>, is sent whenever possible to the processor with rank
<var>Dest</var>. An <var>Handle</var> to the message is returned to be used to
check for the status of the message, using the <code>mpi_wait</code> or
<code>mpi_test</code> predicates. Until <code>mpi_wait</code> is called, the
memory allocated for the buffer containing the message is not
released.
</p>
</dd>
<dt><code>mpi_recv(?<var>Source</var>,?<var>Tag</var>,-<var>Data</var>)</code></dt>
<dd><a name="index-mpi_005frecv_002f3"></a>
<a name="index-mpi_005frecv_002f3-1"></a>
<a name="index-mpi_005frecv_002f3-2"></a>
<p>Blocking communication predicate. The predicate blocks until a message
is received from processor with rank <var>Source</var> and tag <var>Tag</var>.
The message is placed in <var>Data</var>.
</p>
</dd>
<dt><code>mpi_irecv(?<var>Source</var>,?<var>Tag</var>,-<var>Handle</var>)</code></dt>
<dd><a name="index-mpi_005firecv_002f3"></a>
<a name="index-mpi_005firecv_002f3-1"></a>
<a name="index-mpi_005firecv_002f3-2"></a>
<p>Non-blocking communication predicate. The predicate returns an
<var>Handle</var> for a message that will be received from processor with
rank <var>Source</var> and tag <var>Tag</var>. Note that the predicate succeeds
immediately, even if no message has been received. The predicate
<code>mpi_wait_recv</code> should be used to obtain the data associated to
the handle.
</p>
</dd>
<dt><code>mpi_wait_recv(?<var>Handle</var>,-<var>Status</var>,-<var>Data</var>)</code></dt>
<dd><a name="index-mpi_005fwait_005frecv_002f3"></a>
<a name="index-mpi_005fwait_005frecv_002f3-1"></a>
<a name="index-mpi_005fwait_005frecv_002f3-2"></a>
<p>Completes a non-blocking receive operation. The predicate blocks until
a message associated with handle <var>Hanlde</var> is buffered. The
predicate succeeds unifying <var>Status</var> with the status of the
message and <var>Data</var> with the message itself.
</p>
</dd>
<dt><code>mpi_test_recv(?<var>Handle</var>,-<var>Status</var>,-<var>Data</var>)</code></dt>
<dd><a name="index-mpi_005ftest_005frecv_002f3"></a>
<a name="index-mpi_005ftest_005frecv_002f3-1"></a>
<a name="index-mpi_005ftest_005frecv_002f3-2"></a>
<p>Provides information regarding a handle. If the message associated
with handle <var>Hanlde</var> is buffered then the predicate succeeds
unifying <var>Status</var> with the status of the message and <var>Data</var>
with the message itself. Otherwise, the predicate fails.
</p>
</dd>
<dt><code>mpi_wait(?<var>Handle</var>,-<var>Status</var>)</code></dt>
<dd><a name="index-mpi_005fwait_002f2"></a>
<a name="index-mpi_005fwait_002f2-1"></a>
<a name="index-mpi_005fwait_002f2-2"></a>
<p>Completes a non-blocking operation. If the operation was a
<code>mpi_send</code>, the predicate blocks until the message is buffered
or sent by the runtime system. At this point the send buffer is
released. If the operation was a <code>mpi_recv</code>, it waits until the
message is copied to the receive buffer. <var>Status</var> is unified with
the status of the message.
</p>
</dd>
<dt><code>mpi_test(?<var>Handle</var>,-<var>Status</var>)</code></dt>
<dd><a name="index-mpi_005ftest_002f2"></a>
<a name="index-mpi_005ftest_002f2-1"></a>
<a name="index-mpi_005ftest_002f2-2"></a>
<p>Provides information regarding the handle <var>Handle</var>, ie., if a
communication operation has been completed. If the operation
associate with <var>Hanlde</var> has been completed the predicate succeeds
with the completion status in <var>Status</var>, otherwise it fails.
</p>
</dd>
<dt><code>mpi_barrier</code></dt>
<dd><a name="index-mpi_005fbarrier_002f0"></a>
<a name="index-mpi_005fbarrier_002f0-1"></a>
<a name="index-mpi_005fbarrier_002f0-2"></a>
<p>Collective communication predicate. Performs a barrier
synchronization among all processes. Note that a collective
communication means that all processes call the same predicate. To be
able to use a regular <code>mpi_recv</code> to receive the messages, one
should use <code>mpi_bcast2</code>.
</p>
</dd>
<dt><code>mpi_bcast2(+<var>Root</var>, +<var>Data</var>)</code></dt>
<dd><a name="index-mpi_005fbcast_002f2"></a>
<a name="index-mpi_005fbcast_002f2-1"></a>
<a name="index-mpi_005fbcast_002f2-2"></a>
<p>Broadcasts the message <var>Data</var> from the process with rank <var>Root</var>
to all other processes.
</p>
</dd>
<dt><code>mpi_bcast3(+<var>Root</var>, +<var>Data</var>, +<var>Tag</var>)</code></dt>
<dd><a name="index-mpi_005fbcast_002f3"></a>
<a name="index-mpi_005fbcast_002f3-1"></a>
<a name="index-mpi_005fbcast_002f3-2"></a>
<p>Broadcasts the message <var>Data</var> with tag <var>Tag</var> from the process with rank <var>Root</var>
to all other processes.
</p>
</dd>
<dt><code>mpi_ibcast(+<var>Root</var>, +<var>Data</var>, +<var>Tag</var>)</code></dt>
<dd><a name="index-mpi_005fbcast_002f3-3"></a>
<a name="index-mpi_005fbcast_002f3-4"></a>
<a name="index-mpi_005fbcast_002f3-5"></a>
<p>Non-blocking operation. Broadcasts the message <var>Data</var> with tag <var>Tag</var>
from the process with rank <var>Root</var> to all other processes.
</p>
</dd>
<dt><code>mpi_gc</code></dt>
<dd><a name="index-mpi_005fgc_002f0"></a>
<a name="index-mpi_005fgc_002f0-1"></a>
<a name="index-mpi_005fgc_002f0-2"></a>
<p>Attempts to perform garbage collection with all the open handles
associated with send and non-blocking broadcasts. For each handle it
tests it and the message has been delivered the handle and the buffer
are released.
</p>
</dd>
</dl>
<hr>
<a name="SWI_002dProlog"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Library" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#LAM" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Invoking-Predicates-on-all-Members-of-a-List" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog-Global-Variables" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="index-SWI_002dProlog"></a>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">SWI-Prolog Emulation
Subnodes of SWI-Prolog
</pre></th></tr><tr><td align="left" valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> maplist and friends
</td></tr>
<tr><td align="left" valign="top"><a href="#Forall">8.2 Forall</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> forall built-in
</td></tr>
</table>
<a name="SWI_002dProlog-Emulation"></a>
<h1 class="chapter">8 SWI-Prolog Emulation</h1>
<p>This library provides a number of SWI-Prolog builtins that are not by
default in YAP. This support is loaded with the
<code>expects_dialect(swi)</code> command.
</p>
<dl compact="compact">
<dt><code>append(?<var>List1</var>,?<var>List2</var>,?<var>List3</var>)</code></dt>
<dd><a name="index-append_002f3-3"></a>
<a name="index-append_002f3-4"></a>
<a name="index-append_002f3-5"></a>
<p>Succeeds when <var>List3</var> unifies with the concatenation of <var>List1</var>
and <var>List2</var>. The predicate can be used with any instantiation
pattern (even three variables).
</p>
</dd>
<dt><code>between(+<var>Low</var>,+<var>High</var>,?<var>Value</var>)</code></dt>
<dd><a name="index-between_002f3-3"></a>
<a name="index-between_002f3-4"></a>
<a name="index-between_002f3-5"></a>
<p><var>Low</var> and <var>High</var> are integers, <var>High</var> less or equal than
<var>Low</var>. If <var>Value</var> is an integer, <var>Low</var> less or equal than
<var>Value</var> less or equal than <var>High</var>. When <var>Value</var> is a
variable it is successively bound to all integers between <var>Low</var> and
<var>High</var>. If <var>High</var> is <code>inf</code>, <code>between/3</code> is true iff
<var>Value</var> less or equal than <var>Low</var>, a feature that is particularly
interesting for generating integers from a certain value.
</p>
</dd>
<dt><code>chdir(+<var>Dir</var>)</code></dt>
<dd><a name="index-chdir_002f1"></a>
<a name="index-chdir_002f1-1"></a>
<a name="index-chdir_002f1-2"></a>
<p>Compatibility predicate. New code should use <code>working_directory/2</code>.
</p>
</dd>
<dt><code>concat_atom(+<var>List</var>,-<var>Atom</var>)</code></dt>
<dd><a name="index-concat_005fatom_002f2"></a>
<a name="index-concat_005fatom_002f2-1"></a>
<a name="index-concat_005fatom_002f2-2"></a>
<p><var>List</var> is a list of atoms, integers or floating point numbers. Succeeds
if <var>Atom</var> can be unified with the concatenated elements of <var>List</var>. If
<var>List</var> has exactly 2 elements it is equivalent to <code>atom_concat/3</code>,
allowing for variables in the list.
</p>
</dd>
<dt><code>concat_atom(?<var>List</var>,+<var>Separator</var>,?<var>Atom</var>)</code></dt>
<dd><a name="index-concat_005fatom_002f3"></a>
<a name="index-concat_005fatom_002f3-1"></a>
<a name="index-concat_005fatom_002f3-2"></a>
<p>Creates an atom just like concat_atom/2, but inserts <var>Separator</var>
between each pair of atoms. For example:
\</p><div class="example">
<pre class="example">?- concat_atom([gnu, gnat], ', ', A).
A = 'gnu, gnat'
</pre></div>
<p>(Unimplemented) This predicate can also be used to split atoms by
instantiating <var>Separator</var> and <var>Atom</var>:
</p>
<div class="example">
<pre class="example">?- concat_atom(L, -, 'gnu-gnat').
L = [gnu, gnat]
</pre></div>
</dd>
<dt><code>nth1(+<var>Index</var>,?<var>List</var>,?<var>Elem</var>)</code></dt>
<dd><a name="index-nth1_002f3-3"></a>
<a name="index-nth1_002f3-4"></a>
<a name="index-nth1_002f3-5"></a>
<p>Succeeds when the <var>Index</var>-th element of <var>List</var> unifies with
<var>Elem</var>. Counting starts at 1.
</p>
<p>Set environment variable. <var>Name</var> and <var>Value</var> should be
instantiated to atoms or integers. The environment variable will be
passed to <code>shell/[0-2]</code> and can be requested using <code>getenv/2</code>.
They also influence <code>expand_file_name/2</code>.
</p>
</dd>
<dt><code>setenv(+<var>Name</var>,+<var>Value</var>)</code></dt>
<dd><a name="index-setenv_002f2"></a>
<a name="index-setenv_002f2-1"></a>
<a name="index-setenv_002f2-2"></a>
<p>Set environment variable. <var>Name</var> and <var>Value</var> should be
instantiated to atoms or integers. The environment variable will be
passed to <code>shell/[0-2]</code> and can be requested using <code>getenv/2</code>.
They also influence <code>expand_file_name/2</code>.
</p>
</dd>
<dt><code>term_to_atom(?<var>Term</var>,?<var>Atom</var>)</code></dt>
<dd><a name="index-term_005fto_005fatom_002f2-3"></a>
<a name="index-term_005fto_005fatom_002f2-4"></a>
<a name="index-term_005fto_005fatom_002f2-5"></a>
<p>Succeeds if <var>Atom</var> describes a term that unifies with <var>Term</var>. When
<var>Atom</var> is instantiated <var>Atom</var> is converted and then unified with
<var>Term</var>. If <var>Atom</var> has no valid syntax, a <code>syntax_error</code>
exception is raised. Otherwise <var>Term</var> is &ldquo;written&rdquo; on <var>Atom</var>
using <code>write/1</code>.
</p>
</dd>
<dt><code>working_directory(-<var>Old</var>,+<var>New</var>)</code></dt>
<dd><a name="index-working_005fdirectory_002f2-3"></a>
<a name="index-working_005fdirectory_002f2-4"></a>
<a name="index-working_005fdirectory_002f2-5"></a>
<p>Unify <var>Old</var> with an absolute path to the current working directory
and change working directory to <var>New</var>. Use the pattern
<code>working_directory(CWD, CWD)</code> to get the current directory. See
also <code>absolute_file_name/2</code> and <code>chdir/1</code>.
</p>
</dd>
<dt><code>@<var>Term1</var> =@= @<var>Term2</var></code></dt>
<dd><a name="index-_003d_0040_003d_002f2"></a>
<a name="index-_003d_0040_003d_002f2-1"></a>
<a name="index-_003d_0040_003d_002f2-2"></a>
<p>True iff <var>Term1</var> and <var>Term2</var> are structurally equivalent. I.e. if <var>Term1</var> and <var>Term2</var> are variants of each other.
</p>
</dd>
</dl>
<hr>
<a name="Invoking-Predicates-on-all-Members-of-a-List"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Forall" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog-Global-Variables" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Invoking-Predicates-on-all-Members-of-a-List-1"></a>
<h2 class="section">8.1 Invoking Predicates on all Members of a List</h2>
<p>All the predicates in this section call a predicate on all members of a
list or until the predicate called fails. The predicate is called via
<code>call/[2..]</code>, which implies common arguments can be put in
front of the arguments obtained from the list(s). For example:
</p>
<div class="example">
<pre class="example">?- maplist(plus(1), [0, 1, 2], X).
X = [1, 2, 3]
</pre></div>
<p>we will phrase this as &ldquo;<var>Predicate</var> is applied on ...&rdquo;
</p>
<dl compact="compact">
<dt><code>maplist(+<var>Pred</var>,+<var>List</var>)</code></dt>
<dd><a name="index-maplist_002f2"></a>
<a name="index-maplist_002f2-1"></a>
<a name="index-maplist_002f2-2"></a>
<p><var>Pred</var> is applied successively on each element of <var>List</var> until
the end of the list or <var>Pred</var> fails. In the latter case
<code>maplist/2</code> fails.
</p>
</dd>
<dt><code>maplist(+<var>Pred</var>,+<var>List1</var>,+<var>List2</var>)</code></dt>
<dd><a name="index-maplist_002f3-6"></a>
<a name="index-maplist_002f3-7"></a>
<a name="index-maplist_002f3-8"></a>
<p>Apply <var>Pred</var> on all successive pairs of elements from
<var>List1</var> and
<var>List2</var>. Fails if <var>Pred</var> can not be applied to a
pair. See the example above.
</p>
</dd>
<dt><code>maplist(+<var>Pred</var>,+<var>List1</var>,+<var>List2</var>,+<var>List4</var>)</code></dt>
<dd><a name="index-maplist_002f4-3"></a>
<a name="index-maplist_002f4-4"></a>
<a name="index-maplist_002f4-5"></a>
<p>Apply <var>Pred</var> on all successive triples of elements from <var>List1</var>,
<var>List2</var> and <var>List3</var>. Fails if <var>Pred</var> can not be applied to a
triple. See the example above.
</p>
</dd>
</dl>
<hr>
<a name="Forall"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Invoking-Predicates-on-all-Members-of-a-List" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog-Global-Variables" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog-Global-Variables" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Forall-1"></a>
<h2 class="section">8.2 Forall</h2>
<dl compact="compact">
<dt><code>forall(+<var>Cond</var>,+<var>Action</var>)</code></dt>
<dd><a name="index-forall_002f2-3"></a>
<a name="index-forall_002f2-4"></a>
<a name="index-forall_002f2-5"></a>
<p>For all alternative bindings of <var>Cond</var> <var>Action</var> can be proven.
The next example verifies that all arithmetic statements in the list
<var>L</var> are correct. It does not say which is wrong if one proves wrong.
</p>
<div class="example">
<pre class="example">?- forall(member(Result = Formula, [2 = 1 + 1, 4 = 2 * 2]),
Result =:= Formula).
</pre></div>
</dd>
</dl>
<hr>
<a name="SWI_002dProlog-Global-Variables"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SWI_002dProlog" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Forall" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility-of-Global-Variables" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Extensions" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="SWI-Global-variables"></a>
<h1 class="chapter">9 SWI Global variables</h1>
<p>SWI-Prolog global variables are associations between names (atoms) and
terms. They differ in various ways from storing information using
<code>assert/1</code> or <code>recorda/3</code>.
</p>
<ul>
<li> The value lives on the Prolog (global) stack. This implies
that lookup time is independent 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.
</li><li> They support both global assignment using <code>nb_setval/2</code> and
backtrackable assignment using <code>b_setval/2</code>.
</li><li> Only one value (which can be an arbitrary complex Prolog
term) can be associated to a variable at a time.
</li><li> Their value cannot be shared among threads. Each thread
has its own namespace and values for global variables.
</li><li> Currently global variables are scoped globally. We may
consider module scoping in future versions.
</li></ul>
<p>Both <code>b_setval/2</code> and <code>nb_setval/2</code> implicitly create a variable if the
referenced name does not already refer to a variable.
</p>
<p>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 <code>initialization/1</code>
to recreate them after loading the saved state. Each thread has
its own set of global variables, starting with an empty set. Using
<code>thread_inititialization/1</code> to define a global variable it will be
defined, restored after reloading a saved state and created in all
threads that are created <em>after</em> the registration.
</p>
<dl compact="compact">
<dt><code>b_setval(+<var>Name</var>,+<var>Value</var>)</code></dt>
<dd><a name="index-b_005fsetval_002f2-3"></a>
<a name="index-b_005fsetval_002f2-4"></a>
<a name="index-b_005fsetval_002f2-5"></a>
<p>Associate the term <var>Value</var> with the atom <var>Name</var> or replaces
the currently associated value with <var>Value</var>. If <var>Name</var> does
not refer to an existing global variable a variable with initial value
<code>[]</code> is created (the empty list). On backtracking the
assignment is reversed.
</p>
</dd>
<dt><code>b_getval(+<var>Name</var>,-<var>Value</var>)</code></dt>
<dd><a name="index-b_005fgetval_002f2-3"></a>
<a name="index-b_005fgetval_002f2-4"></a>
<a name="index-b_005fgetval_002f2-5"></a>
<p>Get the value associated with the global variable <var>Name</var> and unify
it with <var>Value</var>. Note that this unification may further instantiate
the value of the global variable. If this is undesirable the normal
precautions (double negation or <code>copy_term/2</code>) must be taken. The
<code>b_getval/2</code> predicate generates errors if <var>Name</var> is not an atom or
the requested variable does not exist.
</p></dd>
</dl>
<dl compact="compact">
<dt><code>nb_setval(+<var>Name</var>,+<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fsetval_002f2-3"></a>
<a name="index-nb_005fsetval_002f2-4"></a>
<a name="index-nb_005fsetval_002f2-5"></a>
<p>Associates a copy of <var>Value</var> created with <code>duplicate_term/2</code>
with the atom <var>Name</var>. Note that this can be used to set an
initial value other than <code>[]</code> prior to backtrackable assignment.
</p>
</dd>
<dt><code>nb_getval(+<var>Name</var>,-<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fgetval_002f2-3"></a>
<a name="index-nb_005fgetval_002f2-4"></a>
<a name="index-nb_005fgetval_002f2-5"></a>
<p>The <code>nb_getval/2</code> predicate is a synonym for b_getval/2, introduced for
compatibility and symmetry. As most scenarios will use a particular
global variable either using non-backtrackable or backtrackable
assignment, using <code>nb_getval/2</code> can be used to document that the
variable is used non-backtrackable.
</p>
</dd>
<dt><code>nb_current(?<var>Name</var>,?<var>Value</var>)</code></dt>
<dd><a name="index-nb_005fcurrent_002f2-3"></a>
<a name="index-nb_005fcurrent_002f2-4"></a>
<a name="index-nb_005fcurrent_002f2-5"></a>
<p>Enumerate all defined variables with their value. The order of
enumeration is undefined.
</p>
</dd>
<dt><code>nb_delete(?<var>Name</var>)</code></dt>
<dd><a name="index-nb_005fdelete_002f1"></a>
<a name="index-nb_005fdelete_002f1-1"></a>
<a name="index-nb_005fdelete_002f1-2"></a>
<p>Delete the named global variable.
</p></dd>
</dl>
<hr>
<a name="Compatibility-of-Global-Variables"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SWI_002dProlog-Global-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog-Global-Variables" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SWI_002dProlog-Global-Variables" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Extensions" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Extensions" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">9.1 Compatibility of Global Variables</h2>
<p>Global variables have been introduced by various Prolog
implementations recently. YAP follows their implementation in SWI-Prolog, itself
based on hProlog by Bart Demoen. Jan and Bart
decided that the semantics if hProlog <code>nb_setval/2</code>, which is
equivalent to <code>nb_linkval/2</code> is not acceptable for normal Prolog
users as the behaviour is influenced by how builtin predicates
constructing terms (<code>read/1</code>, <code>=../2</code>, etc.) are implemented.
</p>
<p>GNU-Prolog provides a rich set of global variables, including arrays.
Arrays can be implemented easily in SWI-Prolog using <code>functor/3</code> and
<code>setarg/3</code> due to the unrestricted arity of compound terms.
</p>
<hr>
<a name="Extensions"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SWI_002dProlog-Global-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility-of-Global-Variables" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Rational-Trees" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Attributed-Variables" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Extensions-to-Prolog"></a>
<h1 class="chapter">10 Extensions to Prolog</h1>
<p>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 <code>Makefile</code>
</p>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">Extensions to Traditional Prolog
</pre></th></tr><tr><td align="left" valign="top"><a href="#Rational-Trees">10.1 Rational Trees</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Working with Rational Trees
</td></tr>
<tr><td align="left" valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Changing the Execution of Goals
</td></tr>
<tr><td align="left" valign="top"><a href="#Attributed-Variables">11 Attributed Variables</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Using attributed Variables
</td></tr>
<tr><td align="left" valign="top"><a href="#CLPR">12 Constraint Logic Programming over Reals</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The CLP(R) System
</td></tr>
<tr><td align="left" valign="top"><a href="#Logtalk">14 Logtalk</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The Logtalk Object-Oriented system
</td></tr>
<tr><td align="left" valign="top"><a href="#MYDDAS">15 MYDDAS</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> The MYDDAS Database Interface package
</td></tr>
<tr><td align="left" valign="top"><a href="#Threads">16 Threads</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Thread Library
</td></tr>
<tr><td align="left" valign="top"><a href="#Parallelism">17 Parallelism</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Running in Or-Parallel
</td></tr>
<tr><td align="left" valign="top"><a href="#Tabling">18 Tabling</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Storing Intermediate Solutions of programs
</td></tr>
<tr><td align="left" valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Profiling Abstract Machine Instructions
</td></tr>
<tr><td align="left" valign="top"><a href="#Low-Level-Tracing">19 Tracing at Low Level</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Tracing at Abstract Machine Level
</td></tr>
</table>
<hr>
<a name="Rational-Trees"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Extensions" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Extensions" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Extensions" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Co_002droutining" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Attributed-Variables" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Rational-Trees-1"></a>
<h2 class="section">10.1 Rational Trees</h2>
<p>Prolog unification is not a complete implementation. For efficiency
considerations, Prolog systems do not perform occur checks while
unifying terms. As an example, <code>X = a(X)</code> will not fail but instead
will create an infinite term of the form <code>a(a(a(a(a(...)))))</code>, or
<em>rational tree</em>.
</p>
<p>Rational trees are now supported by default in YAP. In previous
versions, this was not the default and these terms could easily lead
to infinite computation. For example, <code>X = a(X), X = X</code> would
enter an infinite loop.
</p>
<p>The <code>RATIONAL_TREES</code> flag improves support for these
terms. Internal primitives are now aware that these terms can exist, and
will not enter infinite loops. Hence, the previous unification will
succeed. Another example, <code>X = a(X), ground(X)</code> will succeed
instead of looping. Other affected built-ins include the term comparison
primitives, <code>numbervars/3</code>, <code>copy_term/2</code>, and the internal
data base routines. The support does not extend to Input/Output routines
or to <code>assert/1</code> YAP does not allow directly reading
rational trees, and you need to use <code>write_depth/2</code> to avoid
entering an infinite cycle when trying to write an infinite term.
</p>
<hr>
<a name="Co_002droutining"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Extensions" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Rational-Trees" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Extensions" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Attributed-Variables" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Attributed-Variables" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Co_002droutining-1"></a>
<h2 class="section">10.2 Co-routining</h2>
<p>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 &quot;data-driven&quot;
execution, or may be necessary to correctly implement extensions such as
negation by default.
</p>
<p>The <code>COROUTINING</code> flag enables this option. Note that the support for
coroutining will in general slow down execution.
</p>
<p>The following declaration is supported:
</p>
<dl compact="compact">
<dt><code>block/1</code></dt>
<dd><p>The argument to <code>block/1</code> is a condition on a goal or a conjunction
of conditions, with each element separated by commas. Each condition is
of the form <code>predname(<var>C1</var>,...,<var>CN</var>)</code>, where <var>N</var> is the
arity of the goal, and each <var>CI</var> is of the form <code>-</code>, if the
argument must suspend until the first such variable is bound, or
<code>?</code>, otherwise.
</p>
</dd>
<dt><code>wait/1</code></dt>
<dd><p>The argument to <code>wait/1</code> is a predicate descriptor or a conjunction
of these predicates. These predicates will suspend until their first
argument is bound.
</p></dd>
</dl>
<p>The following primitives are supported:
</p>
<dl compact="compact">
<dt><code>dif(<var>X</var>,<var>Y</var>)</code></dt>
<dd><a name="index-dif_002f2"></a>
<a name="index-dif_002f2-1"></a>
<a name="index-dif_002f2-2"></a>
<p>Succeed if the two arguments do not unify. A call to <code>dif/2</code> will
suspend if unification may still succeed or fail, and will fail if they
always unify.
</p>
</dd>
<dt><code>freeze(?<var>X</var>,:<var>G</var>)</code></dt>
<dd><a name="index-freeze_002f2"></a>
<a name="index-freeze_002f2-1"></a>
<a name="index-freeze_002f2-2"></a>
<p>Delay execution of goal <var>G</var> until the variable <var>X</var> is bound.
</p>
</dd>
<dt><code>frozen(<var>X</var>,<var>G</var>)</code></dt>
<dd><a name="index-frozen_002f2"></a>
<a name="index-frozen_002f2-1"></a>
<a name="index-frozen_002f2-2"></a>
<p>Unify <var>G</var> with a conjunction of goals suspended on variable <var>X</var>,
or <code>true</code> if no goal has suspended.
</p>
</dd>
<dt><code>when(+<var>C</var>,:<var>G</var>)</code></dt>
<dd><a name="index-when_002f2"></a>
<a name="index-when_002f2-1"></a>
<a name="index-when_002f2-2"></a>
<p>Delay execution of goal <var>G</var> until the conditions <var>C</var> are
satisfied. The conditions are of the following form:
</p>
<dl compact="compact">
<dt><code><var>C1</var>,<var>C2</var></code></dt>
<dd><p>Delay until both conditions <var>C1</var> and <var>C2</var> are satisfied.
</p></dd>
<dt><code><var>C1</var>;<var>C2</var></code></dt>
<dd><p>Delay until either condition <var>C1</var> or condition <var>C2</var> is satisfied.
</p></dd>
<dt><code>?=(<var>V1</var>,<var>C2</var>)</code></dt>
<dd><p>Delay until terms <var>V1</var> and <var>V1</var> have been unified.
</p></dd>
<dt><code>nonvar(<var>V</var>)</code></dt>
<dd><p>Delay until variable <var>V</var> is bound.
</p></dd>
<dt><code>ground(<var>V</var>)</code></dt>
<dd><p>Delay until variable <var>V</var> is ground.
</p></dd>
</dl>
<p>Note that <code>when/2</code> will fail if the conditions fail.
</p>
</dd>
<dt><code>call_residue(:<var>G</var>,<var>L</var>)</code></dt>
<dd><a name="index-call_005fresidue_002f2"></a>
<a name="index-call_005fresidue_002f2-1"></a>
<a name="index-call_005fresidue_002f2-2"></a>
<p>Call goal <var>G</var>. If subgoals of <var>G</var> 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 <code>dif/2</code> suspends twice, once outside <code>call_residue/2</code>,
and the other inside:
</p>
<div class="example">
<pre class="example">?- 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
</pre></div>
<p>The system only reports one invocation of <code>dif/2</code> as having
suspended.
</p>
</dd>
<dt><code>call_residue_vars(:<var>G</var>,<var>L</var>)</code></dt>
<dd><a name="index-call_005fresidue_005fvars_002f2"></a>
<a name="index-call_005fresidue_005fvars_002f2-1"></a>
<a name="index-call_005fresidue_005fvars_002f2-2"></a>
<p>Call goal <var>G</var> and unify <var>L</var> with a list of all constrained variables created <em>during</em> execution of <var>G</var>:
</p>
<div class="example">
<pre class="example"> ?- dif(X,Z), call_residue_vars(dif(X,Y),L).
dif(X,Z), call_residue_vars(dif(X,Y),L).
L = [Y],
dif(X,Z),
dif(X,Y) ? ;
no
</pre></div>
</dd>
</dl>
<hr>
<a name="Attributed-Variables"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Extensions" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Co_002droutining" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#New-Style-Attribute-Declarations" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Attributed-Variables-1"></a>
<h1 class="chapter">11 Attributed Variables</h1>
<a name="index-attributed-variables"></a>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> New Style code
</td></tr>
<tr><td align="left" valign="top"><a href="#Old-Style-Attribute-Declarations">11.2 SICStus Prolog style Attribute Declarations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Old Style code (deprecated)
</td></tr>
</table>
<p>YAP supports attributed variables, originally 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 unification algorithm is
aware of attributed variables and will call user defined handlers when
trying to unify these variables.
</p>
<p>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&rsquo;s CLPQR, Fruewirth
and Holzbaur&rsquo;s CHR, and CLP(BN).
</p>
<p>Different Prolog systems implement attributed variables in different
ways. Traditionally, YAP has used the interface designed by SICStus
Prolog. This interface is still
available in the <tt>atts</tt> library, but from YAP-6.0.3 we recommend using
the hProlog, SWI style interface. The main reason to do so is that
most packages included in YAP that use attributed variables, such as CHR, CLP(FD), and CLP(QR),
rely on the SWI-Prolog interface.
</p>
<hr>
<a name="New-Style-Attribute-Declarations"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Attributed-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Attributed-Variables" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Attributed-Variables" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Old-Style-Attribute-Declarations" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="hProlog-and-SWI_002dProlog-style-Attribute-Declarations"></a>
<h2 class="section">11.1 hProlog and SWI-Prolog style Attribute Declarations</h2>
<p>The following documentation is taken from the SWI-Prolog manual.
</p>
<p>Binding an attributed variable schedules a goal to be executed at the
first possible opportunity. In the current implementation the hooks are
executed immediately after a successful unification of the clause-head
or successful completion of a foreign language (built-in) predicate. Each
attribute is associated to a module and the hook <code>attr_unify_hook/2</code> is
executed in this module. The example below realises a very simple and
incomplete finite domain reasoner.
</p>
<div class="example">
<pre class="example">:- module(domain,
[ domain/2 % Var, ?Domain
]).
:- use_module(library(ordsets)).
domain(X, Dom) :-
var(Dom), !,
get_attr(X, domain, Dom).
domain(X, List) :-
list_to_ord_set(List, Domain),
put_attr(Y, domain, Domain),
X = Y.
% An attributed variable with attribute value Domain has been
% assigned the value Y
attr_unify_hook(Domain, Y) :-
( get_attr(Y, domain, Dom2)
-&gt; ord_intersection(Domain, Dom2, NewDomain),
( NewDomain == []
-&gt; fail
; NewDomain = [Value]
-&gt; Y = Value
; put_attr(Y, domain, NewDomain)
)
; var(Y)
-&gt; put_attr( Y, domain, Domain )
; ord_memberchk(Y, Domain)
).
% Translate attributes from this module to residual goals
attribute_goals(X) --&gt;
{ get_attr(X, domain, List) },
[domain(X, List)].
</pre></div>
<p>Before explaining the code we give some example queries:
</p>
<table>
<tr><td width="70%"><code>?- domain(X, [a,b]), X = c</code></td><td width="30%"><code>fail</code></td></tr>
<tr><td width="70%"><code>domain(X, [a,b]), domain(X, [a,c]).</code></td><td width="30%"><code>X=a</code></td></tr>
<tr><td width="70%"><code>domain(X, [a,b,c]), domain(X, [a,c]).</code></td><td width="30%"><code>domain(X, [a,c]).</code></td></tr>
</table>
<p>The predicate <code>domain/2</code> fetches (first clause) or assigns
(second clause) the variable a <em>domain</em>, 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 <code>attr_unify_hook/2</code> 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 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). The nonterminal <code>attribute_goals/3</code> is used to translate
remaining attributes to user-readable goals that, when executed, reinstate
these attributes.
</p>
<dl compact="compact">
<dt><code>attvar(?<var>Term</var>)</code></dt>
<dd><a name="index-attvar_002f1"></a>
<a name="index-attvar_002f1-1"></a>
<a name="index-attvar_002f1-2"></a>
<p>Succeeds if <code>Term</code> is an attributed variable. Note that <code>var/1</code> also
succeeds on attributed variables. Attributed variables are created with
<code>put_attr/3</code>.
</p>
</dd>
<dt><code>put_attr(+<var>Var</var>,+<var>Module</var>,+<var>Value</var>)</code></dt>
<dd><a name="index-put_005fattr_002f3"></a>
<a name="index-put_005fattr_002f3-1"></a>
<a name="index-put_005fattr_002f3-2"></a>
<p>If <var>Var</var> is a variable or attributed variable, set the value for the
attribute named <var>Module</var> to <var>Value</var>. If an attribute with this
name is already associated with <var>Var</var>, the old value is replaced.
Backtracking will restore the old value (i.e., an attribute is a mutable
term. See also <code>setarg/3</code>). This predicate raises a representation error if
<var>Var</var> is not a variable and a type error if <var>Module</var> is not an atom.
</p>
</dd>
<dt><code>get_attr(+<var>Var</var>,+<var>Module</var>,-<var>Value</var>)</code></dt>
<dd><a name="index-get_005fattr_002f3"></a>
<a name="index-get_005fattr_002f3-1"></a>
<a name="index-get_005fattr_002f3-2"></a>
<p>Request the current <var>value</var> for the attribute named <var>Module</var>. If
<var>Var</var> is not an attributed variable or the named attribute is not
associated to <var>Var</var> this predicate fails silently. If <var>Module</var>
is not an atom, a type error is raised.
</p>
</dd>
<dt><code>del_attr(+<var>Var</var>,+<var>Module</var>)</code></dt>
<dd><a name="index-del_005fattr_002f2"></a>
<a name="index-del_005fattr_002f2-1"></a>
<a name="index-del_005fattr_002f2-2"></a>
<p>Delete the named attribute. If <var>Var</var> loses its last attribute it
is transformed back into a traditional Prolog variable. If <var>Module</var>
is not an atom, a type error is raised. In all other cases this
predicate succeeds regardless whether or not the named attribute is
present.
</p>
</dd>
<dt><code>attr_unify_hook(+<var>AttValue</var>,+<var>VarValue</var>)</code></dt>
<dd><a name="index-attr_005funify_005fhook_002f2"></a>
<a name="index-attr_005funify_005fhook_002f2-1"></a>
<a name="index-attr_005funify_005fhook_002f2-2"></a>
<p>Hook that must be defined in the module an attributed variable refers
to. Is is called <em>after</em> the attributed variable has been
unified with a non-var term, possibly another attributed variable.
<var>AttValue</var> is the attribute that was associated to the variable
in this module and <var>VarValue</var> is the new value of the variable.
Normally this predicate fails to veto binding the variable to
<var>VarValue</var>, forcing backtracking to undo the binding. If
<var>VarValue</var> is another attributed variable the hook often combines
the two attribute and associates the combined attribute with
<var>VarValue</var> using <code>put_attr/3</code>.
</p>
</dd>
<dt><code>attr_portray_hook(+<var>AttValue</var>,+<var>Var</var>)</code></dt>
<dd><a name="index-attr_005fportray_005fhook_002f2"></a>
<a name="index-attr_005fportray_005fhook_002f2-1"></a>
<a name="index-attr_005fportray_005fhook_002f2-2"></a>
<p>Called by <code>write_term/2</code> and friends for each attribute if the option
<code>attributes(portray)</code> is in effect. If the hook succeeds the
attribute is considered printed. Otherwise <code>Module = ...</code> is
printed to indicate the existence of a variable.
</p>
</dd>
<dt><code>attribute_goals(+<var>Var</var>,-<var>Gs</var>,+<var>GsRest</var>)</code></dt>
<dd><a name="index-attribute_005fgoals_002f2"></a>
<a name="index-attribute_005fgoals_002f2-1"></a>
<a name="index-attribute_005fgoals_002f2-2"></a>
<p>This nonterminal, if it is defined in a module, is used by <var>copy_term/3</var>
to project attributes of that module to residual goals. It is also
used by the toplevel to obtain residual goals after executing a query.
</p></dd>
</dl>
<p>Normal user code should deal with <code>put_attr/3</code>, <code>get_attr/3</code> and <code>del_attr/2</code>.
The routines in this section fetch or set the entire attribute list of a
variables. Use of these predicates is anticipated to be restricted to
printing and other special purpose operations.
</p>
<dl compact="compact">
<dt><code>get_attrs(+<var>Var</var>,-<var>Attributes</var>)</code></dt>
<dd><a name="index-get_005fattrs_002f2"></a>
<a name="index-get_005fattrs_002f2-1"></a>
<a name="index-get_005fattrs_002f2-2"></a>
<p>Get all attributes of <var>Var</var>. <var>Attributes</var> is a term of the form
<code>att(<var>Module</var>, <var>Value</var>, <var>MoreAttributes</var>)</code>, where <var>MoreAttributes</var> is
<code>[]</code> for the last attribute.
</p>
</dd>
<dt><code>put_attrs(+<var>Var</var>,+<var>Attributes</var>)</code></dt>
<dd><a name="index-put_005fattrs_002f2"></a>
<a name="index-put_005fattrs_002f2-1"></a>
<a name="index-put_005fattrs_002f2-2"></a>
<p>Set all attributes of <var>Var</var>. See <code>get_attrs/2</code> for a description of
<var>Attributes</var>.
</p>
</dd>
<dt><code>del_attrs(+<var>Var</var>)</code></dt>
<dd><a name="index-del_005fattrs_002f1"></a>
<a name="index-del_005fattrs_002f1-1"></a>
<a name="index-del_005fattrs_002f1-2"></a>
<p>If <var>Var</var> is an attributed variable, delete <em>all</em> its
attributes. In all other cases, this predicate succeeds without
side-effects.
</p>
</dd>
<dt><code>term_attvars(+<var>Term</var>,-<var>AttVars</var>)</code></dt>
<dd><a name="index-term_005fattvars_002f2"></a>
<a name="index-term_005fattvars_002f2-1"></a>
<a name="index-term_005fattvars_002f2-2"></a>
<p><var>AttVars</var> is a list of all attributed variables in <var>Term</var> and
its attributes. I.e., <code>term_attvars/2</code> works recursively through
attributes. This predicate is Cycle-safe.
</p>
</dd>
<dt><code>copy_term(?<var>TI</var>,-<var>TF</var>,-<var>Goals</var>)</code></dt>
<dd><a name="index-copy_005fterm_002f3"></a>
<a name="index-copy_005fterm_002f3-1"></a>
<a name="index-copy_005fterm_002f3-2"></a>
<p>Term <var>TF</var> is a variant of the original term <var>TI</var>, such that for
each variable <var>V</var> in the term <var>TI</var> there is a new variable <var>V&rsquo;</var>
in term <var>TF</var> without any attributes attached. Attributed
variables are thus converted to standard variables. <var>Goals</var> is
unified with a list that represents the attributes. The goal
<code>maplist(call,<var>Goals</var>)</code> can be called to recreate the
attributes.
</p>
<p>Before the actual copying, <code>copy_term/3</code> calls
<code>attribute_goals/1</code> in the module where the attribute is
defined.
</p>
</dd>
<dt><code>copy_term_nat(?<var>TI</var>,-<var>TF</var>)</code></dt>
<dd><a name="index-copy_005fterm_005fnat_002f2"></a>
<a name="index-copy_005fterm_005fnat_002f2-1"></a>
<a name="index-copy_005fterm_005fnat_002f2-2"></a>
<p>As <code>copy_term/2</code>. Attributes however, are <em>not</em> copied but replaced
by fresh variables.
</p></dd>
</dl>
<hr>
<a name="Old-Style-Attribute-Declarations"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Attributed-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#New-Style-Attribute-Declarations" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Attributed-Variables" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Attribute-Declarations" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="SICStus-Prolog-style-Attribute-Declarations"></a>
<h2 class="section">11.2 SICStus Prolog style Attribute Declarations</h2>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Attribute-Declarations">11.2.1 Attribute Declarations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Declaring New Attributes
</td></tr>
<tr><td align="left" valign="top"><a href="#Attribute-Manipulation">11.2.2 Attribute Manipulation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Setting and Reading Attributes
</td></tr>
<tr><td align="left" valign="top"><a href="#Attributed-Unification">11.2.3 Attributed Unification</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Tuning the Unification Algorithm
</td></tr>
<tr><td align="left" valign="top"><a href="#Displaying-Attributes">11.2.4 Displaying Attributes</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Displaying Attributes in User-Readable Form
</td></tr>
<tr><td align="left" valign="top"><a href="#Projecting-Attributes">11.2.5 Projecting Attributes</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Obtaining the Attributes of Interest
</td></tr>
<tr><td align="left" valign="top"><a href="#Attribute-Examples">11.2.6 Attribute Examples</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Two Simple Examples of how to use Attributes.
</td></tr>
</table>
<p>Old style attribute declarations are activated through loading the library <tt>atts</tt> . The command
</p><div class="example">
<pre class="example">| ?- use_module(library(atts)).
</pre></div>
<p>enables this form of use of attributed variables. The package provides the
following functionality:
</p><ul>
<li> 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.
</li><li> The built-in <code>put_atts/2</code> 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.
</li><li> The built-in <code>get_atts/2</code> can be used to check the values of
an attribute associated with a variable.
</li><li> The unification algorithm calls the user-defined predicate
<tt>verify_attributes/3</tt> before trying to bind an attributed
variable. Unification will resume after this call.
</li><li> The user-defined predicate
<tt>attribute_goal/2</tt> converts from an attribute to a goal.
</li><li> The user-defined predicate
<tt>project_attributes/2</tt> is used from a set of variables into a set of
constraints or goals. One application of <tt>project_attributes/2</tt> is in
the top-level, where it is used to output the set of
floundered constraints at the end of a query.
</li></ul>
<hr>
<a name="Attribute-Declarations"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Attributed-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Old-Style-Attribute-Declarations" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Old-Style-Attribute-Declarations" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Attribute-Manipulation" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Attribute-Declarations-1"></a>
<h3 class="subsection">11.2.1 Attribute Declarations</h3>
<p>Attributes are compound terms associated with a variable. Each attribute
has a <em>name</em> which is <em>private</em> to the module in which the
attribute was defined. Variables may have at most one attribute with a
name. Attribute names are defined with the following declaration:
</p>
<a name="index-attribute-declaration"></a>
<a name="index-declaration_002c-attribute"></a>
<a name="index-attribute_002f1-_0028declaration_0029"></a>
<div class="example">
<pre class="example">:- attribute <var>AttributeSpec</var>, ..., <var>AttributeSpec</var>.
</pre></div>
<p>where each <var>AttributeSpec</var> has the form (<var>Name</var>/<var>Arity</var>).
One single such declaration is allowed per module <var>Module</var>.
</p>
<p>Although the YAP module system is predicate based, attributes are local
to modules. This is implemented by rewriting all calls to the
built-ins that manipulate attributes so that attribute names are
preprocessed depending on the module. The <code>user:goal_expansion/3</code>
mechanism is used for this purpose.
</p>
<hr>
<a name="Attribute-Manipulation"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Attributed-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Attribute-Declarations" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Old-Style-Attribute-Declarations" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Attributed-Unification" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Attribute-Manipulation-1"></a>
<h3 class="subsection">11.2.2 Attribute Manipulation</h3>
<p>The attribute manipulation predicates always work as follows:
</p><ol>
<li> The first argument is the unbound variable associated with
attributes,
</li><li> The second argument is a list of attributes. Each attribute will
be a Prolog term or a constant, prefixed with the <tt>+</tt> and <tt>-</tt> unary
operators. The prefix <tt>+</tt> may be dropped for convenience.
</li></ol>
<p>The following three procedures are available to the user. Notice that
these built-ins are rewritten by the system into internal built-ins, and
that the rewriting process <em>depends</em> on the module on which the
built-ins have been invoked.
</p>
<dl compact="compact">
<dt><code><var>Module</var>:get_atts(<var>-Var</var>,<var>?ListOfAttributes</var>)</code></dt>
<dd><a name="index-get_005fatts_002f2"></a>
<a name="index-get_005fatts_002f2-1"></a>
<a name="index-get_005fatts_002f2-2"></a>
<p>Unify the list <var>?ListOfAttributes</var> with the attributes for the unbound
variable <var>Var</var>. Each member of the list must be a bound term of the
form <code>+(<var>Attribute</var>)</code>, <code>-(<var>Attribute</var>)</code> (the <tt>kbd</tt>
prefix may be dropped). The meaning of <tt>+</tt> and <tt>-</tt> is:
</p></dd>
<dt><code>+(<var>Attribute</var>)</code></dt>
<dd><p>Unifies <var>Attribute</var> with a corresponding attribute associated with
<var>Var</var>, fails otherwise.
</p>
</dd>
<dt><code>-(<var>Attribute</var>)</code></dt>
<dd><p>Succeeds if a corresponding attribute is not associated with
<var>Var</var>. The arguments of <var>Attribute</var> are ignored.
</p>
</dd>
<dt><code><var>Module</var>:put_atts(<var>-Var</var>,<var>?ListOfAttributes</var>)</code></dt>
<dd><a name="index-put_005fatts_002f2"></a>
<a name="index-put_005fatts_002f2-1"></a>
<a name="index-put_005fatts_002f2-2"></a>
<p>Associate with or remove attributes from a variable <var>Var</var>. The
attributes are given in <var>?ListOfAttributes</var>, and the action depends
on how they are prefixed:
</p></dd>
<dt><code>+(<var>Attribute</var>)</code></dt>
<dd><p>Associate <var>Var</var> with <var>Attribute</var>. A previous value for the
attribute is simply replace (like with <code>set_mutable/2</code>).
</p>
</dd>
<dt><code>-(<var>Attribute</var>)</code></dt>
<dd><p>Remove the attribute with the same name. If no such attribute existed,
simply succeed.
</p></dd>
</dl>
<hr>
<a name="Attributed-Unification"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Attributed-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Attribute-Manipulation" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Old-Style-Attribute-Declarations" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Displaying-Attributes" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Attributed-Unification-1"></a>
<h3 class="subsection">11.2.3 Attributed Unification</h3>
<p>The user-predicate predicate <code>verify_attributes/3</code> is called when
attempting to unify an attributed variable which might have attributes
in some <var>Module</var>.
</p>
<dl compact="compact">
<dt><code><var>Module</var>:verify_attributes(<var>-Var</var>, <var>+Value</var>, <var>-Goals</var>)</code></dt>
<dd><a name="index-verify_005fattributes_002f3"></a>
<a name="index-verify_005fattributes_002f3-1"></a>
<a name="index-verify_005fattributes_002f3-2"></a>
<p>The predicate is called when trying to unify the attributed variable
<var>Var</var> with the Prolog term <var>Value</var>. Note that <var>Value</var> may be
itself an attributed variable, or may contain attributed variables. The
goal <tt>verify_attributes/3</tt> is actually called before <var>Var</var> is
unified with <var>Value</var>.
</p>
<p>It is up to the user to define which actions may be performed by
<tt>verify_attributes/3</tt> but the procedure is expected to return in
<var>Goals</var> a list of goals to be called <em>after</em> <var>Var</var> is
unified with <var>Value</var>. If <tt>verify_attributes/3</tt> fails, the
unification will fail.
</p>
<p>Notice that the <tt>verify_attributes/3</tt> may be called even if <var>Var</var>
has no attributes in module <tt>Module</tt>. In this case the routine should
simply succeed with <var>Goals</var> unified with the empty list.
</p>
</dd>
<dt><code>attvar(<var>-Var</var>)</code></dt>
<dd><a name="index-attvar_002f1-3"></a>
<a name="index-attvar_002f1-4"></a>
<a name="index-attvar_002f1-5"></a>
<p>Succeed if <var>Var</var> is an attributed variable.
</p></dd>
</dl>
<hr>
<a name="Displaying-Attributes"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Attributed-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Attributed-Unification" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Old-Style-Attribute-Declarations" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Projecting-Attributes" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Displaying-Attributes-1"></a>
<h3 class="subsection">11.2.4 Displaying Attributes</h3>
<p>Attributes are usually presented as goals. The following routines are
used by built-in predicates such as <code>call_residue/2</code> and by the
Prolog top-level to display attributes:
</p>
<dl compact="compact">
<dt><code><var>Module</var>:attribute_goal(<var>-Var</var>, <var>-Goal</var>)</code></dt>
<dd><a name="index-attribute_005fgoal_002f2"></a>
<a name="index-attribute_005fgoal_002f2-1"></a>
<a name="index-attribute_005fgoal_002f2-2"></a>
<p>User-defined procedure, called to convert the attributes in <var>Var</var> to
a <var>Goal</var>. Should fail when no interpretation is available.
</p>
</dd>
<dt><code><var>Module</var>:project_attributes(<var>-QueryVars</var>, <var>+AttrVars</var>)</code></dt>
<dd><a name="index-project_005fattributes_002f2"></a>
<a name="index-project_005fattributes_002f2-1"></a>
<a name="index-project_005fattributes_002f2-2"></a>
<p>User-defined procedure, called to project the attributes in the query,
<var>AttrVars</var>, given that the set of variables in the query is
<var>QueryVars</var>.
</p>
</dd>
</dl>
<hr>
<a name="Projecting-Attributes"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Attributed-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Displaying-Attributes" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Old-Style-Attribute-Declarations" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Attribute-Examples" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Projecting-Attributes-1"></a>
<h3 class="subsection">11.2.5 Projecting Attributes</h3>
<p>Constraint solvers must be able to project a set of constraints to a set
of variables. This is useful when displaying the solution to a goal, but
may also be used to manipulate computations. The user-defined
<code>project_attributes/2</code> is responsible for implementing this
projection.
</p>
<dl compact="compact">
<dt><code><var>Module</var>:project_attributes(<var>+QueryVars</var>, <var>+AttrVars</var>)</code></dt>
<dd><a name="index-project_005fattributes_002f2-3"></a>
<a name="index-project_005fattributes_002f2-4"></a>
<a name="index-project_005fattributes_002f2-5"></a>
<p>Given a list of variables <var>QueryVars</var> and list of attributed
variables <var>AttrVars</var>, project all attributes in <var>AttrVars</var> to
<var>QueryVars</var>. Although projection is constraint system dependent,
typically this will involve expressing all constraints in terms of
<var>QueryVars</var> and considering all remaining variables as existentially
quantified.
</p></dd>
</dl>
<p>Projection interacts with <code>attribute_goal/2</code> at the Prolog top
level. When the query succeeds, the system first calls
<code>project_attributes/2</code>. The system then calls
<code>attribute_goal/2</code> to get a user-level representation of the
constraints. Typically, <code>attribute_goal/2</code> will convert from the
original constraints into a set of new constraints on the projection,
and these constraints are the ones that will have an
<code>attribute_goal/2</code> handler.
</p>
<hr>
<a name="Attribute-Examples"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Attributed-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Projecting-Attributes" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Old-Style-Attribute-Declarations" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Attribute-Examples-1"></a>
<h3 class="subsection">11.2.6 Attribute Examples</h3>
<p>The following two examples example is taken from the SICStus Prolog manual. It
sketches the implementation of a simple finite domain &ldquo;solver&rdquo;. Note
that an industrial strength solver would have to provide a wider range
of functionality and that it quite likely would utilize a more efficient
representation for the domains proper. The module exports a single
predicate <code>domain(<var>-Var</var>,<var>?Domain</var>)</code> which associates
<var>Domain</var> (a list of terms) with <var>Var</var>. A variable can be
queried for its domain by leaving <var>Domain</var> unbound.
</p>
<p>We do not present here a definition for <code>project_attributes/2</code>.
Projecting finite domain constraints happens to be difficult.
</p>
<div class="example">
<pre class="example">:- 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.
verify_attributes(Var, Other, Goals) :-
get_atts(Var, dom(Da)), !, % are we involved?
( var(Other) -&gt; % must be attributed then
( get_atts(Other, dom(Db)) -&gt; % has a domain?
ord_intersection(Da, Db, Dc),
Dc = [El|Els], % at least one element
( Els = [] -&gt; % exactly one element
Goals = [Other=El] % implied binding
; Goals = [],
put_atts(Other, dom(Dc))% rescue intersection
)
; Goals = [],
put_atts(Other, dom(Da)) % rescue the domain
)
; Goals = [],
ord_intersect([Other], Da) % value in domain?
).
verify_attributes(_, _, []). % unification triggered
% because of attributes
% in other modules
attribute_goal(Var, domain(Var,Dom)) :- % interpretation as goal
get_atts(Var, dom(Dom)).
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 = [] -&gt; % exactly one element
X = El % implied binding
; put_atts(Fresh, dom(Set)),
X = Fresh % may call
% verify_attributes/3
).
</pre></div>
<p>Note that the &ldquo;implied binding&rdquo; <code>Other=El</code> was deferred until after
the completion of <code>verify_attribute/3</code>. Otherwise, there might be a
danger of recursively invoking <code>verify_attribute/3</code>, which might bind
<code>Var</code>, which is not allowed inside the scope of <code>verify_attribute/3</code>.
Deferring unifications into the third argument of <code>verify_attribute/3</code>
effectively serializes the calls to <code>verify_attribute/3</code>.
</p>
<p>Assuming that the code resides in the file &lsquo;<tt>domain.yap</tt>&rsquo;, we
can use it via:
</p>
<div class="example">
<pre class="example">| ?- use_module(domain).
</pre></div>
<p>Let&rsquo;s test it:
</p>
<div class="example">
<pre class="example">| ?- 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
</pre></div>
<p>To demonstrate the use of the <var>Goals</var> argument of
<code>verify_attributes/3</code>, we give an implementation of
<code>freeze/2</code>. We have to name it <code>myfreeze/2</code> in order to
avoid a name clash with the built-in predicate of the same name.
</p>
<div class="example">
<pre class="example">:- module(myfreeze, [myfreeze/2]).
:- use_module(library(atts)).
:- attribute frozen/1.
verify_attributes(Var, Other, Goals) :-
get_atts(Var, frozen(Fa)), !, % are we involved?
( var(Other) -&gt; % must be attributed then
( get_atts(Other, frozen(Fb)) % has a pending goal?
-&gt; put_atts(Other, frozen((Fa,Fb))) % rescue conjunction
; put_atts(Other, frozen(Fa)) % rescue the pending goal
),
Goals = []
; Goals = [Fa]
).
verify_attributes(_, _, []).
attribute_goal(Var, Goal) :- % interpretation as goal
get_atts(Var, frozen(Goal)).
myfreeze(X, Goal) :-
put_atts(Fresh, frozen(Goal)),
Fresh = X.
</pre></div>
<p>Assuming that this code lives in file &lsquo;<tt>myfreeze.yap</tt>&rsquo;,
we would use it via:
</p>
<div class="example">
<pre class="example">| ?- use_module(myfreeze).
| ?- myfreeze(X,print(bound(x,X))), X=2.
bound(x,2) % side effect
X = 2 % bindings
</pre></div>
<p>The two solvers even work together:
</p>
<div class="example">
<pre class="example">| ?- myfreeze(X,print(bound(x,X))), domain(X,[1,2,3]),
domain(Y,[2,10]), X=Y.
bound(x,2) % side effect
X = 2, % bindings
Y = 2
</pre></div>
<p>The two example solvers interact via bindings to shared attributed
variables only. More complicated interactions are likely to be found
in more sophisticated solvers. The corresponding
<code>verify_attributes/3</code> predicates would typically refer to the
attributes from other known solvers/modules via the module prefix in
<code><var>Module</var>:get_atts/2</code>.
</p>
<hr>
<a name="CLPR"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Attributed-Variables" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Attribute-Examples" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR-Solver-Predicates" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="index-CLPQ"></a>
<a name="index-CLPR"></a>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#CLPR-Solver-Predicates">12.1 Solver Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CLPR-Syntax">12.2 Syntax of the predicate arguments</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CLPR-Unification">12.3 Use of unification</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CLPR-Non_002dlinear-Constraints">12.4 Non-Linear Constraints</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<a name="Constraint-Logic-Programming-over-Reals"></a>
<h1 class="chapter">12 Constraint Logic Programming over Reals</h1>
<p>YAP now uses the CLP(R) package developed by <em>Leslie De Koninck</em>,
K.U. Leuven as part of a thesis with supervisor Bart Demoen and daily
advisor Tom Schrijvers, and distributed with SWI-Prolog.
</p>
<p>This CLP(R) system is a port of the CLP(Q,R) system of Sicstus Prolog
and YAP by Christian Holzbaur: Holzbaur C.: OFAI clp(q,r) Manual,
Edition 1.3.3, Austrian Research Institute for Artificial
Intelligence, Vienna, TR-95-09, 1995,
<a href="http://www.ai.univie.ac.at/cgi-bin/tr-online?number+95-09">http://www.ai.univie.ac.at/cgi-bin/tr-online?number+95-09</a> This
port only contains the part concerning real arithmetics. This manual
is roughly based on the manual of the above mentioned <strong>CLP(QR)</strong>
implementation.
</p>
<p>Please note that the &lsquo;<tt>clpr</tt>&rsquo; library is <em>not</em> an
<code>autoload</code> library and therefore this library must be loaded
explicitely before using it:
</p>
<div class="example">
<pre class="example">:- use_module(library(clpr)).
</pre></div>
<hr>
<a name="CLPR-Solver-Predicates"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CLPR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR-Syntax" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Solver-Predicates"></a>
<h2 class="section">12.1 Solver Predicates</h2>
<p>The following predicates are provided to work with constraints:
</p>
<dl compact="compact">
<dt><code>{+<var>Constraints</var>}</code></dt>
<dd><p>Adds the constraints given by <var>Constraints</var> to the constraint store.
</p>
</dd>
<dt><code>entailed(+<var>Constraint</var>)</code></dt>
<dd><p>Succeeds if <var>Constraint</var> is necessarily true within the current
constraint store. This means that adding the negation of the constraint
to the store results in failure.
</p>
</dd>
<dt><code>inf(+<var>Expression</var>,-<var>Inf</var>)</code></dt>
<dd><p>Computes the infimum of <var>Expression</var> within the current state of the
constraint store and returns that infimum in <var>Inf</var>. This predicate
does not change the constraint store.
</p>
</dd>
<dt><code>inf(+<var>Expression</var>,-<var>Sup</var>)</code></dt>
<dd><p>Computes the supremum of <var>Expression</var> within the current state of
the constraint store and returns that supremum in <var>Sup</var>. This
predicate does not change the constraint store.
</p>
</dd>
<dt><code>min(+<var>Expression</var>)</code></dt>
<dd><p>Minimizes <var>Expression</var> within the current constraint store. This is
the same as computing the infimum and equation the expression to that
infimum.
</p>
</dd>
<dt><code>max(+<var>Expression</var>)</code></dt>
<dd><p>Maximizes <var>Expression</var> within the current constraint store. This is
the same as computing the supremum and equating the expression to that
supremum.
</p>
</dd>
<dt><code>bb_inf(+<var>Ints</var>,+<var>Expression</var>,-<var>Inf</var>,-<var>Vertext</var>,+<var>Eps</var>)</code></dt>
<dd><p>Computes the infimum of <var>Expression</var> within the current constraint
store, with the additional constraint that in that infimum, all
variables in <var>Ints</var> have integral values. <var>Vertex</var> will contain
the values of <var>Ints</var> in the infimum. <var>Eps</var> denotes how much a
value may differ from an integer to be considered an integer. E.g. when
<var>Eps</var> = 0.001, then X = 4.999 will be considered as an integer (5 in
this case). <var>Eps</var> should be between 0 and 0.5.
</p>
</dd>
<dt><code>bb_inf(+<var>Ints</var>,+<var>Expression</var>,-<var>Inf</var>)</code></dt>
<dd><p>The same as bb_inf/5 but without returning the values of the integers
and with an eps of 0.001.
</p>
</dd>
<dt><code>dump(+<var>Target</var>,+<var>Newvars</var>,-<var>CodedAnswer</var>)</code></dt>
<dd><p>Returns the constraints on <var>Target</var> in the list <var>CodedAnswer</var>
where all variables of <var>Target</var> have veen replaced by <var>NewVars</var>.
This operation does not change the constraint store. E.g. in
</p>
<div class="example">
<pre class="example">dump([X,Y,Z],[x,y,z],Cons)
</pre></div>
<p><var>Cons</var> will contain the constraints on <var>X</var>, <var>Y</var> and
<var>Z</var> where these variables have been replaced by atoms <code>x</code>, <code>y</code> and <code>z</code>.
</p>
</dd>
</dl>
<hr>
<a name="CLPR-Syntax"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CLPR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR-Solver-Predicates" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR-Unification" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Syntax-of-the-predicate-arguments"></a>
<h2 class="section">12.2 Syntax of the predicate arguments</h2>
<p>The arguments of the predicates defined in the subsection above are
defined in the following table. Failing to meet the syntax rules will
result in an exception.
</p>
<div class="example">
<pre class="example">&lt;Constraints&gt; ---&gt; &lt;Constraint&gt; \\ single constraint \\
| &lt;Constraint&gt; , &lt;Constraints&gt; \\ conjunction \\
| &lt;Constraint&gt; ; &lt;Constraints&gt; \\ disjunction \\
&lt;Constraint&gt; ---&gt; &lt;Expression&gt; {&lt;} &lt;Expression&gt; \\ less than \\
| &lt;Expression&gt; {&gt;} &lt;Expression&gt; \\ greater than \\
| &lt;Expression&gt; {=&lt;} &lt;Expression&gt; \\ less or equal \\
| {&lt;=}(&lt;Expression&gt;, &lt;Expression&gt;) \\ less or equal \\
| &lt;Expression&gt; {&gt;=} &lt;Expression&gt; \\ greater or equal \\
| &lt;Expression&gt; {=\=} &lt;Expression&gt; \\ not equal \\
| &lt;Expression&gt; =:= &lt;Expression&gt; \\ equal \\
| &lt;Expression&gt; = &lt;Expression&gt; \\ equal \\
&lt;Expression&gt; ---&gt; &lt;Variable&gt; \\ Prolog variable \\
| &lt;Number&gt; \\ Prolog number (float, integer) \\
| +&lt;Expression&gt; \\ unary plus \\
| -&lt;Expression&gt; \\ unary minus \\
| &lt;Expression&gt; + &lt;Expression&gt; \\ addition \\
| &lt;Expression&gt; - &lt;Expression&gt; \\ substraction \\
| &lt;Expression&gt; * &lt;Expression&gt; \\ multiplication \\
| &lt;Expression&gt; / &lt;Expression&gt; \\ division \\
| abs(&lt;Expression&gt;) \\ absolute value \\
| sin(&lt;Expression&gt;) \\ sine \\
| cos(&lt;Expression&gt;) \\ cosine \\
| tan(&lt;Expression&gt;) \\ tangent \\
| exp(&lt;Expression&gt;) \\ exponent \\
| pow(&lt;Expression&gt;) \\ exponent \\
| &lt;Expression&gt; {^} &lt;Expression&gt; \\ exponent \\
| min(&lt;Expression&gt;, &lt;Expression&gt;) \\ minimum \\
| max(&lt;Expression&gt;, &lt;Expression&gt;) \\ maximum \\
</pre></div>
<hr>
<a name="CLPR-Unification"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CLPR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR-Syntax" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR-Non_002dlinear-Constraints" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Use-of-unification"></a>
<h2 class="section">12.3 Use of unification</h2>
<p>Instead of using the <code>{}/1</code> predicate, you can also use the standard
unification mechanism to store constraints. The following code samples
are equivalent:
</p>
<dl compact="compact">
<dt>&lsquo;<samp>Unification with a variable</samp>&rsquo;</dt>
<dd>
<div class="example">
<pre class="example">{X =:= Y}
{X = Y}
X = Y
</pre></div>
</dd>
<dt>&lsquo;<samp>Unification with a number</samp>&rsquo;</dt>
<dd>
<div class="example">
<pre class="example">{X =:= 5.0}
{X = 5.0}
X = 5.0
</pre></div>
</dd>
</dl>
<hr>
<a name="CLPR-Non_002dlinear-Constraints"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CLPR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR-Unification" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Non_002dLinear-Constraints"></a>
<h2 class="section">12.4 Non-Linear Constraints</h2>
<p>In this version, non-linear constraints do not get solved until certain
conditions are satisfied. We call these conditions the isolation axioms.
They are given in the following table.
</p>
<div class="example">
<pre class="example">A = B * C when B or C is ground or // A = 5 * C or A = B * 4 \\
A and (B or C) are ground // 20 = 5 * C or 20 = B * 4 \\
A = B / C when C is ground or // A = B / 3
A and B are ground // 4 = 12 / C
X = min(Y,Z) when Y and Z are ground or // X = min(4,3)
X = max(Y,Z) Y and Z are ground // X = max(4,3)
X = abs(Y) Y is ground // X = abs(-7)
X = pow(Y,Z) when X and Y are ground or // 8 = 2 ^ Z
X = exp(Y,Z) X and Z are ground // 8 = Y ^ 3
X = Y ^ Z Y and Z are ground // X = 2 ^ 3
X = sin(Y) when X is ground or // 1 = sin(Y)
X = cos(Y) Y is ground // X = sin(1.5707)
X = tan(Y)
</pre></div>
<hr>
<a name="CHR"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CLPR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CLPR-Non_002dlinear-Constraints" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Introduction" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#CHR-Introduction">13.1 Introduction</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-Syntax-and-Semantics">13.2 Syntax and Semantics</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-in-YAP-Programs">13.3 CHR in YAP Programs</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-Debugging">13.4 Debugging</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-Examples">13.5 Examples</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-Compatibility">13.6 Compatibility with SICStus CHR</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#CHR-Guidelines">13.7 Guidelines</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<a name="CHR_003a-Constraint-Handling-Rules"></a>
<h1 class="chapter">13 CHR: Constraint Handling Rules</h1>
<p>This chapter is written by Tom Schrijvers, K.U. Leuven for the hProlog
system. Adjusted by Jan Wielemaker to fit the SWI-Prolog documentation
infrastructure and remove hProlog specific references.
</p>
<p>The CHR system of SWI-Prolog is the K.U.Leuven CHR system. The runtime
environment is written by Christian Holzbaur and Tom Schrijvers while the
compiler is written by Tom Schrijvers. Both are integrated with SWI-Prolog
and licenced under compatible conditions with permission from the authors.
</p>
<p>The main reference for SWI-Prolog&rsquo;s CHR system is:
</p><ul>
<li> T. Schrijvers, and B. Demoen, <em>The K.U.Leuven CHR System: Implementation
and Application</em>, First Workshop on Constraint Handling Rules: Selected
Contributions (Fruwirth, T. and Meister, M., eds.), pp. 1&ndash;5, 2004.
</li></ul>
<hr>
<a name="CHR-Introduction"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Syntax-and-Semantics" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Introduction-1"></a>
<h2 class="section">13.1 Introduction</h2>
<p>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 providing application-specific constraints.
It has been used in many kinds of applications, like scheduling,
model checking, abduction, type checking among many others.
</p>
<p>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.
</p>
<p>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.
</p>
<hr>
<a name="CHR-Syntax-and-Semantics"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Introduction" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Syntax-2" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Syntax-and-Semantics"></a>
<h2 class="section">13.2 Syntax and Semantics</h2>
<hr>
<a name="Syntax-2"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Syntax-and-Semantics" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Syntax-and-Semantics" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Semantics" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.2.1 Syntax</h3>
<p>The syntax of CHR rules in hProlog is the following:
</p>
<div class="example">
<pre class="example">rules --&gt; rule, rules.
rules --&gt; [].
rule --&gt; name, actual_rule, pragma, [atom('.')].
name --&gt; atom, [atom(')'].
name --&gt; [].
actual_rule --&gt; simplification_rule.
actual_rule --&gt; propagation_rule.
actual_rule --&gt; simpagation_rule.
simplification_rule --&gt; constraints, [atom('&lt;=&gt;')], guard, body.
propagation_rule --&gt; constraints, [atom('==&gt;')], guard, body.
simpagation_rule --&gt; constraints, [atom('\')], constraints, [atom('&lt;=&gt;')],
guard, body.
constraints --&gt; constraint, constraint_id.
constraints --&gt; constraint, [atom(',')], constraints.
constraint --&gt; compound_term.
constraint_id --&gt; [].
constraint_id --&gt; [atom('#')], variable.
guard --&gt; [].
guard --&gt; goal, [atom('|')].
body --&gt; goal.
pragma --&gt; [].
pragma --&gt; [atom('pragma')], actual_pragmas.
actual_pragmas --&gt; actual_pragma.
actual_pragmas --&gt; actual_pragma, [atom(',')], actual_pragmas.
actual_pragma --&gt; [atom('passive(')], variable, [atom(')')].
</pre></div>
<p>Additional syntax-related terminology:
</p>
<ul>
<li> <strong>head:</strong> the constraints in an <code>actual_rule</code> before
the arrow (either <code>&lt;=&gt;</code> or <code>==&gt;</code>)
</li></ul>
<hr>
<a name="Semantics"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Syntax-2" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Syntax-and-Semantics" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Rule-Types" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.2.2 Semantics</h3>
<p>In this subsection the operational semantics of CHR in Prolog are presented
informally. They do not differ essentially from other CHR systems.
</p>
<p>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.
</p>
<p>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.
</p>
<p>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.
</p>
<p>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 constraint 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.
</p>
<hr>
<a name="Rule-Types"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Semantics" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Semantics" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Rule-Names" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h4 class="unnumberedsubsubsec">Rule Types</h4>
<p>There are three different kinds of rules, each with their specific semantics:
</p>
<dl compact="compact">
<dt><code>simplification</code></dt>
<dd><p>The simplification rule removes the constraints in its head and calls its body.
</p>
</dd>
<dt><code>propagation</code></dt>
<dd><p>The propagation rule calls its body exactly once for the constraints in
its head.
</p>
</dd>
<dt><code>simpagation</code></dt>
<dd><p>The simpagation rule removes the constraints in its head after the
<code>\</code> and then calls its body. It is an optimization of
simplification rules of the form: \[constraints_1, constraints_2 &lt;=&gt;
constraints_1, body \] Namely, in the simpagation form:
</p>
<div class="example">
<pre class="example">constraints1 \ constraints2 &lt;=&gt; body
</pre></div>
<p><var>constraints1</var>
constraints are not called in the body.
</p></dd>
</dl>
<hr>
<a name="Rule-Names"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Rule-Types" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Semantics" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Pragmas" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h4 class="unnumberedsubsubsec">Rule Names</h4>
<p>Naming a rule is optional and has no semantical meaning. It only functions
as documentation for the programmer.
</p>
<hr>
<a name="Pragmas"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Rule-Names" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Semantics" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Options" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h4 class="unnumberedsubsubsec">Pragmas</h4>
<p>The semantics of the pragmas are:
</p>
<dl compact="compact">
<dt>&lsquo;<samp>passive(Identifier)</samp>&rsquo;</dt>
<dd><p>The constraint in the head of a rule <var>Identifier</var> can only act as a
passive constraint in that rule.
</p></dd>
</dl>
<p>Additional pragmas may be released in the future.
</p>
<hr>
<a name="Options"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Pragmas" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Semantics" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-in-YAP-Programs" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h4 class="unnumberedsubsubsec">Options</h4>
<p>It is possible to specify options that apply to all the CHR rules in the module.
Options are specified with the <code>option/2</code> declaration:
</p>
<div class="example">
<pre class="example"> option(Option,Value).
</pre></div>
<p>Available options are:
</p><dl compact="compact">
<dt><code>check_guard_bindings</code></dt>
<dd><p>This option controls whether guards should be checked for illegal
variable bindings or not. Possible values for this option are
<code>on</code>, to enable the checks, and <code>off</code>, to disable the
checks.
</p>
</dd>
<dt><code>optimize</code></dt>
<dd><p>This is an experimental option controlling the degree of optimization.
Possible values are <code>full</code>, to enable all available
optimizations, and <code>off</code> (default), to disable all optimizations.
The default is derived from the SWI-Prolog flag <code>optimise</code>, where
<code>true</code> is mapped to <code>full</code>. Therefore the commandline
option &lsquo;<samp>-O</samp>&rsquo; provides full CHR optimization.
If optimization is enabled, debugging should be disabled.
</p>
</dd>
<dt><code>debug</code></dt>
<dd><p>This options enables or disables the possibility to debug the CHR code.
Possible values are <code>on</code> (default) and <code>off</code>. See
&lsquo;<samp>debugging</samp>&rsquo; for more details on debugging. The default is
derived from the prolog flag <code>generate_debug_info</code>, which
is <code>true</code> by default. See &lsquo;<samp>-nodebug</samp>&rsquo;.
If debugging is enabled, optimization should be disabled.
</p>
</dd>
<dt><code>mode</code></dt>
<dd><p>This option specifies the mode for a particular constraint. The
value is a term with functor and arity equal to that of a constraint.
The arguments can be one of <code>-</code>, <code>+</code> or <code>?</code>.
The latter is the default. The meaning is the following:
</p><dl compact="compact">
<dt><code>-</code></dt>
<dd><p> The corresponding argument of every occurrence
of the constraint is always unbound.
</p></dd>
<dt><code>+</code></dt>
<dd><p> The corresponding argument of every occurrence
of the constraint is always ground.
</p></dd>
<dt><code>?</code></dt>
<dd><p> The corresponding argument of every occurrence
of the constraint can have any instantiation, which may change
over time. This is the default value.
</p></dd>
</dl>
<p>The declaration is used by the compiler for various optimizations.
Note that it is up to the user the ensure that the mode declaration
is correct with respect to the use of the constraint.
This option may occur once for each constraint.
</p>
</dd>
<dt><code>type_declaration</code></dt>
<dd><p>This option specifies the argument types for a particular constraint. The
value is a term with functor and arity equal to that of a constraint.
The arguments can be a user-defined type or one of
the built-in types:
</p><dl compact="compact">
<dt><code>int</code></dt>
<dd><p> The corresponding argument of every occurrence
of the constraint is an integer number.
</p></dd>
<dt><code>float</code></dt>
<dd><p> &hellip; a floating point number.
</p></dd>
<dt><code>number</code></dt>
<dd><p> &hellip; a number.
</p></dd>
<dt><code>natural</code></dt>
<dd><p> &hellip; a positive integer.
</p></dd>
<dt><code>any</code></dt>
<dd><p> The corresponding argument of every occurrence
of the constraint can have any type. This is the default value.
</p></dd>
</dl>
<p>Currently, type declarations are only used to improve certain
optimizations (guard simplification, occurrence subsumption, &hellip;).
</p>
</dd>
<dt><code>type_definition</code></dt>
<dd><p>This option defines a new user-defined type which can be used in
type declarations. The value is a term of the form
<code>type(</code><var>name</var><code>,</code><var>list</var><code>)</code>, where
<var>name</var> is a term and <var>list</var> is a list of alternatives.
Variables can be used to define generic types. Recursive definitions
are allowed. Examples are
</p>
<div class="example">
<pre class="example">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)]).
</pre></div>
</dd>
</dl>
<p>The mode, type_declaration and type_definition options are provided
for backward compatibility. The new syntax is described below.
</p>
<hr>
<a name="CHR-in-YAP-Programs"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Options" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Embedding-in-Prolog-Programs" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="CHR-in-YAP-Programs-1"></a>
<h2 class="section">13.3 CHR in YAP Programs</h2>
<hr>
<a name="Embedding-in-Prolog-Programs"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-in-YAP-Programs" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-in-YAP-Programs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Constraint-declaration" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.3.1 Embedding in Prolog Programs</h3>
<p>The CHR constraints defined in a particulary &lsquo;<tt>chr</tt>&rsquo; file are
associated with a module. The default module is <code>user</code>. One should
never load different &lsquo;<tt>chr</tt>&rsquo; files with the same CHR module name.
</p>
<hr>
<a name="Constraint-declaration"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Embedding-in-Prolog-Programs" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-in-YAP-Programs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Compilation" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.3.2 Constraint declaration</h3>
<p>Every constraint used in CHR rules has to be declared.
There are two ways to do this. The old style is as follows:
</p>
<div class="example">
<pre class="example">option(type_definition,type(list(T),[ [] , [T|list(T)] ]).
option(mode,foo(+,?)).
option(type_declaration,foo(list(int),float)).
:- constraints foo/2, bar/0.
</pre></div>
<p>The new style is as follows:
</p>
<div class="example">
<pre class="example">:- chr_type list(T) ---&gt; [] ; [T|list(T)].
:- constraints foo(+list(int),?float), bar.
</pre></div>
<hr>
<a name="Compilation"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Constraint-declaration" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-in-YAP-Programs" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Debugging" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.3.3 Compilation</h3>
<p>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 &lsquo;<tt>chr</tt>&rsquo;. They are activated if the compiled file
has the &lsquo;<tt>chr</tt>&rsquo; extension or after finding a declaration of the
format below.
</p>
<div class="example">
<pre class="example">:- constraints ...
</pre></div>
<p>It is adviced to define CHR rules in a module file, where the module
declaration is immediately followed by including the &lsquo;<tt>chr</tt>&rsquo;
library as examplified below:
</p>
<div class="example">
<pre class="example">:- module(zebra, [ zebra/0 ]).
:- use_module(library(chr)).
:- constraints ...
</pre></div>
<p>Using this style CHR rules can be defined in ordinary Prolog
&lsquo;<tt>pl</tt>&rsquo; files and the operator definitions required by CHR do not
leak into modules where they might cause conflicts.
</p>
<hr>
<a name="CHR-Debugging"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Compilation" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Ports" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Debugging-2"></a>
<h2 class="section">13.4 Debugging</h2>
<p>The CHR debugging facilities are currently rather limited. Only tracing
is currently available. To use the CHR debugging facilities for a CHR
file it must be compiled for debugging. Generating debug info is
controlled by the CHR option <code>debug</code>, whose default is derived
from the SWI-Prolog flag <code>generate_debug_info</code>. Therefore debug
info is provided unless the &lsquo;<samp>-nodebug</samp>&rsquo; is used.
</p>
<hr>
<a name="Ports"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Debugging" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Debugging" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Tracing" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.4.1 Ports</h3>
<p>For CHR constraints the four standard ports are defined:
</p>
<dl compact="compact">
<dt><code>call</code></dt>
<dd><p>A new constraint is called and becomes active.
</p></dd>
<dt><code>exit</code></dt>
<dd><p>An active constraint exits: it has either been inserted in the store after
trying all rules or has been removed from the constraint store.
</p></dd>
<dt><code>fail</code></dt>
<dd><p>An active constraint fails.
</p></dd>
<dt><code>redo</code></dt>
<dd><p>An active constraint starts looking for an alternative solution.
</p></dd>
</dl>
<p>In addition to the above ports, CHR constraints have five additional
ports:
</p>
<dl compact="compact">
<dt><code>wake</code></dt>
<dd><p>A suspended constraint is woken and becomes active.
</p></dd>
<dt><code>insert</code></dt>
<dd><p>An active constraint has tried all rules and is suspended in
the constraint store.
</p></dd>
<dt><code>remove</code></dt>
<dd><p>An active or passive constraint is removed from the constraint
store, if it had been inserted.
</p></dd>
<dt><code>try</code></dt>
<dd><p> An active constraints tries a rule with possibly
some passive constraints. The try port is entered
just before committing to the rule.
</p></dd>
<dt><code>apply</code></dt>
<dd><p> An active constraints commits to a rule with possibly
some passive constraints. The apply port is entered
just after committing to the rule.
</p></dd>
</dl>
<hr>
<a name="Tracing"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Ports" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Debugging" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Debugging-Predicates" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.4.2 Tracing</h3>
<p>Tracing is enabled with the chr_trace/0 predicate
and disabled with the chr_notrace/0 predicate.
</p>
<p>When enabled the tracer will step through the <code>call</code>,
<code>exit</code>, <code>fail</code>, <code>wake</code> and <code>apply</code> ports,
accepting debug commands, and simply write out the other ports.
</p>
<p>The following debug commans are currently supported:
</p>
<div class="example">
<pre class="example"> CHR debug options:
&lt;cr&gt; creep c creep
s skip
g ancestors
n nodebug
b break
a abort
f fail
? help h help
</pre></div>
<p>Their meaning is:
</p>
<dl compact="compact">
<dt><code>creep</code></dt>
<dd><p>Step to the next port.
</p></dd>
<dt><code>skip</code></dt>
<dd><p>Skip to exit port of this call or wake port.
</p></dd>
<dt><code>ancestors</code></dt>
<dd><p>Print list of ancestor call and wake ports.
</p></dd>
<dt><code>nodebug</code></dt>
<dd><p>Disable the tracer.
</p></dd>
<dt><code>break</code></dt>
<dd><p>Enter a recursive Prolog toplevel. See break/0.
</p></dd>
<dt><code>abort</code></dt>
<dd><p>Exit to the toplevel. See abort/0.
</p></dd>
<dt><code>fail</code></dt>
<dd><p>Insert failure in execution.
</p></dd>
<dt><code>help</code></dt>
<dd><p>Print the above available debug options.
</p></dd>
</dl>
<hr>
<a name="CHR-Debugging-Predicates"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tracing" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Debugging" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Examples" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">13.4.3 CHR Debugging Predicates</h3>
<p>The &lsquo;<tt>chr</tt>&rsquo; module contains several predicates that allow
inspecting and printing the content of the constraint store.
</p>
<dl compact="compact">
<dt><code>chr_trace/0</code></dt>
<dd><p>Activate the CHR tracer. By default the CHR tracer is activated and
deactivated automatically by the Prolog predicates trace/0 and
notrace/0.
</p>
</dd>
<dt><code>chr_notrace/0</code></dt>
<dd><p>De-activate the CHR tracer. By default the CHR tracer is activated and
deactivated automatically by the Prolog predicates trace/0 and
notrace/0.
</p>
</dd>
<dt><code>chr_leash/0</code></dt>
<dd>
<p>Define the set of CHR ports on which the CHR
tracer asks for user intervention (i.e. stops). <var>Spec</var> is either a
list of ports or a predefined &lsquo;alias&rsquo;. Defined aliases are:
<code>full</code> to stop at all ports, <code>none</code> or <code>off</code> to never
stop, and <code>default</code> to stop at the <code>call</code>, <code>exit</code>,
<code>fail</code>, <code>wake</code> and <code>apply</code> ports. See also leash/1.
</p>
</dd>
<dt><code>chr_show_store(+<var>Mod</var>)</code></dt>
<dd><p>Prints all suspended constraints of module <var>Mod</var> to the standard
output. This predicate is automatically called by the SWI-Prolog toplevel at
the end of each query for every CHR module currently loaded. The prolog-flag
<code>chr_toplevel_show_store</code> controls whether the toplevel shows the
constraint stores. The value <code>true</code> enables it. Any other value
disables it.
</p>
</dd>
</dl>
<hr>
<a name="CHR-Examples"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Debugging-Predicates" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Compatibility" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Examples"></a>
<h2 class="section">13.5 Examples</h2>
<p>Here are two example constraint solvers written in CHR.
</p>
<ul>
<li>
The program below defines a solver with one constraint,
<code>leq/2</code>, which is a less-than-or-equal constraint.
<div class="example">
<pre class="example">:- module(leq,[cycle/3, leq/2]).
:- use_module(library(chr)).
:- constraints leq/2.
reflexivity &nbsp;leq(X,X) &lt;=&gt; true.
antisymmetry &nbsp;leq(X,Y), leq(Y,X) &lt;=&gt; X = Y.
idempotence &nbsp;leq(X,Y) \ leq(X,Y) &lt;=&gt; true.
transitivity &nbsp;leq(X,Y), leq(Y,Z) ==&gt; leq(X,Z).
cycle(X,Y,Z):-
leq(X,Y),
leq(Y,Z),
leq(Z,X).
</pre></div>
</li><li>
The program below implements a simple finite domain
constraint solver.
<div class="example">
<pre class="example">:- module(dom,[dom/2]).
:- use_module(library(chr)).
:- constraints dom/2.
dom(X,[]) &lt;=&gt; fail.
dom(X,[Y]) &lt;=&gt; X = Y.
dom(X,L1), dom(X,L2) &lt;=&gt; intersection(L1,L2,L3), dom(X,L3).
intersection([],_,[]).
intersection([H|T],L2,[H|L3]) :-
member(H,L2), !,
intersection(T,L2,L3).
intersection([_|T],L2,L3) :-
intersection(T,L2,L3).
</pre></div>
</li></ul>
<hr>
<a name="CHR-Compatibility"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Examples" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Guidelines" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Compatibility-with-SICStus-CHR"></a>
<h2 class="section">13.6 Compatibility with SICStus CHR</h2>
<p>There are small differences between CHR in SWI-Prolog and newer
YAPs and SICStus and older versions of YAP. Besides differences in
available options and pragmas, the following differences should be
noted:
</p>
<dl compact="compact">
<dt><code>[The handler/1 declaration]</code></dt>
<dd><p>In SICStus every CHR module requires a <code>handler/1</code>
declaration declaring a unique handler name. This declaration is valid
syntax in SWI-Prolog, but will have no effect. A warning will be given
during compilation.
</p>
</dd>
<dt><code>[The rules/1 declaration]</code></dt>
<dd><p>In SICStus, for every CHR module it is possible to only enable a subset
of the available rules through the <code>rules/1</code> declaration. The
declaration is valid syntax in SWI-Prolog, but has no effect. A
warning is given during compilation.
</p>
</dd>
<dt><code>[Sourcefile naming]</code></dt>
<dd><p>SICStus uses a two-step compiler, where &lsquo;<tt>chr</tt>&rsquo; files are
first translated into &lsquo;<tt>pl</tt>&rsquo; files. For SWI-Prolog CHR
rules may be defined in a file with any extension.
</p></dd>
</dl>
<hr>
<a name="CHR-Guidelines"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Compatibility" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Guidelines"></a>
<h2 class="section">13.7 Guidelines</h2>
<p>In this section we cover several guidelines on how to use CHR to write
constraint solvers and how to do so efficiently.
</p>
<dl compact="compact">
<dt><code>[Set semantics]</code></dt>
<dd><p>The CHR system allows the presence of identical constraints, i.e.
multiple constraints with the same functor, arity and arguments. For
most constraint solvers, this is not desirable: it affects efficiency
and possibly termination. Hence appropriate simpagation rules should be
added of the form:
</p>
<div class="example">
<pre class="example">{constraint \ constraint &lt;=&gt; true}.
</pre></div>
</dd>
<dt><code>[Multi-headed rules]</code></dt>
<dd><p>Multi-headed rules are executed more efficiently when the constraints
share one or more variables.
</p>
</dd>
<dt><code>[Mode and type declarations]</code></dt>
<dd><p>Provide mode and type declarations to get more efficient program execution.
Make sure to disable debug (&lsquo;<samp>-nodebug</samp>&rsquo;) and enable optimization
(&lsquo;<samp>-O</samp>&rsquo;).
</p></dd>
</dl>
<hr>
<a name="Logtalk"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#CHR" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#CHR-Guidelines" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Logtalk-1"></a>
<h1 class="chapter">14 Logtalk</h1>
<a name="index-Logtalk"></a>
<p>The Logtalk object-oriented extension is available after running its
standalone installer by using the <code>yaplgt</code> command in POSIX
systems or by using the <code>Logtalk - YAP</code> shortcut in the Logtalk
program group in the Start Menu on Windows systems. For more information
please see the URL <a href="http://logtalk.org/">http://logtalk.org/</a>.
</p>
<hr>
<a name="MYDDAS"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Logtalk" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Logtalk" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Requirements-and-Installation-Guide" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="MYDDAS-1"></a>
<h1 class="chapter">15 MYDDAS</h1>
<a name="index-MYDDAS"></a>
<p>The MYDDAS database project was developed within a FCT project aiming at
the development of a highly efficient deductive database system, based
on the coupling of the MySQL relational database system with the Yap
Prolog system. MYDDAS was later expanded to support the ODBC interface.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">Subnodes of MYDDAS
</pre></th></tr><tr><td align="left" valign="top"><a href="#Requirements-and-Installation-Guide">15.1 Requirements and Installation Guide</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#MYDDAS-Architecture">15.2 MYDDAS Architecture</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Loading-MYDDAS">15.3 Loading MYDDAS</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Accessing-a-Relation">15.5 Accessing a Relation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#View-Level-Interface">15.6 View Level Interface</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Accessing-Tables-in-Data-Sources-Using-SQL">15.7 Accessing Tables in Data Sources Using SQL</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Types-of-Attributes">15.9 Types of Attributes</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Number-of-Fields">15.10 Number of Fields</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Enumerating-Relations">15.12 Enumeration Relations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-MYDDAS-MySQL-Top-Level">15.13 The MYDDAS MySQL Top Level</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Requirements-and-Installation-Guide"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS-Architecture" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Requirements-and-Installation-Guide-1"></a>
<h2 class="section">15.1 Requirements and Installation Guide</h2>
<p>Next, we describe how to usen of the YAP with the MYDDAS System. The
use of this system is entirely depend of the MySQL development libraries
or the ODBC development libraries. At least one of the this development
libraries must be installed on the computer system, otherwise MYDDAS
will not compile. The MySQL development libraries from MySQL 3.23 an
above are know to work. We recommend the usage of MySQL versusODBC,
but it is possible to have both options installed
</p>
<p>At the same time, without any problem. The MYDDAS system automatically
controls the two options. Currently, MYDDAS is know to compile without
problems in Linux. The usage of this system on Windows has not been
tested yet. MYDDAS must be enabled at configure time. This can be done
with the following options:
</p>
<dl compact="compact">
<dt><code>--enable-myddas</code></dt>
<dd><p> This option will detect which development libraries are installed on the computer system, MySQL, ODBC or both, and will compile the Yap system with the support for which libraries it detects;
</p></dd>
<dt><code>--enable-myddas-stats</code></dt>
<dd><p>This option is only available in MySQL. It includes code to get
statistics from the MYDDAS system;
</p></dd>
<dt><code>--enable-top-level</code></dt>
<dd><p>This option is only available in MySQL. It enables the option to interact with the MySQL server in
two different ways. As if we were on the MySQL Client Shell, and as if
we were using Datalog.
</p></dd>
</dl>
<hr>
<a name="MYDDAS-Architecture"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Requirements-and-Installation-Guide" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-MYDDAS" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="MYDDAS-Architecture-1"></a>
<h2 class="section">15.2 MYDDAS Architecture</h2>
<p>The system includes four main blocks that are put together through the
MYDDAS interface: the Yap Prolog compiler, the MySQL database system, an
ODBC layer and a Prolog to SQL compiler. Current effort is put on the
MySQL interface rather than on the ODBC interface. If you want to use
the full power of the MYDDAS interface we recommend you to use a MySQL
database. Other databases, such as Oracle, PostGres or Microsoft SQL
Server, can be interfaced through the ODBC layer, but with limited
performance and features support.
</p>
<p>The main structure of the MYDDAS interface is simple. Prolog queries
involving database goals are translated to SQL using the Prolog to SQL
compiler; then the SQL expression is sent to the database system, which
returns the set of tuples satisfying the query; and finally those tuples
are made available to the Prolog engine as terms. For recursive queries
involving database goals, the YapTab tabling engine provides the
necessary support for an efficient evaluation of such queries.
</p>
<p>An important aspect of the MYDDAS interface is that for the programmer
the use of predicates which are defined in database relations is
completely transparent. An example of this transparent support is the
Prolog cut operator, which has exactly the same behaviour from
predicates defined in the Prolog program source code, or from predicates
defined in database as relations.
</p>
<hr>
<a name="Loading-MYDDAS"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS-Architecture" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Connecting-to-and-disconnecting-from-a-Database-Server" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Loading-MYDDAS-1"></a>
<h2 class="section">15.3 Loading MYDDAS</h2>
<p>Begin by starting YAP and loading the library
<code>use_module(library(myddas))</code>. This library already includes the
Prolog to SQL Compiler described in [2] and [1]. In MYDDAS this compiler
has been extended to support further constructs which allow a more
efficient SQL translation.
</p>
<hr>
<a name="Connecting-to-and-disconnecting-from-a-Database-Server"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-MYDDAS" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Accessing-a-Relation" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Connecting-to-and-disconnecting-from-a-Database-Server-1"></a>
<h2 class="section">15.4 Connecting to and disconnecting from a Database Server</h2>
<dl compact="compact">
<dt><code>db open(+,+,+,+,+).</code></dt>
<dd><a name="index-db_005fopen_002f5"></a>
<a name="index-db_005fopen_002f5-1"></a>
<a name="index-db_005fopen_002f5-2"></a>
</dd>
<dt><code>db open(+,+,+,+).</code></dt>
<dd><a name="index-db_005fopen_002f4"></a>
<a name="index-db_005fopen_002f4-1"></a>
<a name="index-db_005fopen_002f4-2"></a>
</dd>
<dt><code>db close(+).</code></dt>
<dd><a name="index-db_005fclose_002f1"></a>
<a name="index-db_005fclose_002f1-1"></a>
<a name="index-db_005fclose_002f1-2"></a>
</dd>
<dt><code>db_close.</code></dt>
</dl>
<p> Assuming the MySQL server is running and we have an account, we can
login to MySQL by invoking <code>db_open/5</code> as one of the following:
</p><div class="example">
<pre class="example">?- db_open(mysql,Connection,Host/Database,User,Password).
?- db_open(mysql,Connection,Host/Database/Port,User,Password).
?- db_open(mysql,Connection,Host/Database/UnixSocket,User,Password).
?- db_open(mysql,Connection,Host/Database/Port/UnixSocket,User,Password).
</pre></div>
<p>If the login is successful, there will be a response of <code>yes</code>. For
instance:
</p><div class="example">
<pre class="example">?- db_open(mysql,con1,localhost/guest_db,guest,'').
</pre></div>
<p>uses the MySQL native interface, selected by the first argument, to open
a connection identified by the <code>con1</code> atom, to an instance of a
MySQL server running on host <code>localhost</code>, using database guest <code>db</code>
and user <code>guest</code> with empty <code>password</code>. To disconnect from the <code>con1</code>
connection we use:
</p><div class="example">
<pre class="example">?- db_close(con1).
</pre></div>
<p> Alternatively, we can use <code>db_open/4</code> and <code>db_close/0,</code> without an argument
to identify the connection. In this case the default connection is used,
with atom <code>myddas</code>. Thus using
</p><div class="example">
<pre class="example">?- db_open(mysql,localhost/guest_db,guest,'').
?- db_close.
</pre></div>
<p>or
</p><div class="example">
<pre class="example">?- db_open(mysql,myddas,localhost/guest_db,guest,'').
?- db_close(myddas).
</pre></div>
<p>is exactly the same.
</p>
<p>MYDDAS also supports ODBC. To connect to a database using an ODBC driver
you must have configured on your system a ODBC DSN. If so, the <code>db_open/4</code>
and <code>db_open/5</code> have the following mode:
</p><div class="example">
<pre class="example"> ?- db_open(odbc,Connection,ODBC_DSN,User,Password).
?- db_open(odbc,ODBC_DSN,User,Password).
</pre></div>
<p>For instance, if you do <code>db_open(odbc,odbc_dsn,guest,'')</code>. it will connect
to a database, through ODBC, using the definitions on the <code>odbc_dsn</code> DSN
configured on the system. The user will be the user <code>guest</code> with no
password.
</p>
<hr>
<a name="Accessing-a-Relation"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Connecting-to-and-disconnecting-from-a-Database-Server" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#View-Level-Interface" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Accessing-a-Relation-1"></a>
<h2 class="section">15.5 Accessing a Relation</h2>
<dl compact="compact">
<dt><code>db_import(+Conn,+RelationName,+PredName).</code></dt>
<dd><a name="index-db_005fimport_002f3"></a>
<a name="index-db_005fimport_002f3-1"></a>
<a name="index-db_005fimport_002f3-2"></a>
</dd>
<dt><code>db_import(+RelationName,+PredName).</code></dt>
<dd><a name="index-db_005fimport_002f2"></a>
<a name="index-db_005fimport_002f2-1"></a>
<a name="index-db_005fimport_002f2-2"></a>
</dd>
</dl>
<p>Assuming you have access permission for the relation you wish to import,
you can use <code>db_import/3</code> or <code>db_import/2</code> as:
</p><div class="example">
<pre class="example">?- db_import(Conn,RelationName,PredName).
?- db_import(RelationName,PredName).
</pre></div>
<p> where <var>RelationName</var>, is the name of
relation we wish to access, <var>PredName</var> is the name of the predicate we
wish to use to access the relation from YAP. <var>Conn</var>, is the connection
identifier, which again can be dropped so that the default myddas connection
is used. For instance, if we want to access the relation phonebook,
using the predicate <code>phonebook/3</code> we write:
</p><div class="example">
<pre class="example">?- db_import(con1,phonebook,phonebook).
yes
?- phonebook(Letter,Name,Number).
Letter = 'D',
Name = 'John Doe',
Number = 123456789 ?
yes
</pre></div>
<p>Backtracking can then be used to retrieve the next row
of the relation phonebook. Records with particular field values may be
selected in the same way as in Prolog. (In particular, no mode
specification for database predicates is required). For instance:
</p><div class="example">
<pre class="example">?- phonebook(Letter,'John Doe',Letter).
Letter = 'D',
Number = 123456789 ?
yes
</pre></div>
<p>generates the query </p><div class="example">
<pre class="example">SELECT A.Letter , 'John Doe' , A.Number
FROM 'phonebook' A
WHERE A.Name = 'John Doe';
</pre></div>
<hr>
<a name="View-Level-Interface"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Accessing-a-Relation" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Accessing-Tables-in-Data-Sources-Using-SQL" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="View-Level-Interface-1"></a>
<h2 class="section">15.6 View Level Interface</h2>
<dl compact="compact">
<dt><code>db view(+,+,+).</code></dt>
<dd><a name="index-db_005fview_002f3"></a>
<a name="index-db_005fview_002f3-1"></a>
<a name="index-db_005fview_002f3-2"></a>
</dd>
<dt><code>db view(+,+).</code></dt>
<dd><a name="index-db_005fview_002f2"></a>
<a name="index-db_005fview_002f2-1"></a>
<a name="index-db_005fview_002f2-2"></a>
</dd>
</dl>
<p>If we import a database relation, such as an edge relation representing the edges of a directed graph, through
</p><div class="example">
<pre class="example">?- db_import('Edge',edge).
yes
</pre></div>
<p>and we then write a query to retrieve all the direct cycles in the
graph, such as
</p><div class="example">
<pre class="example">?- edge(A,B), edge(B,A).
A = 10,
B = 20 ?
</pre></div>
<p>this is clearly inefficient [3], because of relation-level
access. Relation-level access means that a separate SQL query will be
generated for every goal in the body of the clause. For the second
<code>edge/2</code> goal, a SQL query is generated using the variable bindings that
result from the first <code>edge/2</code> goal execution. If the second
<code>edge/2</code> goal
fails, or if alternative solutions are demanded, backtracking access the
next tuple for the first <code>edge/2</code> goal and another SQL query will be
generated for the second <code>edge/2</code> goal. The generation of this large
number of queries and the communication overhead with the database
system for each of them, makes the relation-level approach inefficient.
To solve this problem the view level interface can be used for the
definition of rules whose bodies includes only imported database
predicates. One can use the view level interface through the predicates
<code>db_view/3</code> and <code>db_view/2</code>:
</p><div class="example">
<pre class="example">?- db_view(Conn,PredName(Arg_1,...,Arg_n),DbGoal).
?- db_view(PredName(Arg_1,...,Arg_n),DbGoal).
</pre></div>
<p> All arguments are standard Prolog terms. <var>Arg1</var> through <var>Argn</var>
define the attributes to be retrieved from the database, while
<var>DbGoal</var> defines the selection restrictions and join
conditions. <var>Conn</var> is the connection identifier, which again can be
dropped. Calling predicate <code>PredName/n</code> will retrieve database
tuples using a single SQL query generated for the <var>DbGoal</var>. We next show
an example of a view definition for the direct cycles discussed
above. Assuming the declaration:
</p><div class="example">
<pre class="example">?- db_import('Edge',edge).
yes
</pre></div>
<p>we
write:</p><div class="example">
<pre class="example">?- db_view(direct_cycle(A,B),(edge(A,B), edge(B,A))).
yes
?- direct_cycle(A,B)).
A = 10,
B = 20 ?
</pre></div>
<p>This call generates the SQL
statement: </p><div class="example">
<pre class="example">SELECT A.attr1 , A.attr2
FROM Edge A , Edge B
WHERE B.attr1 = A.attr2 AND B.attr2 = A.attr1;
</pre></div>
<p>Backtracking, as in relational level interface, can be used to retrieve the next row of the view.
The view interface also supports aggregate function predicates such as
<code>sum</code>, <code>avg</code>, <code>count</code>, <code>min</code> and <code>max</code>. For
instance:
</p><div class="example">
<pre class="example">?- db_view(count(X),(X is count(B, B^edge(10,B)))).
</pre></div>
<p>generates the query :
</p><div class="example">
<pre class="example">SELECT COUNT(A.attr2)
FROM Edge A WHERE A.attr1 = 10;
</pre></div>
<p>To know how to use db <code>view/3</code>, please refer to Draxler&rsquo;s Prolog to
SQL Compiler Manual.
</p>
<hr>
<a name="Accessing-Tables-in-Data-Sources-Using-SQL"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#View-Level-Interface" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Insertion-of-Rows" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Accessing-Tables-in-Data-Sources-Using-SQL-1"></a>
<h2 class="section">15.7 Accessing Tables in Data Sources Using SQL</h2>
<dl compact="compact">
<dt><code>db_sql(+,+,?).</code></dt>
<dd><a name="index-db_005fsql_002f3"></a>
<a name="index-db_005fsql_002f3-1"></a>
<a name="index-db_005fsql_002f3-2"></a>
</dd>
<dt><code>db_sql(+,?).</code></dt>
<dd><a name="index-db_005fsql_002f2"></a>
<a name="index-db_005fsql_002f2-1"></a>
<a name="index-db_005fsql_002f2-2"></a>
</dd>
</dl>
<p>It is also possible to explicitly send a SQL query to the database server using
</p><div class="example">
<pre class="example">?- db_sql(Conn,SQL,List).
?- db_sql(SQL,List).
</pre></div>
<p>where <var>SQL</var> is an arbitrary SQL expression, and <var>List</var> is a list
holding the first tuple of result set returned by the server. The result
set can also be navigated through backtracking.
</p>
<p>Example:
</p><div class="example">
<pre class="example">?- db_sql('SELECT * FROM phonebook',LA).
LA = ['D','John Doe',123456789] ?
</pre></div>
<hr>
<a name="Insertion-of-Rows"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Accessing-Tables-in-Data-Sources-Using-SQL" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Types-of-Attributes" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Insertion-of-Rows-1"></a>
<h2 class="section">15.8 Insertion of Rows</h2>
<dl compact="compact">
<dt><code>db_assert(+,+).</code></dt>
<dd><a name="index-db_005fassert_002f2"></a>
<a name="index-db_005fassert_002f2-1"></a>
<a name="index-db_005fassert_002f2-2"></a>
</dd>
<dt><code>db_assert(+).</code></dt>
<dd><a name="index-db_005fassert_002f1"></a>
<a name="index-db_005fassert_002f1-1"></a>
<a name="index-db_005fassert_002f1-2"></a>
</dd>
</dl>
<p>Assuming you have imported the related base table using
<code>db_import/2</code> or <code>db_import/3</code>, you can insert to that table
by using <code>db_assert/2</code> predicate any given fact.
</p><div class="example">
<pre class="example">?- db_assert(Conn,Fact).
?- db_assert(Fact).
</pre></div>
<p>The second argument must be declared with all of its arguments bound to
constants. For example assuming <code>helloWorld</code> is imported through
<code>db_import/2</code>:
</p><div class="example">
<pre class="example">?- db_import('Hello World',helloWorld).
yes
?- db_assert(helloWorld('A' ,'Ana',31)).
yes
</pre></div>
<p>This, would generate the following query
</p><div class="example">
<pre class="example">INSERT INTO helloWorld
VALUES ('A','Ana',3)
</pre></div>
<p>which would insert into the helloWorld, the following row:
<code>A,Ana,31</code>. If we want to insert <code>NULL</code> values into the
relation, we call <code>db_assert/2</code> with a uninstantiated variable in
the data base imported predicate. For example, the following query on
the YAP-prolog system:
</p>
<div class="example">
<pre class="example">?- db_assert(helloWorld('A',NULL,31)).
yes
</pre></div>
<p>Would insert the row: <code>A,null value,31</code> into the relation
<code>Hello World</code>, assuming that the second row allows null values.
</p>
<dl compact="compact">
<dt><code>db insert(+,+,+).</code></dt>
<dd><a name="index-db_005finsert_002f3"></a>
<a name="index-db_005finsert_002f3-1"></a>
<a name="index-db_005finsert_002f3-2"></a>
</dd>
<dt><code>db insert(+,+).</code></dt>
<dd><a name="index-db_005finsert_002f2"></a>
<a name="index-db_005finsert_002f2-1"></a>
<a name="index-db_005finsert_002f2-2"></a>
</dd>
</dl>
<p>This predicate would create a new database predicate, which will insert
any given tuple into the database.
</p><div class="example">
<pre class="example">?- db_insert(Conn,RelationName,PredName).
?- db_insert(RelationName,PredName).
</pre></div>
<p>This would create a new predicate with name <var>PredName</var>, that will
insert tuples into the relation <var>RelationName</var>. is the connection
identifier. For example, if we wanted to insert the new tuple
<code>('A',null,31)</code> into the relation <code>Hello World</code>, we do:
</p><div class="example">
<pre class="example">?- db_insert('Hello World',helloWorldInsert).
yes
?- helloWorldInsert('A',NULL,31).
yes
</pre></div>
<hr>
<a name="Types-of-Attributes"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Insertion-of-Rows" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Number-of-Fields" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Types-of-Attributes-1"></a>
<h2 class="section">15.9 Types of Attributes</h2>
<dl compact="compact">
<dt><code>db_get_attributes_types(+,+,?).</code></dt>
<dd><a name="index-db_005fget_005fattributes_005ftypes_002f3"></a>
<a name="index-db_005fget_005fattributes_005ftypes_002f3-1"></a>
<a name="index-db_005fget_005fattributes_005ftypes_002f3-2"></a>
</dd>
<dt><code>db_get_attributes_types(+,?).</code></dt>
<dd><a name="index-db_005fget_005fattributes_005ftypes_002f2"></a>
<a name="index-db_005fget_005fattributes_005ftypes_002f2-1"></a>
<a name="index-db_005fget_005fattributes_005ftypes_002f2-2"></a>
</dd>
</dl>
<p>The prototype for this predicate is the following:
</p><div class="example">
<pre class="example">?- db_get_attributes_types(Conn,RelationName,ListOfFields).
?- db_get_attributes_types(RelationName,ListOfFields).
</pre></div>
<p>You can use the
predicate <code>db_get_attributes types/2</code> or <code>db_get_attributes_types/3</code>, to
know what are the names and attributes types of the fields of a given
relation. For example:
</p><div class="example">
<pre class="example">?- db_get_attributes_types(myddas,'Hello World',LA).
LA = ['Number',integer,'Name',string,'Letter',string] ?
yes
</pre></div>
<p>where <tt>Hello World</tt> is the name of the relation and <tt>myddas</tt> is the
connection identifier.
</p>
<hr>
<a name="Number-of-Fields"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Types-of-Attributes" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Describing-a-Relation" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Number-of-Fields-1"></a>
<h2 class="section">15.10 Number of Fields</h2>
<dl compact="compact">
<dt><code>db_number_of_fields(+,?).</code></dt>
<dd><a name="index-db_005fnumber_005fof_005ffields_002f2"></a>
<a name="index-db_005fnumber_005fof_005ffields_002f2-1"></a>
<a name="index-db_005fnumber_005fof_005ffields_002f2-2"></a>
</dd>
<dt><code>db_number_of_fields(+,+,?).</code></dt>
<dd><a name="index-db_005fnumber_005fof_005ffields_002f3"></a>
<a name="index-db_005fnumber_005fof_005ffields_002f3-1"></a>
<a name="index-db_005fnumber_005fof_005ffields_002f3-2"></a>
</dd>
</dl>
<p>The prototype for this
predicate is the following:
</p><div class="example">
<pre class="example"> ?- db_number_of_fields(Conn,RelationName,Arity).
?- db_number_of_fields(RelationName,Arity).
</pre></div>
<p>You can use the predicate <code>db_number_of_fields/2</code> or
<code>db_number_of_fields/3</code> to know what is the arity of a given
relation. Example:
</p><div class="example">
<pre class="example">?- db_number_of_fields(myddas,'Hello World',Arity).
Arity = 3 ?
yes
</pre></div>
<p>where <code>Hello World</code> is the name of the
relation and <code>myddas</code> is the connection identifier.
</p>
<hr>
<a name="Describing-a-Relation"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Number-of-Fields" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Enumerating-Relations" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Describing-a-Relation-1"></a>
<h2 class="section">15.11 Describing a Relation</h2>
<dl compact="compact">
<dt><code>db_datalog_describe(+,+).</code></dt>
<dd><a name="index-db_005fdatalog_005fdescribe_002f2"></a>
<a name="index-db_005fdatalog_005fdescribe_002f2-1"></a>
<a name="index-db_005fdatalog_005fdescribe_002f2-2"></a>
</dd>
<dt><code>db_datalog_describe(+).</code></dt>
<dd><a name="index-db_005fdatalog_005fdescribe_002f1"></a>
<a name="index-db_005fdatalog_005fdescribe_002f1-1"></a>
<a name="index-db_005fdatalog_005fdescribe_002f1-2"></a>
</dd>
</dl>
<p>The db <code>datalog_describe/2</code> predicate does not really returns any
value. It simply prints to the screen the result of the MySQL describe
command, the same way as <code>DESCRIBE</code> in the MySQL prompt would.
</p><div class="example">
<pre class="example">?- db_datalog_describe(myddas,'Hello World').
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
+ Number | int(11) | YES | | NULL | |
+ Name | char(10) | YES | | NULL | |
+ Letter | char(1) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
yes
</pre></div>
<dl compact="compact">
<dt><code>db_describe(+,+).</code></dt>
<dd><a name="index-db_005fdescribe_002f2"></a>
<a name="index-db_005fdescribe_002f2-1"></a>
<a name="index-db_005fdescribe_002f2-2"></a>
</dd>
<dt><code>db_describe(+).</code></dt>
<dd><a name="index-db_005fdescribe_002f1"></a>
<a name="index-db_005fdescribe_002f1-1"></a>
<a name="index-db_005fdescribe_002f1-2"></a>
</dd>
</dl>
<p>The <code>db_describe/3</code> predicate does the same action as
<code>db_datalog_describe/2</code> predicate but with one major
difference. The results are returned by backtracking. For example, the
last query:
</p><div class="example">
<pre class="example"> ?- db_describe(myddas,'Hello World',Term).
Term = tableInfo('Number',int(11),'YES','',null(0),'') ? ;
Term = tableInfo('Name',char(10),'YES','',null(1),'' ? ;
Term = tableInfo('Letter',char(1),'YES','',null(2),'') ? ;
no
</pre></div>
<hr>
<a name="Enumerating-Relations"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Describing-a-Relation" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-MYDDAS-MySQL-Top-Level" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Enumeration-Relations"></a>
<h2 class="section">15.12 Enumeration Relations</h2>
<dl compact="compact">
<dt><code>db_datalog_show_tables(+).</code></dt>
<dt><code>db_datalog_show_tables</code></dt>
</dl>
<p>If we need to know what relations exists in a given MySQL Schema, we can use
the <code>db_datalog_show_tables/1</code> predicate. As <tt>db_datalog_describe/2</tt>,
it does not returns any value, but instead prints to the screen the result of the
<code>SHOW TABLES</code> command, the same way as it would be in the MySQL prompt.
</p><div class="example">
<pre class="example">?- db_datalog_show_tables(myddas).
+-----------------+
| Tables_in_guest |
+-----------------+
| Hello World |
+-----------------+
yes
</pre></div>
<dl compact="compact">
<dt><code>db_show_tables(+, ?).</code></dt>
<dd><a name="index-db_005fshow_005ftables_002f2"></a>
<a name="index-db_005fshow_005ftables_002f2-1"></a>
<a name="index-db_005fshow_005ftables_002f2-2"></a>
</dd>
<dt><code>db_show_tables(?)</code></dt>
<dd><a name="index-db_005fshow_005ftables_002f1"></a>
<a name="index-db_005fshow_005ftables_002f1-1"></a>
<a name="index-db_005fshow_005ftables_002f1-2"></a>
</dd>
</dl>
<p>The <code>db_show_tables/2</code> predicate does the same action as
<code>db_show_tables/1</code> predicate but with one major difference. The
results are returned by backtracking. For example, given the last query:
</p><div class="example">
<pre class="example">?- db_show_tables(myddas,Table).
Table = table('Hello World') ? ;
no
</pre></div>
<hr>
<a name="The-MYDDAS-MySQL-Top-Level"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Enumerating-Relations" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Other-MYDDAS-Properties" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="The-MYDDAS-MySQL-Top-Level-1"></a>
<h2 class="section">15.13 The MYDDAS MySQL Top Level</h2>
<dl compact="compact">
<dt><code>db_top_level(+,+,+,+,+).</code></dt>
<dd><a name="index-db_005ftop_005flevel_002f5"></a>
<a name="index-db_005ftop_005flevel_002f5-1"></a>
<a name="index-db_005ftop_005flevel_002f5-2"></a>
</dd>
<dt><code>db_top_level(+,+,+,+).</code></dt>
<dd><a name="index-db_005ftop_005flevel_002f4"></a>
<a name="index-db_005ftop_005flevel_002f4-1"></a>
<a name="index-db_005ftop_005flevel_002f4-2"></a>
</dd>
</dl>
<p>Through MYDDAS is also possible to access the MySQL Database Server, in
the same wthe mysql client. In this mode, is possible to query the
SQL server by just using the standard SQL language. This mode is exactly the same as
different from the standard mysql client. We can use this
mode, by invoking the db top level/5. as one of the following:
</p><div class="example">
<pre class="example">?- db_top_level(mysql,Connection,Host/Database,User,Password).
?- db_top_level(mysql,Connection,Host/Database/Port,User,Password).
?- db_top_level(mysql,Connection,Host/Database/UnixSocket,User,Password).
?- db_top_level(mysql,Connection,Host/Database/Port/UnixSocket,User,Password).
</pre></div>
<p>Usage is similar as the one described for the <code>db_open/5</code> predicate
discussed above. If the login is successful, automatically the prompt of
the mysql client will be used. For example:
</p><div class="example">
<pre class="example"> ?- db_top_level(mysql,con1,localhost/guest_db,guest,'').
</pre></div>
<p>opens a
connection identified by the <code>con1</code> atom, to an instance of a MySQL server
running on host <code>localhost</code>, using database guest <code>db</code> and user <code>guest</code> with
empty password. After this is possible to use MYDDAS as the mysql
client.
</p><div class="example">
<pre class="example"> ?- db_top_level(mysql,con1,localhost/guest_db,guest,'').
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 4468 to server version: 4.0.20
Type 'help;' or '\h' for help.
Type '\c' to clear the buffer.
mysql&gt; exit
Bye
yes
?-
</pre></div>
<hr>
<a name="Other-MYDDAS-Properties"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-MYDDAS-MySQL-Top-Level" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#MYDDAS" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Other-MYDDAS-Properties-1"></a>
<h2 class="section">15.14 Other MYDDAS Properties</h2>
<dl compact="compact">
<dt><code>db_verbose(+).</code></dt>
<dt><code>db_top_level(+,+,+,+).</code></dt>
</dl>
<p>When we ask a question to YAP, using a predicate asserted by
<code>db_import/3</code>, or by <code>db_view/3</code>, this will generate a SQL
<code>QUERY</code>. If we want to see that query, we must to this at a given
point in our session on YAP.
</p><div class="example">
<pre class="example">?- db_verbose(1).
yes
?-
</pre></div>
<p>If we want to
disable this feature, we must call the <code>db_verbose/1</code> predicate with the value 0.
</p>
<dl compact="compact">
<dt><code>db_module(?).</code></dt>
<dd><a name="index-db_005fmodule_002f1"></a>
<a name="index-db_005fmodule_002f1-1"></a>
<a name="index-db_005fmodule_002f1-2"></a>
</dd>
</dl>
<p>When we create a new database predicate, by using <code>db_import/3</code>,
<code>db_view/3</code> or <code>db_insert/3</code>, that predicate will be asserted
by default on the <code>user</code> module. If we want to change this value, we can
use the <code>db_module/1</code> predicate to do so.
</p><div class="example">
<pre class="example">?- db_module(lists).
yes
?-
</pre></div>
<p>By executing this predicate, all of the predicates asserted by the
predicates enumerated earlier will created in the lists module.
If we want to put back the value on default, we can manually put the
value user. Example:
</p><div class="example">
<pre class="example">?- db_module(user).
yes
?-
</pre></div>
<p>We can also see in what module the predicates are being asserted by doing:
</p><div class="example">
<pre class="example">?- db_module(X).
X=user
yes
?-
</pre></div>
<dl compact="compact">
<dt><code>db_my_result_set(?).</code></dt>
<dd><a name="index-db_005fmy_005fresult_005fset_002f1"></a>
<a name="index-db_005fmy_005fresult_005fset_002f1-1"></a>
<a name="index-db_005fmy_005fresult_005fset_002f1-2"></a>
</dd>
</dl>
<p>The MySQL C API permits two modes for transferring the data generated by
a query to the client, in our case YAP. The first mode, and the default
mode used by the MYDDAS-MySQL, is to store the result. This mode copies all the
information generated to the client side.</p><div class="example">
<pre class="example">?- db_my_result_set(X).
X=store_result
yes
</pre></div>
<p>The other mode that we can use is use result. This one uses the result
set created directly from the server. If we want to use this mode, he
simply do
</p><div class="example">
<pre class="example"> ?- db_my_result_set(use_result).
yes
</pre></div>
<p>After this command, all
of the database predicates will use use result by default. We can change
this by doing again <code>db_my_result_set(store_result)</code>.
</p>
<dl compact="compact">
<dt><code>db_my_sql_mode(+Conn,?SQL_Mode).</code></dt>
<dd><a name="index-db_005fmy_005fsql_005fmode_002f2"></a>
<a name="index-db_005fmy_005fsql_005fmode_002f2-1"></a>
<a name="index-db_005fmy_005fsql_005fmode_002f2-2"></a>
</dd>
<dt><code>db_my_sql_mode(?SQL_Mode).</code></dt>
<dd><a name="index-db_005fmy_005fsql_005fmode_002f1"></a>
<a name="index-db_005fmy_005fsql_005fmode_002f1-1"></a>
<a name="index-db_005fmy_005fsql_005fmode_002f1-2"></a>
</dd>
</dl>
<p>The MySQL server allows the user to change the SQL mode. This can be
very useful for debugging proposes. For example, if we want MySQL server
not to ignore the INSERT statement warnings and instead of taking
action, report an error, we could use the following SQL mode.
</p><div class="example">
<pre class="example"> ?-db_my_sql_mode(traditional). yes
</pre></div>
<p>You can see the available SQL Modes at the MySQL homepage at
<a href="http://www.mysql.org">http://www.mysql.org</a>.
</p>
<hr>
<a name="Threads"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#MYDDAS" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Other-MYDDAS-Properties" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Creating-and-Destroying-Prolog-Threads" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parallelism" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Threads-1"></a>
<h1 class="chapter">16 Threads</h1>
<p>YAP implements a SWI-Prolog compatible multithreading
library. Like in SWI-Prolog, Prolog threads have their own stacks and
only share the Prolog <em>heap</em>: 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.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">Subnodes of Threads
</pre></th></tr><tr><td align="left" valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Thread-Communication">16.3 Thread communication</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">
Subnodes of Thread Communication
</pre></th></tr><tr><td align="left" valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Signalling-Threads">16.3.2 Signalling Threads</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Threads-and-Dynamic-Predicates">16.3.3 Threads and Dynamic Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Creating-and-Destroying-Prolog-Threads"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Threads" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Monitoring-Threads" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parallelism" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Creating-and-Destroying-Prolog-Threads-1"></a>
<h2 class="section">16.1 Creating and Destroying Prolog Threads</h2>
<dl compact="compact">
<dt><code>thread_create(:<var>Goal</var>, -<var>Id</var>, +<var>Options</var>)</code></dt>
<dd><a name="index-thread_005fcreate_002f3"></a>
<a name="index-thread_005fcreate_002f3-1"></a>
<a name="index-thread_005fcreate_002f3-2"></a>
<p>Create a new Prolog thread (and underlying C-thread) and start it
by executing <var>Goal</var>. If the thread is created successfully, the
thread-identifier of the created thread is unified to <var>Id</var>.
<var>Options</var> is a list of options. Currently defined options are:
</p>
<dl compact="compact">
<dt><code>stack</code></dt>
<dd><p>Set the limit in K-Bytes to which the Prolog stacks of
this thread may grow. If omitted, the limit of the calling thread is
used. See also the commandline <code>-S</code> option.
</p>
</dd>
<dt><code>trail</code></dt>
<dd><p>Set the limit in K-Bytes to which the trail stack of this thread may
grow. If omitted, the limit of the calling thread is used. See also the
commandline option <code>-T</code>.
</p>
</dd>
<dt><code>alias</code></dt>
<dd><p>Associate an alias-name with the thread. This named may be used to
refer to the thread and remains valid until the thread is joined
(see <code>thread_join/2</code>).
</p>
</dd>
<dt><code>at_exit</code></dt>
<dd><p>Define an exit hook for the thread. This hook is called when the thread
terminates, no matter its exit status.
</p>
</dd>
<dt><code>detached</code></dt>
<dd><p>If <code>false</code> (default), the thread can be waited for using
<code>thread_join/2</code>. <code>thread_join/2</code> must be called on this thread
to reclaim the all resources associated to the thread. If <code>true</code>,
the system will reclaim all associated resources automatically after the
thread finishes. Please note that thread identifiers are freed for reuse
after a detached thread finishes or a normal thread has been joined.
See also <code>thread_join/2</code> and <code>thread_detach/1</code>.
</p></dd>
</dl>
<p>The <var>Goal</var> argument is <em>copied</em> to the new Prolog engine.
This implies further instantiation of this term in either thread does
not have consequences for the other thread: Prolog threads do not share
data from their stacks.
</p>
</dd>
<dt><code>thread_create(:<var>Goal</var>, -<var>Id</var>)</code></dt>
<dd><a name="index-thread_005fcreate_002f2"></a>
<a name="index-thread_005fcreate_002f2-1"></a>
<a name="index-thread_005fcreate_002f2-2"></a>
<p>Create a new Prolog thread using default options. See <code>thread_create/3</code>.
</p>
</dd>
<dt><code>thread_create(:<var>Goal</var>)</code></dt>
<dd><a name="index-thread_005fcreate_002f1"></a>
<a name="index-thread_005fcreate_002f1-1"></a>
<a name="index-thread_005fcreate_002f1-2"></a>
<p>Create a new Prolog detached thread using default options. See <code>thread_create/3</code>.
</p>
</dd>
<dt><code>thread_self(-<var>Id</var>)</code></dt>
<dd><a name="index-thread_005fself_002f1"></a>
<a name="index-thread_005fself_002f1-1"></a>
<a name="index-thread_005fself_002f1-2"></a>
<p>Get the Prolog thread identifier of the running thread. If the thread
has an alias, the alias-name is returned.
</p>
</dd>
<dt><code>thread_join(+<var>Id</var>, -<var>Status</var>)</code></dt>
<dd><a name="index-thread_005fjoin_002f2"></a>
<a name="index-thread_005fjoin_002f2-1"></a>
<a name="index-thread_005fjoin_002f2-2"></a>
<p>Wait for the termination of thread with given <var>Id</var>. Then unify the
result-status of the thread with <var>Status</var>. After this call,
<var>Id</var> becomes invalid and all resources associated with the thread
are reclaimed. Note that threads with the attribute <code>detached</code>
<code>true</code> cannot be joined. See also <code>current_thread/2</code>.
</p>
<p>A thread that has been completed without <code>thread_join/2</code> being
called on it is partly reclaimed: the Prolog stacks are released and the
C-thread is destroyed. A small data-structure representing the
exit-status of the thread is retained until <code>thread_join/2</code> is called on
the thread. Defined values for <var>Status</var> are:
</p>
<dl compact="compact">
<dt><code>true</code></dt>
<dd><p>The goal has been proven successfully.
</p>
</dd>
<dt><code>false</code></dt>
<dd><p>The goal has failed.
</p>
</dd>
<dt><code>exception(<var>Term</var>)</code></dt>
<dd><p> The thread is terminated on an
exception. See <code>print_message/2</code> to turn system exceptions into
readable messages.
</p>
</dd>
<dt><code>exited(<var>Term</var>)</code></dt>
<dd><p>The thread is terminated on <code>thread_exit/1</code> using the argument <var>Term</var>.
</p></dd>
</dl>
</dd>
<dt><code>thread_detach(+<var>Id</var>)</code></dt>
<dd><a name="index-thread_005fdetach_002f1"></a>
<a name="index-thread_005fdetach_002f1-1"></a>
<a name="index-thread_005fdetach_002f1-2"></a>
<p>Switch thread into detached-state (see <code>detached</code> option at
<code>thread_create/3</code> at runtime. <var>Id</var> is the identifier of the thread
placed in detached state.
</p>
<p>One of the possible applications is to simplify debugging. Threads that
are created as <code>detached</code> leave no traces if they crash. For
not-detached threads the status can be inspected using
<code>current_thread/2</code>. Threads nobody is waiting for may be created
normally and detach themselves just before completion. This way they
leave no traces on normal completion and their reason for failure can be
inspected.
</p>
</dd>
<dt><code>thread_yield</code></dt>
<dd><a name="index-thread_005fyield_002f0"></a>
<a name="index-thread_005fyield_002f0-1"></a>
<a name="index-thread_005fyield_002f0-2"></a>
<p>Voluntarily relinquish the processor.
</p>
</dd>
<dt><code>thread_exit(+<var>Term</var>)</code></dt>
<dd><a name="index-thread_005fexit_002f1"></a>
<a name="index-thread_005fexit_002f1-1"></a>
<a name="index-thread_005fexit_002f1-2"></a>
<p>Terminates the thread immediately, leaving <code>exited(<var>Term</var>)</code> as
result-state for <code>thread_join/2</code>. If the thread has the attribute
<code>detached</code> <code>true</code> it terminates, but its exit status cannot be
retrieved using <code>thread_join/2</code> making the value of <var>Term</var>
irrelevant. The Prolog stacks and C-thread are reclaimed.
</p>
</dd>
<dt><code>thread_at_exit(:<var>Term</var>)</code></dt>
<dd><a name="index-thread_005fat_005fexit_002f1"></a>
<a name="index-thread_005fat_005fexit_002f1-1"></a>
<a name="index-thread_005fat_005fexit_002f1-2"></a>
<p>Run <var>Goal</var> just before releasing the thread resources. This is to
be compared to <code>at_halt/1</code>, but only for the current
thread. These hooks are ran regardless of why the execution of the
thread has been completed. As these hooks are run, the return-code is
already available through <code>thread_property/2</code> using the result of
<code>thread_self/1</code> as thread-identifier. If you want to guarantee the
execution of an exit hook no matter how the thread terminates (the thread
can be aborted before reaching the <code>thread_at_exit/1</code> call), consider
using instead the <code>at_exit/1</code> option of <code>thread_create/3</code>.
</p>
</dd>
<dt><code>thread_setconcurrency(+<var>Old</var>, -<var>New</var>)</code></dt>
<dd><a name="index-thread_005fsetconcurrency_002f2"></a>
<a name="index-thread_005fsetconcurrency_002f2-1"></a>
<a name="index-thread_005fsetconcurrency_002f2-2"></a>
<p>Determine the concurrency of the process, which is defined as the
maximum number of concurrently active threads. &lsquo;Active&rsquo; here means
they are using CPU time. This option is provided if the
thread-implementation provides
<code>pthread_setconcurrency()</code>. Solaris is a typical example of this
family. On other systems this predicate unifies <var>Old</var> to 0 (zero)
and succeeds silently.
</p>
</dd>
<dt><code>thread_sleep(+<var>Time</var>)</code></dt>
<dd><a name="index-thread_005fsleep_002f1"></a>
<a name="index-thread_005fsleep_002f1-1"></a>
<a name="index-thread_005fsleep_002f1-2"></a>
<p>Make current thread sleep for <var>Time</var> seconds. <var>Time</var> may be an
integer or a floating point number. When time is zero or a negative value
the call succeeds and returns immediately. This call should not be used if
alarms are also being used.
</p></dd>
</dl>
<hr>
<a name="Monitoring-Threads"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Threads" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Creating-and-Destroying-Prolog-Threads" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Thread-Communication" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parallelism" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Monitoring-Threads-1"></a>
<h2 class="section">16.2 Monitoring Threads</h2>
<p>Normal multi-threaded applications should not need these the predicates
from this section because almost any usage of these predicates is
unsafe. For example checking the existence of a thread before signalling
it is of no use as it may vanish between the two calls. Catching
exceptions using <code>catch/3</code> is the only safe way to deal with
thread-existence errors.
</p>
<p>These predicates are provided for diagnosis and monitoring tasks.
</p>
<dl compact="compact">
<dt><code>thread_property(?<var>Id</var>, ?<var>Property</var>)</code></dt>
<dd><a name="index-thread_005fproperty_002f2"></a>
<a name="index-thread_005fproperty_002f2-1"></a>
<a name="index-thread_005fproperty_002f2-2"></a>
<p>Enumerates the properties of the specified thread.
Calling <code>thread_property/2</code> does not influence any thread. See also
<code>thread_join/2</code>. For threads that have an alias-name, this name can
be used in <var>Id</var> instead of the numerical thread identifier.
<var>Property</var> is one of:
</p>
<dl compact="compact">
<dt><code>status(<var>Status</var>)</code></dt>
<dd><p>The thread status of a thread (see below).
</p>
</dd>
<dt><code>alias(<var>Alias</var>)</code></dt>
<dd><p>The thread alias, if it exists.
</p>
</dd>
<dt><code>at_exit(<var>AtExit</var>)</code></dt>
<dd><p>The thread exit hook, if defined (not available if the thread is already terminated).
</p>
</dd>
<dt><code>detached(<var>Boolean</var>)</code></dt>
<dd><p>The detached state of the thread.
</p>
</dd>
<dt><code>stack(<var>Size</var>)</code></dt>
<dd><p>The thread stack data-area size.
</p>
</dd>
<dt><code>trail(<var>Size</var>)</code></dt>
<dd><p>The thread trail data-area size.
</p>
</dd>
<dt><code>system(<var>Size</var>)</code></dt>
<dd><p>The thread system data-area size.
</p></dd>
</dl>
</dd>
<dt><code>current_thread(+<var>Id</var>, -<var>Status</var>)</code></dt>
<dd><a name="index-current_005fthread_002f2"></a>
<a name="index-current_005fthread_002f2-1"></a>
<a name="index-current_005fthread_002f2-2"></a>
<p>Enumerates identifiers and status of all currently known threads.
Calling <code>current_thread/2</code> does not influence any thread. See also
<code>thread_join/2</code>. For threads that have an alias-name, this name is
returned in <var>Id</var> instead of the numerical thread identifier.
<var>Status</var> is one of:
</p>
<dl compact="compact">
<dt><code>running</code></dt>
<dd><p>The thread is running. This is the initial status of a thread. Please
note that threads waiting for something are considered running too.
</p>
</dd>
<dt><code>false</code></dt>
<dd><p>The <var>Goal</var> of the thread has been completed and failed.
</p>
</dd>
<dt><code>true</code></dt>
<dd><p>The <var>Goal</var> of the thread has been completed and succeeded.
</p>
</dd>
<dt><code>exited(<var>Term</var>)</code></dt>
<dd><p>The <var>Goal</var> of the thread has been terminated using <code>thread_exit/1</code>
with <var>Term</var> as argument. If the underlying native thread has
exited (using pthread_exit()) <var>Term</var> is unbound.
</p>
</dd>
<dt><code>exception(<var>Term</var>)</code></dt>
<dd><p>The <var>Goal</var> of the thread has been terminated due to an uncaught
exception (see <code>throw/1</code> and <code>catch/3</code>).
</p></dd>
</dl>
</dd>
<dt><code>thread_statistics(+<var>Id</var>, +<var>Key</var>, -<var>Value</var>)</code></dt>
<dd><a name="index-thread_005fstatistics_002f3"></a>
<a name="index-thread_005fstatistics_002f3-1"></a>
<a name="index-thread_005fstatistics_002f3-2"></a>
<p>Obtains statistical information on thread <var>Id</var> as <code>statistics/2</code>
does in single-threaded applications. This call returns all keys
of <code>statistics/2</code>, although only information statistics about the
stacks and CPU time yield different values for each thread.
</p>
</dd>
<dt><code>mutex_statistics</code></dt>
<dd><a name="index-mutex_005fstatistics_002f0"></a>
<a name="index-mutex_005fstatistics_002f0-1"></a>
<a name="index-mutex_005fstatistics_002f0-2"></a>
<p>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 collision-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.
</p>
</dd>
<dt><code>threads</code></dt>
<dd><a name="index-threads_002f0"></a>
<a name="index-threads_002f0-1"></a>
<a name="index-threads_002f0-2"></a>
<p>Prints a table of current threads and their status.
</p></dd>
</dl>
<hr>
<a name="Thread-Communication"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Threads" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Monitoring-Threads" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Message-Queues" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parallelism" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Thread-communication"></a>
<h2 class="section">16.3 Thread communication</h2>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">Subnodes of Thread Communication
</pre></th></tr><tr><td align="left" valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Signalling-Threads">16.3.2 Signalling Threads</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#Threads-and-Dynamic-Predicates">16.3.3 Threads and Dynamic Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="Message-Queues"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Threads" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Thread-Communication" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Thread-Communication" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Signalling-Threads" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parallelism" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Message-Queues-1"></a>
<h3 class="subsection">16.3.1 Message Queues</h3>
<p>Prolog threads can exchange data using dynamic predicates, database
records, and other globally shared data. These provide no suitable means
to wait for data or a condition as they can only be checked in an
expensive polling loop. <em>Message queues</em> provide a means for
threads to wait for data or conditions without using the CPU.
</p>
<p>Each thread has a message-queue attached to it that is identified
by the thread. Additional queues are created using
<code>message_queue_create/2</code>.
</p>
<dl compact="compact">
<dt><code>thread_send_message(+<var>Term</var>)</code></dt>
<dd><a name="index-thread_005fsend_005fmessage_002f1"></a>
<a name="index-thread_005fsend_005fmessage_002f1-1"></a>
<a name="index-thread_005fsend_005fmessage_002f1-2"></a>
<p>Places <var>Term</var> in the message-queue of the thread running the goal.
Any term can be placed in a message queue, but note that the term is
copied to the receiving thread and variable-bindings are thus lost.
This call returns immediately.
</p>
</dd>
<dt><code>thread_send_message(+<var>QueueOrThreadId</var>, +<var>Term</var>)</code></dt>
<dd><a name="index-thread_005fsend_005fmessage_002f2"></a>
<a name="index-thread_005fsend_005fmessage_002f2-1"></a>
<a name="index-thread_005fsend_005fmessage_002f2-2"></a>
<p>Place <var>Term</var> in the given queue or default queue of the indicated
thread (which can even be the message queue of itself (see
<code>thread_self/1</code>). Any term can be placed in a message queue, but note that
the term is copied to the receiving thread and variable-bindings are
thus lost. This call returns immediately.
</p>
<p>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
<var>Term</var>, the waiting threads are <em>all</em> 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.
</p>
</dd>
<dt><code>thread_get_message(?<var>Term</var>)</code></dt>
<dd><a name="index-thread_005fget_005fmessage_002f1"></a>
<a name="index-thread_005fget_005fmessage_002f1-1"></a>
<a name="index-thread_005fget_005fmessage_002f1-2"></a>
<p>Examines the thread message-queue and if necessary blocks execution
until a term that unifies to <var>Term</var> arrives in the queue. After
a term from the queue has been unified unified to <var>Term</var>, the
term is deleted from the queue and this predicate returns.
</p>
<p>Please note that not-unifying messages remain in the queue. After
the following has been executed, thread 1 has the term <code>gnu</code>
in its queue and continues execution using <var>A</var> is <code>gnat</code>.
</p>
<div class="example">
<pre class="example"> &lt;thread 1&gt;
thread_get_message(a(A)),
&lt;thread 2&gt;
thread_send_message(b(gnu)),
thread_send_message(a(gnat)),
</pre></div>
<p>See also <code>thread_peek_message/1</code>.
</p>
</dd>
<dt><code>message_queue_create(?<var>Queue</var>)</code></dt>
<dd><a name="index-message_005fqueue_005fcreate_002f1"></a>
<a name="index-message_005fqueue_005fcreate_002f1-1"></a>
<a name="index-message_005fqueue_005fcreate_002f1-2"></a>
<p>If <var>Queue</var> is an atom, create a named queue. To avoid ambiguity
on <code>thread_send_message/2</code>, the name of a queue may not be in use
as a thread-name. If <var>Queue</var> is unbound an anonymous queue is
created and <var>Queue</var> is unified to its identifier.
</p>
</dd>
<dt><code>message_queue_destroy(+<var>Queue</var>)</code></dt>
<dd><a name="index-message_005fqueue_005fdestroy_002f1"></a>
<a name="index-message_005fqueue_005fdestroy_002f1-1"></a>
<a name="index-message_005fqueue_005fdestroy_002f1-2"></a>
<p>Destroy a message queue created with <code>message_queue_create/1</code>. It is
<em>not</em> allows to destroy the queue of a thread. Neither is it
allowed to destroy a queue other threads are waiting for or, for
anonymous message queues, may try to wait for later.
</p>
</dd>
<dt><code>thread_get_message(+<var>Queue</var>, ?<var>Term</var>)</code></dt>
<dd><a name="index-thread_005fget_005fmessage_002f2"></a>
<a name="index-thread_005fget_005fmessage_002f2-1"></a>
<a name="index-thread_005fget_005fmessage_002f2-2"></a>
<p>As <code>thread_get_message/1</code>, operating on a given queue. It is allowed to
peek into another thread&rsquo;s message queue, an operation that can be used
to check whether a thread has swallowed a message sent to it.
</p>
</dd>
<dt><code>thread_peek_message(?<var>Term</var>)</code></dt>
<dd><a name="index-thread_005fpeek_005fmessage_002f1"></a>
<a name="index-thread_005fpeek_005fmessage_002f1-1"></a>
<a name="index-thread_005fpeek_005fmessage_002f1-2"></a>
<p>Examines the thread message-queue and compares the queued terms
with <var>Term</var> until one unifies or the end of the queue has been
reached. In the first case the call succeeds (possibly instantiating
<var>Term</var>. If no term from the queue unifies this call fails.
</p>
</dd>
<dt><code>thread_peek_message(+<var>Queue</var>, ?<var>Term</var>)</code></dt>
<dd><a name="index-thread_005fpeek_005fmessage_002f2"></a>
<a name="index-thread_005fpeek_005fmessage_002f2-1"></a>
<a name="index-thread_005fpeek_005fmessage_002f2-2"></a>
<p>As <code>thread_peek_message/1</code>, operating on a given queue. It is allowed to
peek into another thread&rsquo;s message queue, an operation that can be used
to check whether a thread has swallowed a message sent to it.
</p>
</dd>
</dl>
<p>Explicit message queues are designed with the <em>worker-pool</em> 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.
</p>
<div class="example">
<pre class="example">% 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))
-&gt; 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).
</pre></div>
<hr>
<a name="Signalling-Threads"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Threads" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Message-Queues" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Thread-Communication" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Threads-and-Dynamic-Predicates" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parallelism" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Signalling-Threads-1"></a>
<h3 class="subsection">16.3.2 Signalling Threads</h3>
<p>These predicates provide a mechanism to make another thread execute some
goal as an <em>interrupt</em>. Signalling threads is safe as these
interrupts are only checked at safe points in the virtual machine.
Nevertheless, signalling in multi-threaded environments should be
handled with care as the receiving thread may hold a <em>mutex</em>
(see <code>with_mutex/2</code>). Signalling probably only makes sense to start
debugging threads and to cancel no-longer-needed threads with <code>throw/1</code>,
where the receiving thread should be designed carefully do handle
exceptions at any point.
</p>
<dl compact="compact">
<dt><code>thread_signal(+<var>ThreadId</var>, :<var>Goal</var>)</code></dt>
<dd><a name="index-thread_005fsignal_002f2"></a>
<a name="index-thread_005fsignal_002f2-1"></a>
<a name="index-thread_005fsignal_002f2-2"></a>
<p>Make thread <var>ThreadId</var> execute <var>Goal</var> at the first
opportunity. In the current implementation, this implies at the first
pass through the <em>Call-port</em>. The predicate <code>thread_signal/2</code>
itself places <var>Goal</var> into the signalled-thread&rsquo;s signal queue
and returns immediately.
</p>
<p>Signals (interrupts) do not cooperate well with the world of
multi-threading, mainly because the status of mutexes cannot be
guaranteed easily. At the call-port, the Prolog virtual machine
holds no locks and therefore the asynchronous execution is safe.
</p>
<p><var>Goal</var> can be any valid Prolog goal, including <code>throw/1</code> to make
the receiving thread generate an exception and <code>trace/0</code> to start
tracing the receiving thread.
</p>
</dd>
</dl>
<hr>
<a name="Threads-and-Dynamic-Predicates"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Threads" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Signalling-Threads" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Thread-Communication" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Thread-Synchronisation" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parallelism" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Threads-and-Dynamic-Predicates-1"></a>
<h3 class="subsection">16.3.3 Threads and Dynamic Predicates</h3>
<p>Besides queues threads can share and exchange data using dynamic
predicates. The multi-threaded version knows about two types of
dynamic predicates. By default, a predicate declared <em>dynamic</em>
(see <code>dynamic/1</code>) is shared by all threads. Each thread may
assert, retract and run the dynamic predicate. Synchronisation inside
Prolog guarantees the consistency of the predicate. Updates are
<em>logical</em>: visible clauses are not affected by assert/retract
after a query started on the predicate. In many cases primitive from
thread synchronisation should be used to ensure application invariants on
the predicate are maintained.
</p>
<p>Besides shared predicates, dynamic predicates can be declared with the
<code>thread_local/1</code> directive. Such predicates share their
attributes, but the clause-list is different in each thread.
</p>
<dl compact="compact">
<dt><code>thread_local(<var>+Functor/Arity</var>)</code></dt>
<dd><a name="index-thread_005flocal_002f1-_0028directive_0029"></a>
<a name="index-thread_005flocal_002f1-_0028directive_0029-1"></a>
<a name="index-thread_005flocal_002f1-_0028directive_0029-2"></a>
<p>related to the dynamic/1 directive. It tells the system that the
predicate may be modified using <code>assert/1</code>, <code>retract/1</code>,
etc, during execution of the program. Unlike normal shared dynamic
data however each thread has its own clause-list for the predicate.
As a thread starts, this clause list is empty. If there are still
clauses as the thread terminates these are automatically reclaimed by
the system. The <code>thread_local</code> property implies
the property <code>dynamic</code>.
</p>
<p>Thread-local dynamic predicates are intended for maintaining
thread-specific state or intermediate results of a computation.
</p>
<p>It is not recommended to put clauses for a thread-local predicate into
a file as in the example below as the clause is only visible from the
thread that loaded the source-file. All other threads start with an
empty clause-list.
</p>
<div class="example">
<pre class="example">:- thread_local
foo/1.
foo(gnat).
</pre></div>
</dd>
</dl>
<hr>
<a name="Thread-Synchronisation"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Threads" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads-and-Dynamic-Predicates" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Threads" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Parallelism" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parallelism" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Thread-Synchronisation-1"></a>
<h2 class="section">16.4 Thread Synchronisation</h2>
<p>All internal Prolog operations are thread-safe. This implies two Prolog
threads can operate on the same dynamic predicate without corrupting the
consistency of the predicate. This section deals with user-level
<em>mutexes</em> (called <em>monitors</em> in ADA or
<em>critical-sections</em> by Microsoft). A mutex is a
<em>MUT</em>ual <em>EX</em>clusive device, which implies at most one thread
can <em>hold</em> a mutex.
</p>
<p>Mutexes are used to realise related updates to the Prolog database.
With &lsquo;related&rsquo;, we refer to the situation where a &lsquo;transaction&rsquo; implies
two or more changes to the Prolog database. For example, we have a
predicate <code>address/2</code>, representing the address of a person and we want
to change the address by retracting the old and asserting the new
address. Between these two operations the database is invalid: this
person has either no address or two addresses, depending on the
assert/retract order.
</p>
<p>Here is how to realise a correct update:
</p>
<div class="example">
<pre class="example">:- initialization
mutex_create(addressbook).
change_address(Id, Address) :-
mutex_lock(addressbook),
retractall(address(Id, _)),
asserta(address(Id, Address)),
mutex_unlock(addressbook).
</pre></div>
<dl compact="compact">
<dt><code>mutex_create(?<var>MutexId</var>)</code></dt>
<dd><a name="index-mutex_005fcreate_002f1"></a>
<a name="index-mutex_005fcreate_002f1-1"></a>
<a name="index-mutex_005fcreate_002f1-2"></a>
<p>Create a mutex. if <var>MutexId</var> is an atom, a <em>named</em> 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.
</p>
</dd>
<dt><code>mutex_destroy(+<var>MutexId</var>)</code></dt>
<dd><a name="index-mutex_005fdestroy_002f1"></a>
<a name="index-mutex_005fdestroy_002f1-1"></a>
<a name="index-mutex_005fdestroy_002f1-2"></a>
<p>Destroy a mutex. After this call, <var>MutexId</var> becomes invalid and
further references yield an <code>existence_error</code> exception.
</p>
</dd>
<dt><code>with_mutex(+<var>MutexId</var>, :<var>Goal</var>)</code></dt>
<dd><a name="index-with_005fmutex_002f2"></a>
<a name="index-with_005fmutex_002f2-1"></a>
<a name="index-with_005fmutex_002f2-2"></a>
<p>Execute <var>Goal</var> while holding <var>MutexId</var>. If <var>Goal</var> leaves
choicepoints, these are destroyed (as in <code>once/1</code>). The mutex is unlocked
regardless of whether <var>Goal</var> succeeds, fails or raises an exception.
An exception thrown by <var>Goal</var> is re-thrown after the mutex has been
successfully unlocked. See also <code>mutex_create/2</code>.
</p>
<p>Although described in the thread-section, this predicate is also
available in the single-threaded version, where it behaves simply as
<code>once/1</code>.
</p>
</dd>
<dt><code>mutex_lock(+<var>MutexId</var>)</code></dt>
<dd><a name="index-mutex_005flock_002f1"></a>
<a name="index-mutex_005flock_002f1-1"></a>
<a name="index-mutex_005flock_002f1-2"></a>
<p>Lock the mutex. Prolog mutexes are <em>recursive</em> 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.
</p>
<p>If <var>MutexId</var> is an atom, and there is no current mutex with that
name, the mutex is created automatically using <code>mutex_create/1</code>. This
implies named mutexes need not be declared explicitly.
</p>
<p>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
<code>with_mutex/2</code>, which provides a safer way for handling Prolog-level
mutexes.
</p>
</dd>
<dt><code>mutex_trylock(+<var>MutexId</var>)</code></dt>
<dd><a name="index-mutex_005ftrylock_002f1"></a>
<a name="index-mutex_005ftrylock_002f1-1"></a>
<a name="index-mutex_005ftrylock_002f1-2"></a>
<p>As mutex_lock/1, but if the mutex is held by another thread, this
predicates fails immediately.
</p>
</dd>
<dt><code>mutex_unlock(+<var>MutexId</var>)</code></dt>
<dd><a name="index-mutex_005funlock_002f1"></a>
<a name="index-mutex_005funlock_002f1-1"></a>
<a name="index-mutex_005funlock_002f1-2"></a>
<p>Unlock the mutex. This can only be called if the mutex is held by the
calling thread. If this is not the case, a <code>permission_error</code>
exception is raised.
</p>
</dd>
<dt><code>mutex_unlock_all</code></dt>
<dd><a name="index-mutex_005funlock_005fall_002f0"></a>
<a name="index-mutex_005funlock_005fall_002f0-1"></a>
<a name="index-mutex_005funlock_005fall_002f0-2"></a>
<p>Unlock all mutexes held by the current thread. This call is especially
useful to handle thread-termination using <code>abort/0</code> or exceptions. See
also <code>thread_signal/2</code>.
</p>
</dd>
<dt><code>current_mutex(?<var>MutexId</var>, ?<var>ThreadId</var>, ?<var>Count</var>)</code></dt>
<dd><a name="index-current_005fmutex_002f3"></a>
<a name="index-current_005fmutex_002f3-1"></a>
<a name="index-current_005fmutex_002f3-2"></a>
<p>Enumerates all existing mutexes. If the mutex is held by some thread,
<var>ThreadId</var> is unified with the identifier of the holding thread and
<var>Count</var> with the recursive count of the mutex. Otherwise,
<var>ThreadId</var> is <code>[]</code> and <var>Count</var> is 0.
</p></dd>
</dl>
<hr>
<a name="Parallelism"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Threads" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Thread-Synchronisation" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Tabling" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tabling" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Parallelism-1"></a>
<h1 class="chapter">17 Parallelism</h1>
<a name="index-parallelism"></a>
<a name="index-or_002dparallelism"></a>
<p>There has been a sizeable amount of work on an or-parallel
implementation for YAP, called <strong>YAPOr</strong>. 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 <code>configure</code> script or by checking the
system&rsquo;s <code>Makefile</code>.
</p>
<p><strong>YAPOr</strong> is still a very experimental system, going through rapid
development. The following restrictions are of note:
</p>
<ul>
<li> <strong>YAPOr</strong> currently only supports the Linux/X86 and SPARC/Solaris
platforms. Porting to other Unix-like platforms should be straightforward.
</li><li> <strong>YAPOr</strong> does not support parallel updates to the
data-base.
</li><li> <strong>YAPOr</strong> does not support opening or closing of streams during
parallel execution.
</li><li> Garbage collection and stack shifting are not supported in
<strong>YAPOr</strong>.
</li><li> 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.
</li><li> YAP does not support voluntary suspension of work.
</li></ul>
<p>We expect that some of these restrictions will be removed in future
releases.
</p>
<hr>
<a name="Tabling"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Parallelism" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parallelism" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Low-Level-Tracing" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Low-Level-Tracing" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Tabling-1"></a>
<h1 class="chapter">18 Tabling</h1>
<a name="index-tabling"></a>
<p><strong>YAPTab</strong> is the tabling engine that extends YAP&rsquo;s execution
model to support tabled evaluation for definite programs. YAPTab was
implemented by Ricardo Rocha and its implementation is largely based
on the ground-breaking design of the XSB Prolog system, which
implements the SLG-WAM. Tables are implemented using tries and YAPTab
supports the dynamic intermixing of batched scheduling and local
scheduling at the subgoal level. Currently, the following restrictions
are of note:
</p><ul>
<li> YAPTab does not handle tabled predicates with loops through negation (undefined behaviour).
</li><li> YAPTab does not handle tabled predicates with cuts (undefined behaviour).
</li><li> YAPTab does not support coroutining (configure error).
</li><li> YAPTab does not support tabling dynamic predicates (permission error).
</li></ul>
<p>To experiment with YAPTab use <code>--enable-tabling</code> in the configure
script or add <code>-DTABLING</code> to <code>YAP_EXTRAS</code> in the system&rsquo;s
<code>Makefile</code>. We next describe the set of built-ins predicates
designed to interact with YAPTab and control tabled execution:
</p>
<dl compact="compact">
<dt><code>table +<var>P</var></code></dt>
<dd><a name="index-table_002f1"></a>
<a name="index-table_002f1-1"></a>
<a name="index-table_002f1-2"></a>
<p>Declares predicate <var>P</var> (or a list of predicates
<var>P1</var>,...,<var>Pn</var> or [<var>P1</var>,...,<var>Pn</var>]) as a tabled
predicate. <var>P</var> must be written in the form
<var>name/arity</var>. Examples:
</p><div class="example">
<pre class="example">:- table son/3.
:- table father/2.
:- table mother/2.
</pre></div>
<p>or
</p><div class="example">
<pre class="example">:- table son/3, father/2, mother/2.
</pre></div>
<p>or
</p><div class="example">
<pre class="example">:- table [son/3, father/2, mother/2].
</pre></div>
</dd>
<dt><code>is_tabled(+<var>P</var>)</code></dt>
<dd><a name="index-is_005ftabled_002f1"></a>
<a name="index-is_005ftabled_002f1-1"></a>
<a name="index-is_005ftabled_002f1-2"></a>
<p>Succeeds if the predicate <var>P</var> (or a list of predicates
<var>P1</var>,...,<var>Pn</var> or [<var>P1</var>,...,<var>Pn</var>]), of the form
<var>name/arity</var>, is a tabled predicate.
</p>
</dd>
<dt><code>tabling_mode(+<var>P</var>,?<var>Mode</var>)</code></dt>
<dd><a name="index-tabling_005fmode_002f2"></a>
<a name="index-tabling_005fmode_002f2-1"></a>
<a name="index-tabling_005fmode_002f2-2"></a>
<p>Sets or reads the default tabling mode for a tabled predicate <var>P</var>
(or a list of predicates <var>P1</var>,...,<var>Pn</var> or
[<var>P1</var>,...,<var>Pn</var>]). The list of <var>Mode</var> options includes:
</p><dl compact="compact">
<dt><code>batched</code></dt>
<dd><p> Defines that, by default, batched scheduling is the scheduling
strategy to be used to evaluated calls to predicate <var>P</var>.
</p></dd>
<dt><code>local</code></dt>
<dd><p> Defines that, by default, local scheduling is the scheduling
strategy to be used to evaluated calls to predicate <var>P</var>.
</p></dd>
<dt><code>exec_answers</code></dt>
<dd><p> Defines that, by default, when a call to predicate <var>P</var> is
already evaluated (completed), answers are obtained by executing
compiled WAM-like code directly from the trie data
structure. This reduces the loading time when backtracking, but
the order in which answers are obtained is undefined.
</p></dd>
<dt><code>load_answers</code></dt>
<dd><p> Defines that, by default, when a call to predicate <var>P</var> is
already evaluated (completed), answers are obtained (as a
consumer) by loading them from the trie data structure. This
guarantees that answers are obtained in the same order as they
were found. Somewhat less efficient but creates less choice-points.
</p></dd>
</dl>
<p>The default tabling mode for a new tabled predicate is <code>batched</code>
and <code>exec_answers</code>. To set the tabling mode for all predicates at
once you can use the <code>yap_flag/2</code> predicate as described next.
</p>
</dd>
<dt><code>yap_flag(tabling_mode,?<var>Mode</var>)</code></dt>
<dd><a name="index-tabling_005fmode-_0028yap_005fflag_002f2-option_0029"></a>
<p>Sets or reads the tabling mode for all tabled predicates. The list of
<var>Mode</var> options includes:
</p><dl compact="compact">
<dt><code>default</code></dt>
<dd><p> Defines that (i) all calls to tabled predicates are evaluated
using the predicate default mode, and that (ii) answers for all
completed calls are obtained by using the predicate default mode.
</p></dd>
<dt><code>batched</code></dt>
<dd><p> Defines that all calls to tabled predicates are evaluated using
batched scheduling. This option ignores the default tabling mode
of each predicate.
</p></dd>
<dt><code>local</code></dt>
<dd><p> Defines that all calls to tabled predicates are evaluated using
local scheduling. This option ignores the default tabling mode
of each predicate.
</p></dd>
<dt><code>exec_answers</code></dt>
<dd><p> Defines that answers for all completed calls are obtained by
executing compiled WAM-like code directly from the trie data
structure. This option ignores the default tabling mode
of each predicate.
</p></dd>
<dt><code>load_answers</code></dt>
<dd><p> Defines that answers for all completed calls are obtained by
loading them from the trie data structure. This option ignores
the default tabling mode of each predicate.
</p></dd>
</dl>
</dd>
<dt><code>abolish_table(+<var>P</var>)</code></dt>
<dd><a name="index-abolish_005ftable_002f1"></a>
<a name="index-abolish_005ftable_002f1-1"></a>
<a name="index-abolish_005ftable_002f1-2"></a>
<p>Removes all the entries from the table space for predicate <var>P</var> (or
a list of predicates <var>P1</var>,...,<var>Pn</var> or
[<var>P1</var>,...,<var>Pn</var>]). The predicate remains as a tabled predicate.
</p>
</dd>
<dt><code>abolish_all_tables/0</code></dt>
<dd><a name="index-abolish_005fall_005ftables_002f0"></a>
<a name="index-abolish_005fall_005ftables_002f0-1"></a>
<a name="index-abolish_005fall_005ftables_002f0-2"></a>
<p>Removes all the entries from the table space for all tabled
predicates. The predicates remain as tabled predicates.
</p>
</dd>
<dt><code>show_table(+<var>P</var>)</code></dt>
<dd><a name="index-show_005ftable_002f1"></a>
<a name="index-show_005ftable_002f1-1"></a>
<a name="index-show_005ftable_002f1-2"></a>
<p>Prints table contents (subgoals and answers) for predicate <var>P</var>
(or a list of predicates <var>P1</var>,...,<var>Pn</var> or
[<var>P1</var>,...,<var>Pn</var>]).
</p>
</dd>
<dt><code>table_statistics(+<var>P</var>)</code></dt>
<dd><a name="index-table_005fstatistics_002f1"></a>
<a name="index-table_005fstatistics_002f1-1"></a>
<a name="index-table_005fstatistics_002f1-2"></a>
<p>Prints table statistics (subgoals and answers) for predicate <var>P</var>
(or a list of predicates <var>P1</var>,...,<var>Pn</var> or
[<var>P1</var>,...,<var>Pn</var>]).
</p>
</dd>
<dt><code>tabling_statistics/0</code></dt>
<dd><a name="index-tabling_005fstatistics_002f0"></a>
<a name="index-tabling_005fstatistics_002f0-1"></a>
<a name="index-tabling_005fstatistics_002f0-2"></a>
<p>Prints statistics on space used by all tables.
</p></dd>
</dl>
<hr>
<a name="Low-Level-Tracing"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Tabling" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Tabling" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Low-Level-Profiling" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Low-Level-Profiling" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Tracing-at-Low-Level"></a>
<h1 class="chapter">19 Tracing at Low Level</h1>
<p>It is possible to follow the flow at abstract machine level if
YAP is compiled with the flag <code>LOW_LEVEL_TRACER</code>. Note
that this option is of most interest to implementers, as it quickly generates
an huge amount of information.
</p>
<p>Low level tracing can be toggled from an interrupt handler by using the
option <code>T</code>. There are also two built-ins that activate and
deactivate low level tracing:
</p>
<dl compact="compact">
<dt><code>start_low_level_trace</code></dt>
<dd><a name="index-start_005flow_005flevel_005ftrace_002f0"></a>
<a name="index-start_005flow_005flevel_005ftrace_002f0-1"></a>
<a name="index-start_005flow_005flevel_005ftrace_002f0-2"></a>
<p>Begin display of messages at procedure entry and retry.
</p>
</dd>
<dt><code>stop_low_level_trace</code></dt>
<dd><a name="index-start_005flow_005flevel_005ftrace_002f0-3"></a>
<a name="index-start_005flow_005flevel_005ftrace_002f0-4"></a>
<a name="index-start_005flow_005flevel_005ftrace_002f0-5"></a>
<p>Stop display of messages at procedure entry and retry.
</p></dd>
</dl>
<p>Note that this compile-time option will slow down execution.
</p>
<hr>
<a name="Low-Level-Profiling"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Low-Level-Tracing" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Low-Level-Tracing" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Debugging" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Debugging" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Profiling-the-Abstract-Machine"></a>
<h1 class="chapter">20 Profiling the Abstract Machine</h1>
<p>Implementors may be interested in detecting on which abstract machine
instructions are executed by a program. The <code>ANALYST</code> flag can give
WAM level information. Note that this option slows down execution very
substantially, and is only of interest to developers of the system
internals, or to system debuggers.
</p>
<dl compact="compact">
<dt><code>reset_op_counters</code></dt>
<dd><a name="index-reset_005fop_005fcounters_002f0"></a>
<a name="index-reset_005fop_005fcounters_002f0-1"></a>
<a name="index-reset_005fop_005fcounters_002f0-2"></a>
<p>Reinitialize all counters.
</p>
</dd>
<dt><code>show_op_counters(+<var>A</var>)</code></dt>
<dd><a name="index-show_005fop_005fcounters_002f1"></a>
<a name="index-show_005fop_005fcounters_002f1-1"></a>
<a name="index-show_005fop_005fcounters_002f1-2"></a>
<p>Display the current value for the counters, using label <var>A</var>. The
label must be an atom.
</p>
</dd>
<dt><code>show_ops_by_group(+<var>A</var>)</code></dt>
<dd><a name="index-show_005fops_005fby_005fgroup_002f1"></a>
<a name="index-show_005fops_005fby_005fgroup_002f1-1"></a>
<a name="index-show_005fops_005fby_005fgroup_002f1-2"></a>
<p>Display the current value for the counters, organized by groups, using
label <var>A</var>. The label must be an atom.
</p>
</dd>
</dl>
<hr>
<a name="Debugging"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Low-Level-Profiling" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Low-Level-Profiling" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Deb-Preds" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Efficiency" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Debugging-1"></a>
<h1 class="chapter">21 Debugging</h1>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Deb-Interaction">21.2 Interacting with the debugger</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
</table>
<hr>
<a name="Deb-Preds"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Debugging" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Debugging" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Debugging" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Deb-Interaction" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Efficiency" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Debugging-Predicates"></a>
<h2 class="section">21.1 Debugging Predicates</h2>
<p>The following predicates are available to control the debugging of
programs:
</p>
<dl compact="compact">
<dt><code>debug</code></dt>
<dd><a name="index-debug_002f0"></a>
<a name="index-debug_002f0-1"></a>
<a name="index-debug_002f0-2"></a>
<p>Switches the debugger on.
</p>
</dd>
<dt><code>debugging</code></dt>
<dd><a name="index-debugging_002f0"></a>
<a name="index-debugging_002f0-1"></a>
<a name="index-debugging_002f0-2"></a>
<p>Outputs status information about the debugger which includes the leash
mode and the existing spy-points, when the debugger is on.
</p>
</dd>
<dt><code>nodebug</code></dt>
<dd><a name="index-nodebug_002f0"></a>
<a name="index-nodebug_002f0-1"></a>
<a name="index-nodebug_002f0-2"></a>
<p>Switches the debugger off.
</p>
</dd>
<dt><code>spy +<var>P</var></code></dt>
<dd><a name="index-spy_002f1"></a>
<a name="index-spy_002f1-1"></a>
<a name="index-spy_002f1-2"></a>
<p> Sets spy-points on all the predicates represented by
<var>P</var>. <var>P</var> can either be a single specification or a list of
specifications. Each one must be of the form <var>Name/Arity</var>
or <var>Name</var>. In the last case all predicates with the name
<var>Name</var> will be spied. As in C-Prolog, system predicates and
predicates written in C, cannot be spied.
</p>
</dd>
<dt><code>nospy +<var>P</var></code></dt>
<dd><a name="index-nospy_002f1"></a>
<a name="index-nospy_002f1-1"></a>
<a name="index-nospy_002f1-2"></a>
<p> Removes spy-points from all predicates specified by <var>P</var>.
The possible forms for <var>P</var> are the same as in <code>spy P</code>.
</p>
</dd>
<dt><code>nospyall</code></dt>
<dd><a name="index-nospyall_002f0"></a>
<a name="index-nospyall_002f0-1"></a>
<a name="index-nospyall_002f0-2"></a>
<p>Removes all existing spy-points.
</p>
</dd>
<dt><code>notrace</code></dt>
<dd><p>Switches off the debugger and stops tracing.
</p>
</dd>
<dt><code>leash(+<var>M</var>)</code></dt>
<dd><a name="index-leash_002f1"></a>
<a name="index-leash_002f1-1"></a>
<a name="index-leash_002f1-2"></a>
<p> Sets leashing mode to <var>M</var>.
The mode can be specified as:
</p><dl compact="compact">
<dt><code>full</code></dt>
<dd><p>prompt on Call, Exit, Redo and Fail
</p></dd>
<dt><code>tight</code></dt>
<dd><p>prompt on Call, Redo and Fail
</p></dd>
<dt><code>half</code></dt>
<dd><p>prompt on Call and Redo
</p></dd>
<dt><code>loose</code></dt>
<dd><p>prompt on Call
</p></dd>
<dt><code>off</code></dt>
<dd><p>never prompt
</p></dd>
<dt><code>none</code></dt>
<dd><p>never prompt, same as <code>off</code>
</p></dd>
</dl>
<p>The initial leashing mode is <code>full</code>.
</p>
<p>The user may also specify directly the debugger ports
where he wants to be prompted. If the argument for leash
is a number <var>N</var>, each of lower four bits of the number is used to
control prompting at one the ports of the box model. The debugger will
prompt according to the following conditions:
</p>
<ul>
<li>
if <code>N/\ 1 =\= 0</code> prompt on fail
</li><li>
if <code>N/\ 2 =\= 0</code> prompt on redo
</li><li>
if <code>N/\ 4 =\= 0</code> prompt on exit
</li><li>
if <code>N/\ 8 =\= 0</code> prompt on call
</li></ul>
<p>Therefore, <code>leash(15)</code> is equivalent to <code>leash(full)</code> and
<code>leash(0)</code> is equivalent to <code>leash(off)</code>.
</p>
<p>Another way of using <code>leash</code> is to give it a list with the names of
the ports where the debugger should stop. For example,
<code>leash([call,exit,redo,fail])</code> is the same as <code>leash(full)</code> or
<code>leash(15)</code> and <code>leash([fail])</code> might be used instead of
<code>leash(1)</code>.
</p>
</dd>
<dt><code>spy_write(+<var>Stream</var>,Term)</code></dt>
<dd><a name="index-spy_005fwrite_002f2"></a>
<a name="index-spy_005fwrite_002f2-1"></a>
<a name="index-spy_005fwrite_002f2-2"></a>
<p>If defined by the user, this predicate will be used to print goals by
the debugger instead of <code>write/2</code>.
</p>
</dd>
<dt><code>trace</code></dt>
<dd><a name="index-trace_002f0"></a>
<a name="index-trace_002f0-1"></a>
<a name="index-trace_002f0-2"></a>
<p>Switches on the debugger and starts tracing.
</p>
</dd>
<dt><code>notrace</code></dt>
<dd><a name="index-notrace_002f0"></a>
<a name="index-notrace_002f0-1"></a>
<a name="index-notrace_002f0-2"></a>
<p>Ends tracing and exits the debugger. This is the same as
<code>nodebug/0</code>.
</p>
</dd>
</dl>
<hr>
<a name="Deb-Interaction"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Debugging" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Deb-Preds" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Debugging" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Efficiency" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Efficiency" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Interacting-with-the-debugger"></a>
<h2 class="section">21.2 Interacting with the debugger</h2>
<p>Debugging with YAP is similar to debugging with C-Prolog. Both systems
include a procedural debugger, based on Byrd&rsquo;s four port model. In this
model, execution is seen at the procedure level: each activation of a
procedure is seen as a box with control flowing into and out of that
box.
</p>
<p> In the four port model control is caught at four key points: before
entering the procedure, after exiting the procedure (meaning successful
evaluation of all queries activated by the procedure), after backtracking but
before trying new alternative to the procedure and after failing the
procedure. Each one of these points is named a port:
</p>
<div class="smallexample">
<pre class="smallexample"> *--------------------------------------*
Call | | Exit
---------&gt; + descendant(X,Y) :- offspring(X,Y). + ---------&gt;
| |
| descendant(X,Z) :- |
&lt;--------- + offspring(X,Y), descendant(Y,Z). + &lt;---------
Fail | | Redo
*--------------------------------------*
</pre></div>
<dl compact="compact">
<dt><code>Call</code></dt>
<dd><p>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.
</p></dd>
<dt><code>Exit</code></dt>
<dd><p>This port is activated if the procedure succeeds.
Control will now leave the procedure and return to its ancestor.
</p></dd>
<dt><code>Redo</code></dt>
<dd><p>if the goal, or goals, activated after the call port
fail then backtracking will eventually return control to this procedure
through the redo port.
</p></dd>
<dt><code>Fail</code></dt>
<dd><p>If all clauses for this predicate fail, then the
invocation fails, and control will try to redo the ancestor of this
invocation.
</p></dd>
</dl>
<p>To start debugging, the user will either call <code>trace</code> or spy the
relevant procedures, entering debug mode, and start execution of the
program. When finding the first spy-point, YAP&rsquo;s debugger will take
control and show a message of the form:
</p>
<div class="example">
<pre class="example">* (1) call: quicksort([1,2,3],_38) ?
</pre></div>
<p> The debugger message will be shown while creeping, or at spy-points,
and it includes four or five fields:
</p>
<ul>
<li>
The first three characters are used to point out special states of the
debugger. If the port is exit and the first character is &rsquo;?&rsquo;, the
current call is non-deterministic, that is, it still has alternatives to
be tried. If the second character is a <code>*</code>, execution is at a
spy-point. If the third character is a <code>&gt;</code>, execution has returned
either from a skip, a fail or a redo command.
</li><li>
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.
</li><li>
In the third field, the debugger shows the active port.
</li><li>
The fourth field is the goal. The goal is written by
<code>write_term/3</code> on the standard error stream, using the options
given by <code>debugger_print_options</code>.
</li></ul>
<p> If the active port is leashed, the debugger will prompt the user with a
<code>?</code>, 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 <code>leash/1</code> predicate can be used in
order to make the debugger stop where needed.
</p>
<p> There are several commands available, but the user only needs to
remember the help command, which is <code>h</code>. This command shows all the
available options, which are:
</p><dl compact="compact">
<dt><code>c - creep</code></dt>
<dd><p>this command makes YAP continue execution and stop at the next
leashed port.
</p></dd>
<dt><code>return - creep</code></dt>
<dd><p>the same as c
</p></dd>
<dt><code>l - leap</code></dt>
<dd><p>YAP will execute until it meets a port for a spied predicate; this mode
keeps all computation history for debugging purposes, so it is more
expensive than standard execution. Use <tt>k</tt> or <tt>z</tt> for fast execution.
</p></dd>
<dt><code>k - quasi-leap</code></dt>
<dd><p>similar to leap but faster since the computation history is
not kept; useful when leap becomes too slow.
</p></dd>
<dt><code>z - zip</code></dt>
<dd><p>same as <tt>k</tt>
</p></dd>
<dt><code>s - skip</code></dt>
<dd><p>YAP will continue execution without showing any messages until
returning to the current activation. Spy-points will be ignored in this
mode. Note that this command keeps all debugging history, use <tt>t</tt> for fast execution. This command is meaningless, and therefore illegal, in the fail
and exit ports.
</p></dd>
<dt><code>t - fast-skip</code></dt>
<dd><p>similar to skip but faster since computation history is not
kept; useful if skip becomes slow.
</p></dd>
<dt><code>f [<var>GoalId</var>] - fail</code></dt>
<dd><p>If given no argument, forces YAP to fail the goal, skipping the fail
port and backtracking to the parent.
If <tt>f</tt> receives a goal number as
the argument, the command fails all the way to the goal. If goal <var>GoalId</var> has completed execution, YAP fails until meeting the first active ancestor.
</p></dd>
<dt><code>r [<var>GoalId</var>] - retry</code></dt>
<dd><p>This command forces YAP to jump back call to the port. Note that any
side effects of the goal cannot be undone. This command is not available
at the call port. If <tt>f</tt> receives a goal number as the argument, the
command retries goal <var>GoalId</var> instead. If goal <var>GoalId</var> has
completed execution, YAP fails until meeting the first active ancestor.
</p>
</dd>
<dt><code>a - abort</code></dt>
<dd><p>execution will be aborted, and the interpreter will return to the
top-level. YAP disactivates debug mode, but spypoints are not removed.
</p></dd>
<dt><code>n - nodebug</code></dt>
<dd><p>stop debugging and continue execution. The command will not clear active
spy-points.
</p></dd>
<dt><code>e - exit</code></dt>
<dd><p>leave YAP.
</p></dd>
<dt><code>h - help</code></dt>
<dd><p>show the debugger commands.
</p></dd>
<dt><code>! Query</code></dt>
<dd><p>execute a query. YAP will not show the result of the query.
</p></dd>
<dt><code>b - break</code></dt>
<dd><p>break active execution and launch a break level. This is the same as <code>!
break</code>.
</p></dd>
<dt><code>+ - spy this goal</code></dt>
<dd><p>start spying the active goal. The same as <code>! spy G</code> where <var>G</var>
is the active goal.
</p></dd>
<dt><code>- - nospy this goal</code></dt>
<dd><p>stop spying the active goal. The same as <code>! nospy G</code> where <var>G</var> is
the active goal.
</p></dd>
<dt><code>p - print</code></dt>
<dd><p>shows the active goal using print/1
</p></dd>
<dt><code>d - display</code></dt>
<dd><p>shows the active goal using display/1
</p></dd>
<dt><code>&lt;Depth - debugger write depth</code></dt>
<dd><p>sets the maximum write depth, both for composite terms and lists, that
will be used by the debugger. For more
information about <code>write_depth/2</code> (see section <a href="#I_002fO-Control">Controlling Input/Output</a>).
</p></dd>
<dt><code>&lt; - full term</code></dt>
<dd><p>resets to the default of ten the debugger&rsquo;s maximum write depth. For
more information about <code>write_depth/2</code> (see section <a href="#I_002fO-Control">Controlling Input/Output</a>).
</p></dd>
<dt><code>A - alternatives</code></dt>
<dd><p> show the list of backtrack points in the current execution.
</p></dd>
<dt><code>g [<var>N</var>]</code></dt>
<dd><p> show the list of ancestors in the current debugging environment. If it
receives <var>N</var>, show the first <var>N</var> ancestors.
</p></dd>
</dl>
<p>The debugging information, when fast-skip <code>quasi-leap</code> is used, will
be lost.
</p>
<hr>
<a name="Efficiency"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Debugging" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Deb-Interaction" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Deterministic-Programs" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Efficiency-Considerations"></a>
<h1 class="chapter">22 Efficiency Considerations</h1>
<p>We next discuss several issues on trying to make Prolog programs run
fast in YAP. We assume two different programming styles:
</p>
<dl compact="compact">
<dt>&bull; Execution of <em>deterministic</em> programs often</dt>
<dd><p>boils down to a recursive loop of the form:
</p><div class="example">
<pre class="example">loop(Env) :-
do_something(Env,NewEnv),
loop(NewEnv).
</pre></div>
</dd>
</dl>
<hr>
<a name="Deterministic-Programs"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Efficiency" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Efficiency" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Efficiency" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Non_002dDeterministic-Programs" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">22.1 Deterministic Programs</h2>
<hr>
<a name="Non_002dDeterministic-Programs"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Efficiency" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Deterministic-Programs" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Efficiency" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Data_002dBase-Operations" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">22.2 Non-Deterministic Programs</h2>
<hr>
<a name="Data_002dBase-Operations"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Efficiency" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Non_002dDeterministic-Programs" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Efficiency" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Indexing" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">22.3 Data-Base Operations</h2>
<hr>
<a name="Indexing"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Efficiency" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Data_002dBase-Operations" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Efficiency" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Profiling-1" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">22.4 Indexing</h2>
<hr>
<a name="Profiling-1"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Efficiency" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Indexing" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Efficiency" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">22.5 Profiling</h2>
<p>The indexation mechanism restricts the set of clauses to be tried in a
procedure by using information about the status of a selected argument of
the goal (in YAP, as in most compilers, the first argument).
This argument
is then used as a key, selecting a restricted set of a clauses from all the
clauses forming the procedure.
</p>
<p>As an example, the two clauses for concatenate:
</p>
<div class="example">
<pre class="example">concatenate([],L,L).
concatenate([H|T],A,[H|NT]) :- concatenate(T,A,NT).
</pre></div>
<p>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.
</p>
<p>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.
</p>
<p>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.
</p>
<p>An important side effect concerns the use of &quot;cut&quot;. In the above
example, some programmers would use a &quot;cut&quot; 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 &quot;cut&quot; would prevent some uses of
the procedure, like generating lists through backtracking. Of course, with
indexation the &quot;cut&quot; becomes useless: the choice point is not even created.
</p>
<p>Indexation is also very important for predicates with a large number
of clauses that are used like tables:
</p>
<div class="example">
<pre class="example">logician(aristoteles,greek).
logician(frege,german).
logician(russel,english).
logician(godel,german).
logician(whitehead,english).
</pre></div>
<p>An interpreter like C-Prolog, trying to answer the query:
</p>
<div class="example">
<pre class="example">?- logician(godel,X).
</pre></div>
<p>would blindly follow the standard Prolog strategy, trying first the
first clause, then the second, the third and finally finding the
relevant clause. Also, as there are some more clauses after the
important one, a choice point has to be created, even if we know the
next clauses will certainly fail. A &quot;cut&quot; 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.
</p>
<p> 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&rsquo;s head if not a variable. For instance, with the
following clauses,
</p>
<div class="example">
<pre class="example">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).
</pre></div>
<p>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.
</p>
<p>Some advice on how to take a good advantage of this mechanism:
</p>
<ul>
<li>
Try to make the first argument an input argument.
</li><li>
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.
</li><li>
Try to avoid predicates having a lot of clauses with the same key.
For instance, the procedure:
</li></ul>
<div class="example">
<pre class="example">type(n(mary),person).
type(n(john), person).
type(n(chair),object).
type(v(eat),active).
type(v(rest),passive).
</pre></div>
<p> becomes more efficient with:
</p>
<div class="example">
<pre class="example">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).
</pre></div>
<hr>
<a name="C_002dInterface"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Efficiency" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Profiling-1" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Manipulating-Terms" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="C-Language-interface-to-YAP"></a>
<h1 class="chapter">23 C Language interface to YAP</h1>
<p>YAP provides the user with the necessary facilities for writing
predicates in a language other than Prolog. Since, under Unix systems,
most language implementations are link-able to C, we will describe here
only the YAP interface to the C language.
</p>
<p>Before describing in full detail how to interface to C code, we will examine
a brief example.
</p>
<p>Assume the user requires a predicate <code>my_process_id(Id)</code> which succeeds
when <var>Id</var> unifies with the number of the process under which YAP is running.
</p>
<p>In this case we will create a <code>my_process.c</code> file containing the
C-code described below.
</p>
<div class="example">
<table class="cartouche" border="1"><tr><td>
<pre class="example">#include &quot;YAP/YAPInterface.h&quot;
static int my_process_id(void)
{
YAP_Term pid = YAP_MkIntTerm(getpid());
YAP_Term out = YAP_ARG1;
return(YAP_Unify(out,pid));
}
void init_my_predicates()
{
YAP_UserCPredicate(&quot;my_process_id&quot;,my_process_id,1);
}
</pre></td></tr></table>
</div>
<p>The commands to compile the above file depend on the operating
system. Under Linux (i386 and Alpha) you should use:
</p><div class="example">
<pre class="example"> gcc -c -shared -fPIC my_process.c
ld -shared -o my_process.so my_process.o
</pre></div>
<p>Under WIN32 in a MINGW/CYGWIN environment, using the standard
installation path you should use:
</p><div class="example">
<pre class="example"> gcc -mno-cygwin -I &quot;c:/Yap/include&quot; -c my_process.c
gcc -mno-cygwin &quot;c:/Yap/bin/yap.dll&quot; --shared -o my_process.dll my_process.o
</pre></div>
<p>Under WIN32 in a pure CYGWIN environment, using the standard
installation path, you should use:
</p><div class="example">
<pre class="example"> gcc -I/usr/local -c my_process.c
gcc -shared -o my_process.dll my_process.o /usr/local/bin/yap.dll
</pre></div>
<p>Under Solaris2 it is sufficient to use:
</p><div class="example">
<pre class="example"> gcc -fPIC -c my_process.c
</pre></div>
<p>Under SunOS it is sufficient to use:
</p><div class="example">
<pre class="example"> gcc -c my_process.c
</pre></div>
<p>Under Digital Unix you need to create a <code>so</code> file. Use:
</p><div class="example">
<pre class="example"> gcc tst.c -c -fpic
ld my_process.o -o my_process.so -shared -expect_unresolved '*'
</pre></div>
<p>and replace my <code>process.so</code> for my <code>process.o</code> in the
remainder of the example.
And could be loaded, under YAP, by executing the following Prolog goal
</p><div class="example">
<pre class="example"> load_foreign_files(['my_process'],[],init_my_predicates).
</pre></div>
<p>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.
</p>
<p>After loading that file the following Prolog goal
</p><div class="example">
<pre class="example"> my_process_id(N)
</pre></div>
<p>would unify N with the number of the process under which YAP is running.
</p>
<p>Having presented a full example, we will now examine in more detail the
contents of the C source code file presented above.
</p>
<p>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.
</p>
<p>The function <code>my_process_id</code> 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 <var>YAP_ARG1</var>,
<var>YAP_ARG2</var>, ..., <var>YAP_ARG16</var> or with <var>YAP_A</var>(<var>N</var>)
where <var>N</var> is the argument number (starting with 1). In the present
case the function uses just one local variable of type <code>YAP_Term</code>, the
type used for holding YAP terms, where the integer returned by the
standard unix function <code>getpid()</code> is stored as an integer term (the
conversion is done by <code>YAP_MkIntTerm(Int))</code>. Then it calls the
pre-defined routine <code>YAP_Unify(YAP_Term, YAP_Term)</code> which in turn returns an
integer denoting success or failure of the unification.
</p>
<p>The role of the procedure <code>init_my_predicates</code> is to make known to
YAP, by calling <code>YAP_UserCPredicate</code>, the predicates being
defined in the file. This is in fact why, in the example above,
<code>init_my_predicates</code> was passed as the third argument to
<code>load_foreign_files</code>.
</p>
<p>The rest of this appendix describes exhaustively how to interface C to YAP.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Primitives available to the C programmer
</td></tr>
<tr><td align="left" valign="top"><a href="#Unifying-Terms">23.2 Unification</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> How to Unify Two Prolog Terms
</td></tr>
<tr><td align="left" valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> From character arrays to Lists of codes and back
</td></tr>
<tr><td align="left" valign="top"><a href="#Memory-Allocation">23.4 Memory Allocation</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Stealing Memory From YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Controlling-Streams">23.5 Controlling YAP Streams from <code>C</code></a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Control How YAP sees Streams
</td></tr>
<tr><td align="left" valign="top"><a href="#Utility-Functions">23.6 Utility Functions in <code>C</code></a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> From character arrays to Lists of codes and back
</td></tr>
<tr><td align="left" valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> From C to YAP to C to YAP
</td></tr>
<tr><td align="left" valign="top"><a href="#Module-Manipulation-in-C">23.8 Module Manipulation in C</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Create and Test Modules from within C
</td></tr>
<tr><td align="left" valign="top"><a href="#Miscellaneous-C_002dFunctions">23.9 Miscellaneous C Functions</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Other Helpful Interface Functions
</td></tr>
<tr><td align="left" valign="top"><a href="#Writing-C">23.10 Writing predicates in C</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Writing Predicates in C
</td></tr>
<tr><td align="left" valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Save_0026Rest">23.12 Saving and Restoring</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#YAP4-Notes">23.13 Changes to the C-Interface in YAP4</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Changes in Foreign Predicates Interface
</td></tr>
</table>
<hr>
<a name="Manipulating-Terms"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Unifying-Terms" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Terms-1"></a>
<h2 class="section">23.1 Terms</h2>
<p>This section provides information about the primitives available to the C
programmer for manipulating Prolog terms.
</p>
<p>Several C typedefs are included in the header file <code>yap/YAPInterface.h</code> 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.
</p>
<p>The more important typedef is <var>YAP_Term</var> which is used to denote the
type of a Prolog term.
</p>
<p>Terms, from a point of view of the C-programmer, can be classified as
follows
</p><dl compact="compact">
<dt><i>uninstantiated variables</i></dt>
<dt><i>instantiated variables</i></dt>
<dt><i>integers</i></dt>
<dt><i>floating-point numbers</i></dt>
<dt><i>database references</i></dt>
<dt><i>atoms</i></dt>
<dt><i>pairs (lists)</i></dt>
<dt><i>compound terms</i></dt>
</dl>
<a name="index-YAP_005fIsVarTerm-_0028C_002dInterface-function_0029"></a>
<p>The primitive
</p><div class="example">
<pre class="example"> YAP_Bool YAP_IsVarTerm(YAP_Term <var>t</var>)
</pre></div>
<a name="index-YAP_005fIsNonVarTerm-_0028C_002dInterface-function_0029"></a>
<p>returns true iff its argument is an uninstantiated variable. Conversely the
primitive
</p><div class="example">
<pre class="example"> YAP_Bool YAP_NonVarTerm(YAP_Term <var>t</var>)
</pre></div>
<p>returns true iff its argument is not a variable.
</p>
<p>The user can create a new uninstantiated variable using the primitive
</p><div class="example">
<pre class="example"> YAP_Term YAP_MkVarTerm()
</pre></div>
<a name="index-YAP_005fIsIntTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fIsFloatTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fIsDBRefTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fIsAtomTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fIsPairTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fIsApplTerm-_0028C_002dInterface-function_0029"></a>
<p>The following primitives can be used to discriminate among the different types
of non-variable terms:
</p><div class="example">
<pre class="example"> YAP_Bool YAP_IsIntTerm(YAP_Term <var>t</var>)
YAP_Bool YAP_IsFloatTerm(YAP_Term <var>t</var>)
YAP_Bool YAP_IsDbRefTerm(YAP_Term <var>t</var>)
YAP_Bool YAP_IsAtomTerm(YAP_Term <var>t</var>)
YAP_Bool YAP_IsPairTerm(YAP_Term <var>t</var>)
YAP_Bool YAP_IsApplTerm(YAP_Term <var>t</var>)
</pre></div>
<p>Next, we mention the primitives that allow one to destruct and construct
terms. All the above primitives ensure that their result is
<i>dereferenced</i>, i.e. that it is not a pointer to another term.
</p>
<a name="index-YAP_005fMkIntTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fIntOfTerm-_0028C_002dInterface-function_0029"></a>
<p>The following primitives are provided for creating an integer term from an
integer and to access the value of an integer term.
</p><div class="example">
<pre class="example"> YAP_Term YAP_MkIntTerm(YAP_Int <var>i</var>)
YAP_Int YAP_IntOfTerm(YAP_Term <var>t</var>)
</pre></div>
<p>where <code>YAP_Int</code> 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.
</p>
<a name="index-YAP_005fMkFloatTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fFloatOfTerm-_0028C_002dInterface-function_0029"></a>
<p>The two following primitives play a similar role for floating-point terms
</p><div class="example">
<pre class="example"> YAP_Term YAP_MkFloatTerm(YAP_flt <var>double</var>)
YAP_flt YAP_FloatOfTerm(YAP_Term <var>t</var>)
</pre></div>
<p>where <code>flt</code> is a typedef for the appropriate C floating point type,
nowadays a <code>double</code>
</p>
<a name="index-YAP_005fIsBigNumTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fMkBigNumTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fBigNumOfTerm-_0028C_002dInterface-function_0029"></a>
<p>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.
</p><div class="example">
<pre class="example"> YAP_Bool YAP_IsBigNumTerm(YAP_Term <var>t</var>)
YAP_Term YAP_MkBigNumTerm(void *<var>b</var>)
void *YAP_BigNumOfTerm(YAP_Term <var>t</var>, void *<var>b</var>)
</pre></div>
<p>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 <code>void *</code> will be a cast for <code>mpz_t</code>. Notice
that <code>YAP_BigNumOfTerm</code> requires the number to be already
initialised. As an example, we show how to print a bignum:
</p>
<div class="example">
<pre class="example">static int
p_print_bignum(void)
{
mpz_t mz;
if (!YAP_IsBigNumTerm(YAP_ARG1))
return FALSE;
mpz_init(mz);
YAP_BigNumOfTerm(YAP_ARG1, mz);
gmp_printf(&quot;Shows up as %Zd\n&quot;, mz);
mpz_clear(mz);
return TRUE;
}
</pre></div>
<p>Currently, no primitives are supplied to users for manipulating data base
references.
</p>
<a name="index-YAP_005fMkAtomTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fAtomOfTerm-_0028C_002dInterface-function_0029"></a>
<p>A special typedef <code>YAP_Atom</code> is provided to describe Prolog
<i>atoms</i> (symbolic constants). The two following primitives can be used
to manipulate atom terms
</p><div class="example">
<pre class="example"> YAP_Term YAP_MkAtomTerm(YAP_Atom at)
YAP_Atom YAP_AtomOfTerm(YAP_Term <var>t</var>)
</pre></div>
<a name="index-YAP_005fLookupAtom-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fFullLookupAtom-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fAtomName-_0028C_002dInterface-function_0029"></a>
<p>The following primitives are available for associating atoms with their
names
</p><div class="example">
<pre class="example"> YAP_Atom YAP_LookupAtom(char * <var>s</var>)
YAP_Atom YAP_FullLookupAtom(char * <var>s</var>)
char *YAP_AtomName(YAP_Atom <var>t</var>)
</pre></div>
<p>The function <code>YAP_LookupAtom</code> looks up an atom in the standard hash
table. The function <code>YAP_FullLookupAtom</code> will also search if the
atom had been &quot;hidden&quot;: this is useful for system maintenance from C
code. The functor <code>YAP_AtomName</code> returns a pointer to the string
for the atom.
</p>
<a name="index-YAP_005fIsWideAtom-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fLookupWideAtom-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fWideAtomName-_0028C_002dInterface-function_0029"></a>
<p>The following primitives handle constructing atoms from strings with
wide characters, and vice-versa:
</p><div class="example">
<pre class="example"> YAP_Atom YAP_LookupWideAtom(wchar_t * <var>s</var>)
wchar_t *YAP_WideAtomName(YAP_Atom <var>t</var>)
</pre></div>
<a name="index-YAP_005fIsIsWideAtom-_0028C_002dInterface-function_0029"></a>
<p>The following primitive tells whether an atom needs wide atoms in its
representation:
</p><div class="example">
<pre class="example"> int YAP_IsWideAtom(YAP_Atom <var>t</var>)
</pre></div>
<a name="index-YAP_005fAtomNameLength-_0028C_002dInterface-function_0029"></a>
<p>The following primitive can be used to obtain the size of an atom in a
representation-independent way:
</p><div class="example">
<pre class="example"> int YAP_AtomNameLength(YAP_Atom <var>t</var>)
</pre></div>
<a name="index-YAP_005fAtomGetHold--_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fAtomReleaseHold--_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fAGCHook--_0028C_002dInterface-function_0029"></a>
<p>The next routines give users some control over the atom
garbage collector. They allow the user to guarantee that an atom is not
to be garbage collected (this is important if the atom is hold
externally to the Prolog engine, allow it to be collected, and call a
hook on garbage collection:
</p><div class="example">
<pre class="example"> int YAP_AtomGetHold(YAP_Atom <var>at</var>)
int YAP_AtomReleaseHold(YAP_Atom <var>at</var>)
int YAP_AGCRegisterHook(YAP_AGC_hook <var>f</var>)
YAP_Term YAP_TailOfTerm(YAP_Term <var>t</var>)
</pre></div>
<a name="index-YAP_005fMkPairTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fMkNewPairTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fHeadOfTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fTailOfTerm-_0028C_002dInterface-function_0029"></a>
<p>A <i>pair</i> is a Prolog term which consists of a tuple of two Prolog
terms designated as the <i>head</i> and the <i>tail</i> of the term. Pairs are
most often used to build <em>lists</em>. The following primitives can be
used to manipulate pairs:
</p><div class="example">
<pre class="example"> YAP_Term YAP_MkPairTerm(YAP_Term <var>Head</var>, YAP_Term <var>Tail</var>)
YAP_Term YAP_MkNewPairTerm(void)
YAP_Term YAP_HeadOfTerm(YAP_Term <var>t</var>)
YAP_Term YAP_TailOfTerm(YAP_Term <var>t</var>)
</pre></div>
<p>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.
</p>
<a name="index-YAP_005fMkApplTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fMkNewApplTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fArgOfTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fArgsOfTerm-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fFunctorOfTerm-_0028C_002dInterface-function_0029"></a>
<p>A <i>compound</i> term consists of a <i>functor</i> and a sequence of terms with
length equal to the <i>arity</i> of the functor. A functor, described in C by
the typedef <code>Functor</code>, consists of an atom and of an integer.
The following primitives were designed to manipulate compound terms and
functors
</p><div class="example">
<pre class="example"> YAP_Term YAP_MkApplTerm(YAP_Functor <var>f</var>, unsigned long int <var>n</var>, YAP_Term[] <var>args</var>)
YAP_Term YAP_MkNewApplTerm(YAP_Functor <var>f</var>, int <var>n</var>)
YAP_Term YAP_ArgOfTerm(int argno,YAP_Term <var>ts</var>)
YAP_Term *YAP_ArgsOfTerm(YAP_Term <var>ts</var>)
YAP_Functor YAP_FunctorOfTerm(YAP_Term <var>ts</var>)
</pre></div>
<p>The <code>YAP_MkApplTerm</code> function constructs a new term, with functor
<var>f</var> (of arity <var>n</var>), and using an array <var>args</var> of <var>n</var>
terms with <var>n</var> equal to the arity of the
functor. <code>YAP_MkNewApplTerm</code> builds up a compound term whose
arguments are unbound variables. <code>YAP_ArgOfTerm</code> gives an argument
to a compound term. <code>argno</code> should be greater or equal to 1 and
less or equal to the arity of the functor. <code>YAP_ArgsOfTerm</code>
returns a pointer to an array of arguments.
</p>
<p>YAP allows one to manipulate the functors of compound term. The function
<code>YAP_FunctorOfTerm</code> allows one to obtain a variable of type
<code>YAP_Functor</code> with the functor to a term. The following functions
then allow one to construct functors, and to obtain their name and arity.
</p>
<a name="index-YAP_005fMkFunctor-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fNameOfFunctor-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fArityOfFunctor-_0028C_002dInterface-function_0029"></a>
<div class="example">
<pre class="example"> YAP_Functor YAP_MkFunctor(YAP_Atom <var>a</var>,unsigned long int <var>arity</var>)
YAP_Atom YAP_NameOfFunctor(YAP_Functor <var>f</var>)
YAP_Int YAP_ArityOfFunctor(YAP_Functor <var>f</var>)
</pre></div>
<p>Note that the functor is essentially a pair formed by an atom, and
arity.
</p>
<hr>
<a name="Unifying-Terms"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Manipulating-Terms" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Manipulating-Strings" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Unification"></a>
<h2 class="section">23.2 Unification</h2>
<a name="index-YAP_005fUnify-_0028C_002dInterface-function_0029"></a>
<p>YAP provides a single routine to attempt the unification of two Prolog
terms. The routine may succeed or fail:
</p><div class="example">
<pre class="example"> Int YAP_Unify(YAP_Term <var>a</var>, YAP_Term <var>b</var>)
</pre></div>
<p>The routine attempts to unify the terms <var>a</var> and
<var>b</var> returning <code>TRUE</code> if the unification succeeds and <code>FALSE</code>
otherwise.
</p>
<hr>
<a name="Manipulating-Strings"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Unifying-Terms" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Memory-Allocation" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Strings-1"></a>
<h2 class="section">23.3 Strings</h2>
<a name="index-YAP_005fStringToBuffer-_0028C_002dInterface-function_0029"></a>
<p>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
</p><div class="example">
<pre class="example"> int YAP_StringToBuffer(YAP_Term <var>String</var>, char *<var>buf</var>, unsigned int <var>bufsize</var>)
</pre></div>
<p>The routine copies the list of character codes <var>String</var> to a
previously allocated buffer <var>buf</var>. The string including a
terminating null character must fit in <var>bufsize</var> characters,
otherwise the routine will simply fail. The <var>StringToBuffer</var> routine
fails and generates an exception if <var>String</var> is not a valid string.
</p>
<a name="index-YAP_005fBufferToString-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fNBufferToString-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fWideBufferToString-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fNWideBufferToString-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fBufferToAtomList-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fNBufferToAtomList-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fWideBufferToAtomList-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fNWideBufferToAtomList-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fBufferToDiffList-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fNBufferToDiffList-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fWideBufferToDiffList-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fNWideBufferToDiffList-_0028C_002dInterface-function_0029"></a>
<p>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, to a
difference list, or to a list of
character atoms. The routines work either on strings of characters or
strings of wide characters:
</p><div class="example">
<pre class="example"> YAP_Term YAP_BufferToString(char *<var>buf</var>)
YAP_Term YAP_NBufferToString(char *<var>buf</var>, size_t <var>len</var>)
YAP_Term YAP_WideBufferToString(wchar_t *<var>buf</var>)
YAP_Term YAP_NWideBufferToString(wchar_t *<var>buf</var>, size_t <var>len</var>)
YAP_Term YAP_BufferToAtomList(char *<var>buf</var>)
YAP_Term YAP_NBufferToAtomList(char *<var>buf</var>, size_t <var>len</var>)
YAP_Term YAP_WideBufferToAtomList(wchar_t *<var>buf</var>)
YAP_Term YAP_NWideBufferToAtomList(wchar_t *<var>buf</var>, size_t <var>len</var>)
</pre></div>
<p>Users are advised to use the <var>N</var> version of the routines. Otherwise,
the user-provided string must include a terminating null character.
</p>
<a name="index-YAP_005fReadBuffer-_0028C_002dInterface-function_0029"></a>
<p>The C-interface function calls the parser on a sequence of characters
stored at <var>buf</var> and returns the resulting term.
</p><div class="example">
<pre class="example"> YAP_Term YAP_ReadBuffer(char *<var>buf</var>,YAP_Term *<var>error</var>)
</pre></div>
<p>The user-provided string must include a terminating null
character. Syntax errors will cause returning <code>FALSE</code> and binding
<var>error</var> to a Prolog term.
</p>
<hr>
<a name="Memory-Allocation"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Manipulating-Strings" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Controlling-Streams" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Memory-Allocation-1"></a>
<h2 class="section">23.4 Memory Allocation</h2>
<a name="index-YAP_005fAllocSpaceFromYAP-_0028C_002dInterface-function_0029"></a>
<p>The next routine can be used to ask space from the Prolog data-base:
</p><div class="example">
<pre class="example"> void *YAP_AllocSpaceFromYAP(int <var>size</var>)
</pre></div>
<p>The routine returns a pointer to a buffer allocated from the code area,
or <code>NULL</code> if sufficient space was not available.
</p>
<a name="index-YAP_005fFreeSpaceFromYAP-_0028C_002dInterface-function_0029"></a>
<p>The space allocated with <code>YAP_AllocSpaceFromYAP</code> can be released
back to YAP by using:
</p><div class="example">
<pre class="example"> void YAP_FreeSpaceFromYAP(void *<var>buf</var>)
</pre></div>
<p>The routine releases a buffer allocated from the code area. The system
may crash if <code>buf</code> is not a valid pointer to a buffer in the code
area.
</p>
<hr>
<a name="Controlling-Streams"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Memory-Allocation" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Utility-Functions" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Controlling-YAP-Streams-from-C"></a>
<h2 class="section">23.5 Controlling YAP Streams from <code>C</code></h2>
<a name="index-YAP_005fStreamToFileNo-_0028C_002dInterface-function_0029"></a>
<p>The C-Interface also provides the C-application with a measure of
control over the YAP Input/Output system. The first routine allows one
to find a file number given a current stream:
</p><div class="example">
<pre class="example"> int YAP_StreamToFileNo(YAP_Term <var>stream</var>)
</pre></div>
<p>This function gives the file descriptor for a currently available
stream. Note that null streams and in memory streams do not have
corresponding open streams, so the routine will return a
negative. Moreover, YAP will not be aware of any direct operations on
this stream, so information on, say, current stream position, may become
stale.
</p>
<a name="index-YAP_005fCloseAllOpenStreams-_0028C_002dInterface-function_0029"></a>
<p>A second routine that is sometimes useful is:
</p><div class="example">
<pre class="example"> void YAP_CloseAllOpenStreams(void)
</pre></div>
<p>This routine closes the YAP Input/Output system except for the first
three streams, that are always associated with the three standard Unix
streams. It is most useful if you are doing <code>fork()</code>.
</p>
<a name="index-YAP_005fFlushAllStreams-_0028C_002dInterface-function_0029"></a>
<p>Last, one may sometimes need to flush all streams:
</p><div class="example">
<pre class="example"> void YAP_CloseAllOpenStreams(void)
</pre></div>
<p>It is also useful before you do a <code>fork()</code>, or otherwise you may
have trouble with unflushed output.
</p>
<a name="index-YAP_005fOpenStream-_0028C_002dInterface-function_0029"></a>
<p>The next routine allows a currently open file to become a stream. The
routine receives as arguments a file descriptor, the true file name as a
string, an atom with the user name, and a set of flags:
</p><div class="example">
<pre class="example"> void YAP_OpenStream(void *<var>FD</var>, char *<var>name</var>, YAP_Term <var>t</var>, int <var>flags</var>)
</pre></div>
<p>The available flags are <code>YAP_INPUT_STREAM</code>,
<code>YAP_OUTPUT_STREAM</code>, <code>YAP_APPEND_STREAM</code>,
<code>YAP_PIPE_STREAM</code>, <code>YAP_TTY_STREAM</code>, <code>YAP_POPEN_STREAM</code>,
<code>YAP_BINARY_STREAM</code>, and <code>YAP_SEEKABLE_STREAM</code>. By default, the
stream is supposed to be at position 0. The argument <var>name</var> gives
the name by which YAP should know the new stream.
</p>
<hr>
<a name="Utility-Functions"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Controlling-Streams" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Calling-YAP-From-C" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Utility-Functions-in-C"></a>
<h2 class="section">23.6 Utility Functions in <code>C</code></h2>
<p>The C-Interface provides the C-application with a a number of utility
functions that are useful.
</p>
<a name="index-YAP_005fRecord-_0028C_002dInterface-function_0029"></a>
<p>The first provides a way to insert a term into the data-base
</p><div class="example">
<pre class="example"> void *YAP_Record(YAP_Term <var>t</var>)
</pre></div>
<p>This function returns a pointer to a copy of the term in the database
(or to <tt>NULL</tt> if the operation fails.
</p>
<a name="index-YAP_005fRecorded-_0028C_002dInterface-function_0029"></a>
<p>The next functions provides a way to recover the term from the data-base:
</p><div class="example">
<pre class="example"> YAP_Term YAP_Recorded(void *<var>handle</var>)
</pre></div>
<p>Notice that the semantics are the same as for <code>recorded/3</code>: this
function creates a new copy of the term in the stack, with fresh
variables. The function returns <tt>0L</tt> if it cannot create a new term.
</p>
<a name="index-YAP_005fErase-_0028C_002dInterface-function_0029"></a>
<p>Last, the next function allows one to recover space:
</p><div class="example">
<pre class="example"> int YAP_Erase(void *<var>handle</var>)
</pre></div>
<p>Notice that any accesses using <var>handle</var> after this operation may
lead to a crash.
</p>
<p>The following functions are often required to compare terms.
</p>
<a name="index-YAP_005fExactlyEqual-_0028C_002dInterface-function_0029"></a>
<p>The first function succeeds if two terms are actually the same term, as
<code>==/2</code>:
</p><div class="example">
<pre class="example"> int YAP_ExactlyEqual(YAP_Term t1, YAP_Term t2)
</pre></div>
<p>The second function succeeds if two terms are variant terms, and returns
0 otherwise, as
<code>=/=2</code>:
</p><div class="example">
<pre class="example"> int YAP_Variant(YAP_Term t1, YAP_Term t2)
</pre></div>
<p>The second function computes a hash function for a term, as in
<code>term_hash/4</code>.
</p><div class="example">
<pre class="example"> YAP_Int YAP_TermHash(YAP_Term t, YAP_Int range, YAP_Int depth, int ignore_variables));
</pre></div>
<p>The first three arguments follow <code>term_has/4</code>. The last argument
indicates what to do if we find a variable: if <code>0</code> fail, otherwise
ignore the variable.
</p>
<hr>
<a name="Calling-YAP-From-C"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Utility-Functions" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Module-Manipulation-in-C" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="From-C-back-to-Prolog"></a>
<h2 class="section">23.7 From <code>C</code> back to Prolog</h2>
<a name="index-YAP_005fRunGoal-_0028C_002dInterface-function_0029"></a>
<p>There are several ways to call Prolog code from C-code. By default, the
<code>YAP_RunGoal()</code> should be used for this task. It assumes the engine
has been initialised before:
</p>
<div class="example">
<pre class="example"> YAP_RunGoal(YAP_Term Goal)
</pre></div>
<p>Execute query <var>Goal</var> and return 1 if the query succeeds, and 0
otherwise. The predicate returns 0 if failure, otherwise it will return
an <var>YAP_Term</var>.
</p>
<p>Quite often, one wants to run a query once. In this case you should use
<var>Goal</var>:
</p><div class="example">
<pre class="example"> YAP_RunGoalOnce(YAP_Term Goal)
</pre></div>
<p>The <code>YAP_RunGoal()</code> function makes sure to recover stack space at
the end of execution.
</p>
<p>Prolog terms are pointers: a problem users often find is that the term
<var>Goal</var> may actually <em>be moved around</em> during the execution of
<code>YAP_RunGoal()</code>, due to garbage collection or stack shifting. If
this is possible, <var>Goal</var> will become invalid after executing
<code>YAP_RunGoal()</code>. In this case, it is a good idea to save <var>Goal</var>
<em>slots</em>, as shown next:
</p>
<div class="example">
<pre class="example"> long sl = YAP_InitSlot(scoreTerm);
out = YAP_RunGoal(t);
t = YAP_GetFromSlot(sl);
YAP_RecoverSlots(1);
if (out == 0) return FALSE;
</pre></div>
<p>Slots are safe houses in the stack, the garbage collector and the stack
shifter know about them and make sure they have correct values. In this
case, we use a slot to preserve <var>t</var> during the execution of
<code>YAP_RunGoal</code>. When the execution of <var>t</var> is over we read the
(possibly changed) value of <var>t</var> back from the slot <var>sl</var> and tell
YAP that the slot <var>sl</var> is not needed and can be given back to the
system. The slot functions are as follows:
</p>
<dl compact="compact">
<dt><code>YAP_Int YAP_NewSlots(int <var>NumberOfSlots</var>)</code></dt>
<dd><a name="index-YAP_005fNewSlots-_0028C_002dInterface-function_0029"></a>
<p>Allocate <var>NumberOfSlots</var> from the stack and return an handle to the
last one. The other handle can be obtained by decrementing the handle.
</p>
</dd>
<dt><code>YAP_Int YAP_CurrentSlot(void)</code></dt>
<dd><a name="index-YAP_005fCurrentSlot-_0028C_002dInterface-function_0029"></a>
<p>Return a handle to the system&rsquo;s default slot.
</p>
</dd>
<dt><code>YAP_Int YAP_InitSlot(YAP_Term <var>t</var>)</code></dt>
<dd><a name="index-YAP_005fInitSlot-_0028C_002dInterface-function_0029"></a>
<p>Create a new slot, initialise it with <var>t</var>, and return a handle to
this slot, that also becomes the current slot.
</p>
</dd>
<dt><code>YAP_Term *YAP_AddressFromSlot(YAP_Int <var>slot</var>)</code></dt>
<dd><a name="index-YAP_005fAddressFromSlot-_0028C_002dInterface-function_0029"></a>
<p>Return the address of slot <var>slot</var>: please use with care.
</p>
</dd>
<dt><code>void YAP_PutInSlot(YAP_Int <var>slot</var>, YAP_Term <var>t</var>)</code></dt>
<dd><a name="index-YAP_005fPutInSlot-_0028C_002dInterface-function_0029"></a>
<p>Set the contents of slot <var>slot</var> to <var>t</var>.
</p>
</dd>
<dt><code>int YAP_RecoverSlots(int <var>HowMany</var>)</code></dt>
<dd><a name="index-YAP_005fRecoverSlots-_0028C_002dInterface-function_0029"></a>
<p>Recover the space for <var>HowMany</var> slots: these will include the
current default slot. Fails if no such slots exist.
</p>
</dd>
<dt><code>YAP_Int YAP_ArgsToSlots(int <var>HowMany</var>)</code></dt>
<dd><a name="index-YAP_005fArgsToSlots-_0028C_002dInterface-function_0029"></a>
<p>Store the current first <var>HowMany</var> arguments in new slots.
</p>
</dd>
<dt><code>void YAP_SlotsToArgs(int <var>HowMany</var>, YAP_Int <var>slot</var>)</code></dt>
<dd><a name="index-YAP_005fSlotsToArgs-_0028C_002dInterface-function_0029"></a>
<p>Set the first <var>HowMany</var> arguments to the <var>HowMany</var> slots
starting at <var>slot</var>.
</p></dd>
</dl>
<p>The following functions complement <var>YAP_RunGoal</var>:
</p><dl compact="compact">
<dd><a name="index-YAP_005fRestartGoal-_0028C_002dInterface-function_0029"></a>
<p>Look for the next solution to the current query by forcing YAP to
backtrack to the latest goal. Notice that slots allocated since the last
<code>YAP_RunGoal</code> will become invalid.
</p>
</dd>
<dt><code><code>int</code> YAP_Reset(<code>void</code>)</code></dt>
<dd><a name="index-YAP_005fReset-_0028C_002dInterface-function_0029"></a>
<p>Reset execution environment (similar to the <code>abort/0</code>
built-in). This is useful when you want to start a new query before
asking all solutions to the previous query.
</p>
</dd>
<dt><code><code>int</code> YAP_ShutdownGoal(<code>int backtrack</code>)</code></dt>
<dd><a name="index-YAP_005fShutdownGoal-_0028C_002dInterface-function_0029"></a>
<p>Clean up the current goal. If
<code>backtrack</code> is true, stack space will be recovered and bindings
will be undone. In both cases, any slots allocated since the goal was
created will become invalid.
</p>
</dd>
<dt><code><code>YAP_Bool</code> YAP_GoalHasException(<code>YAP_Term *tp</code>)</code></dt>
<dd><a name="index-YAP_005fRestartGoal-_0028C_002dInterface-function_0029-1"></a>
<p>Check if the last goal generated an exception, and if so copy it to the
space pointed to by <var>tp</var>
</p>
</dd>
<dt><code><code>void</code> YAP_ClearExceptions(<code>void</code>)</code></dt>
<dd><a name="index-YAP_005fClearExceptions-_0028C_002dInterface-function_0029"></a>
<p>Reset any exceptions left over by the system.
</p></dd>
</dl>
<p>The <var>YAP_RunGoal</var> interface is designed to be very robust, but may
not be the most efficient when repeated calls to the same goal are made
and when there is no interest in processing exception. The
<var>YAP_EnterGoal</var> interface should have lower-overhead:
</p><dl compact="compact">
<dt><code><code>YAP_PredEntryPtr</code> YAP_FunctorToPred(<code>YAP_Functor</code> <var>f</var>,</code></dt>
<dd><a name="index-YAP_005fFunctorToPred-_0028C_002dInterface-function_0029"></a>
<p>Return the predicate whose main functor is <var>f</var>.
</p>
</dd>
<dt><code><code>YAP_PredEntryPtr</code> YAP_AtomToPred(<code>YAP_Atom</code> <var>at</var>,</code></dt>
<dd><a name="index-YAP_005fAtomToPred-_0028C_002dInterface-function_0029"></a>
<p>Return the arity 0 predicate whose name is <var>at</var>.
</p>
</dd>
<dt><code><code>YAP_Bool</code> YAP_EnterGoal(<code>YAP_PredEntryPtr</code> <var>pe</var>,</code></dt>
<dd><p><code>YAP_Term *</code> <var>array</var>, <code>YAP_dogoalinfo *</code> <var>infop</var>)
<a name="index-YAP_005fEnterGoal-_0028C_002dInterface-function_0029"></a>
Execute a query for predicate <var>pe</var>. The query is given as an
array of terms <var>Array</var>. <var>infop</var> is the address of a goal
handle that can be used to backtrack and to recover space. Succeeds if
a solution was found.
</p>
<p>Notice that you cannot create new slots if an YAP_EnterGoal goal is open.
</p>
</dd>
<dt><code><code>YAP_Bool</code> YAP_RetryGoal(<code>YAP_dogoalinfo *</code> <var>infop</var>)</code></dt>
<dd>
<a name="index-YAP_005fRetryGoal-_0028C_002dInterface-function_0029"></a>
<p>Backtrack to a query created by <code>YAP_EnterGoal</code>. The query is
given by the handle <var>infop</var>. Returns whether a new solution could
be be found.
</p>
</dd>
<dt><code><code>YAP_Bool</code> YAP_LeaveGoal(<code>YAP_Bool</code> <var>backtrack</var>,</code></dt>
<dd><p><code>YAP_dogoalinfo *</code> <var>infop</var>)
<a name="index-YAP_005fLeaveGoal-_0028C_002dInterface-function_0029"></a>
Exit a query query created by <code>YAP_EnterGoal</code>. If
<code>backtrack</code> is <code>TRUE</code>, variable bindings are undone and Heap
space is recovered. Otherwise, only stack space is recovered, ie,
<code>LeaveGoal</code> executes a cut.
</p></dd>
</dl>
<p>Next, follows an example of how to use <code>YAP_EnterGoal</code>:
</p><div class="example">
<pre class="example">void
runall(YAP_Term g)
{
YAP_dogoalinfo goalInfo;
YAP_Term *goalArgs = YAP_ArraysOfTerm(g);
YAP_Functor *goalFunctor = YAP_FunctorOfTerm(g);
YAP_PredEntryPtr goalPred = YAP_FunctorToPred(goalFunctor);
result = YAP_EnterGoal( goalPred, goalArgs, &amp;goalInfo );
while (result)
result = YAP_RetryGoal( &amp;goalInfo );
YAP_LeaveGoal(TRUE, &amp;goalInfo);
}
</pre></div>
<a name="index-YAP_005fCallProlog-_0028C_002dInterface-function_0029"></a>
<p>YAP allows calling a <strong>new</strong> Prolog interpreter from <code>C</code>. One
way is to first construct a goal <code>G</code>, and then it is sufficient to
perform:
</p><div class="example">
<pre class="example"> YAP_Bool YAP_CallProlog(YAP_Term <var>G</var>)
</pre></div>
<p>the result will be <code>FALSE</code>, if the goal failed, or <code>TRUE</code>, if
the goal succeeded. In this case, the variables in <var>G</var> will store
the values they have been unified with. Execution only proceeds until
finding the first solution to the goal, but you can call
<code>findall/3</code> or friends if you need all the solutions.
</p>
<p>Notice that during execution, garbage collection or stack shifting may
have moved the terms
</p>
<hr>
<a name="Module-Manipulation-in-C"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Calling-YAP-From-C" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Miscellaneous-C_002dFunctions" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Module-Manipulation-in-C-1"></a>
<h2 class="section">23.8 Module Manipulation in C</h2>
<p>YAP allows one to create a new module from C-code. To create the new
code it is sufficient to call:
</p><div class="example">
<pre class="example"> YAP_Module YAP_CreateModule(YAP_Atom <var>ModuleName</var>)
</pre></div>
<p>Notice that the new module does not have any predicates associated and
that it is not the current module. To find the current module, you can call:
</p><div class="example">
<pre class="example"> YAP_Module YAP_CurrentModule()
</pre></div>
<p>Given a module, you may want to obtain the corresponding name. This is
possible by using:
</p><div class="example">
<pre class="example"> YAP_Term YAP_ModuleName(YAP_Module mod)
</pre></div>
<p>Notice that this function returns a term, and not an atom. You can
<code>YAP_AtomOfTerm</code> to extract the corresponding Prolog atom.
</p>
<hr>
<a name="Miscellaneous-C_002dFunctions"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Module-Manipulation-in-C" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Writing-C" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Miscellaneous-C-Functions"></a>
<h2 class="section">23.9 Miscellaneous C Functions</h2>
<dl compact="compact">
<dt><code><code>int</code> YAP_SetYAPFlag(<code>yap_flag_t flag, int value</code>)</code></dt>
<dd><a name="index-YAP_005fSetYAPFlag-_0028C_002dInterface-function_0029"></a>
<p>This function allows setting some YAP flags from <code>C</code> .Currently,
only two boolean flags are accepted: <code>YAPC_ENABLE_GC</code> and
<code>YAPC_ENABLE_AGC</code>. The first enables/disables the standard garbage
collector, the second does the same for the atom garbage collector.&lsquo;
</p>
</dd>
<dt><code><code>int</code> YAP_HaltRegisterHook(<code>YAP_halt_hook f, void *closure</code>)</code></dt>
<dd><a name="index-YAP_005fHaltRegisterHook-_0028C_002dInterface-function_0029"></a>
<p>Register the function <var>f</var> to be called if YAP is halted. The
function is called with two arguments: the exit code of the process (<code>0</code>
if this cannot be determined on your operating system) and the closure
argument <var>closure</var>.
</p></dd>
</dl>
<hr>
<a name="Writing-C"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Miscellaneous-C_002dFunctions" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Objects" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Writing-predicates-in-C"></a>
<h2 class="section">23.10 Writing predicates in C</h2>
<p>We will distinguish two kinds of predicates:
</p><dl compact="compact">
<dt><i><i>deterministic</i> predicates which either fail or succeed but are not</i></dt>
<dd><p>backtrackable, like the one in the introduction;
</p></dd>
<dt><i><i>backtrackable</i></i></dt>
<dd><p>predicates which can succeed more than once.
</p></dd>
</dl>
<a name="index-YAP_005fUserCPredicate-_0028C_002dInterface-function_0029"></a>
<p>The first kind of predicates should be implemented as a C function with
no arguments which should return zero if the predicate fails and a
non-zero value otherwise. The predicate should be declared to
YAP, in the initialization routine, with a call to
</p><div class="example">
<pre class="example"> void YAP_UserCPredicate(char *<var>name</var>, YAP_Bool *<var>fn</var>(), unsigned long int <var>arity</var>);
</pre></div>
<p>where <var>name</var> is the name of the predicate, <var>fn</var> is the C function
implementing the predicate and <var>arity</var> is its arity.
</p>
<a name="index-YAP_005fUserBackCPredicate-_0028C_002dInterface-function_002c-deprecated_0029"></a>
<a name="index-YAP_005fUserBackCutCPredicate-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fPRESERVE_005fDATA-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fPRESERVED_005fDATA-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fcutsucceed-_0028C_002dInterface-function_0029"></a>
<a name="index-YAP_005fcutfail-_0028C_002dInterface-function_0029"></a>
<p>For the second kind of predicates we need three C functions. The first one
is called when the predicate is first activated; the second one
is called on backtracking to provide (possibly) other solutions; the
last one is called on pruning. Note
also that we normally also need to preserve some information to find out
the next solution.
</p>
<p>In fact the role of the two functions can be better understood from the
following Prolog definition
</p><div class="example">
<pre class="example"> p :- start.
p :- repeat,
continue.
</pre></div>
<p>where <code>start</code> and <code>continue</code> correspond to the two C functions
described above.
</p>
<p>As an example we will consider implementing in C a predicate <code>n100(N)</code>
which, when called with an instantiated argument should succeed if that
argument is a numeral less or equal to 100, and, when called with an
uninstantiated argument, should provide, by backtracking, all the positive
integers less or equal to 100.
</p>
<p> To do that we first declare a structure, which can only consist
of Prolog terms, containing the information to be preserved on backtracking
and a pointer variable to a structure of that type.
</p>
<div class="example">
<pre class="example">#include &quot;YAPInterface.h&quot;
static int start_n100(void);
static int continue_n100(void);
typedef struct {
YAP_Term next_solution; /* the next solution */
} n100_data_type;
n100_data_type *n100_data;
</pre></div>
<p>We now write the <code>C</code> function to handle the first call:
</p>
<div class="example">
<pre class="example">static int start_n100(void)
{
YAP_Term t = YAP_ARG1;
YAP_PRESERVE_DATA(n100_data,n100_data_type);
if(YAP_IsVarTerm(t)) {
n100_data-&gt;next_solution = YAP_MkIntTerm(0);
return continue_n100();
}
if(!YAP_IsIntTerm(t) || YAP_IntOfTerm(t)&lt;0 || YAP_IntOfTerm(t)&gt;100) {
YAP_cut_fail();
} else {
YAP_cut_succeed();
}
}
</pre></div>
<p>The routine starts by getting the dereference value of the argument.
The call to <code>YAP_PRESERVE_DATA</code> 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 <code>YAP_PRESERVE_DATA</code> once, so often we will
want the variable to be a structure.
</p>
<p>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 <code>
continue_n100</code> to provide that solution.
</p>
<p>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 <code>YAP_cut_succeed</code>, or
otherwise exits with <code>YAP_cut_fail</code> denoting failure.
</p>
<p>The reason for using for using the functions <code>YAP_cut_succeed</code> and
<code>YAP_cut_fail</code> 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 <code>continue_n100</code> would be
called to provide additional solutions.
</p>
<p>The code required for the second function is
</p><div class="example">
<pre class="example">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-&gt;next_solution);
if( n == 100) {
t = YAP_MkIntTerm(n);
YAP_Unify(sol,t);
YAP_cut_succeed();
}
else {
YAP_Unify(sol,n100_data-&gt;next_solution);
n100_data-&gt;next_solution = YAP_MkIntTerm(n+1);
return(TRUE);
}
}
</pre></div>
<p>Note that again the macro <code>YAP_PRESERVED_DATA</code> 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 <code>YAP_cut_succeed</code> in order to cut any further
backtracking. If this is not the last solution then we save the value
for the next solution in the data structure and exit normally with 1
denoting success. Note also that in any of the two cases we use the
function <code>YAP_unify</code> to bind the argument of the call to the value
saved in <code> n100_state-&gt;next_solution</code>.
</p>
<p>Note also that the only correct way to signal failure in a backtrackable
predicate is to use the <code>YAP_cut_fail</code> macro.
</p>
<p>Backtrackable predicates should be declared to YAP, in a way
similar to what happened with deterministic ones, but using instead a
call to
</p><div class="example">
<pre class="example"> void YAP_UserBackCutCPredicate(char *<var>name</var>,
int *<var>init</var>(), int *<var>cont</var>(), int *<var>cut</var>(),
unsigned long int <var>arity</var>, unsigned int <var>sizeof</var>);
</pre></div>
<p>where <var>name</var> is a string with the name of the predicate, <var>init</var>,
<var>cont</var>, <var>cut</var> are the C functions used to start, continue and
when pruning the execution of the predicate, <var>arity</var> is the
predicate arity, and <var>sizeof</var> is the size of the data to be
preserved in the stack. In this example, we would have something like
</p>
<div class="example">
<pre class="example">void
init_n100(void)
{
YAP_UserBackCutCPredicate(&quot;n100&quot;, start_n100, continue_n100, NULL, 1, 1);
}
</pre></div>
<p>Notice that we do not actually need to do anything on receiving a cut in
this case.
</p>
<hr>
<a name="Loading-Objects"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Writing-C" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Save_0026Rest" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Loading-Object-Files"></a>
<h2 class="section">23.11 Loading Object Files</h2>
<p>The primitive predicate
</p><div class="example">
<pre class="example"> load_foreign_files(<var>Files</var>,<var>Libs</var>,<var>InitRoutine</var>)
</pre></div>
<p>should be used, from inside YAP, to load object files produced by the C
compiler. The argument <var>ObjectFiles</var> should be a list of atoms
specifying the object files to load, <var>Libs</var> is a list (possibly
empty) of libraries to be passed to the unix loader (<code>ld</code>) and
InitRoutine is the name of the C routine (to be called after the files
are loaded) to perform the necessary declarations to YAP of the
predicates defined in the files.
</p>
<p>YAP will search for <var>ObjectFiles</var> in the current directory first. If
it cannot find them it will search for the files using the environment
variable <code>YAPLIBDIR</code>, if defined, or in the default library.
</p>
<p>YAP also supports the SWI-Prolog interface to loading foreign code:
</p>
<dl compact="compact">
<dt><code>open_shared_object(+<var>File</var>, -<var>Handle</var>)</code></dt>
<dd><a name="index-open_005fshared_005fobject_002f2"></a>
<a name="index-open_005fshared_005fobject_002f2-1"></a>
<a name="index-open_005fshared_005fobject_002f2-2"></a>
<p> File is the name of a shared object file (called dynamic load
library in MS-Windows). This file is attached to the current process
and <var>Handle</var> is unified with a handle to the library. Equivalent to
<code>open_shared_object(File, [], Handle)</code>. See also
load_foreign_library/[1,2].
</p>
<p> On errors, an exception <code>shared_object</code>(<var>Action</var>,
<var>Message</var>) is raised. <var>Message</var> is the return value from
dlerror().
</p>
</dd>
<dt><code>open_shared_object(+<var>File</var>, -<var>Handle</var>, +<var>Options</var>)</code></dt>
<dd><a name="index-open_005fshared_005fobject_002f3"></a>
<a name="index-open_005fshared_005fobject_002f3-1"></a>
<a name="index-open_005fshared_005fobject_002f3-2"></a>
<p> As <code>open_shared_object/2</code>, but allows for additional flags to
be passed. <var>Options</var> is a list of atoms. <code>now</code> implies the
symbols are
resolved immediately rather than lazily (default). <code>global</code> implies
symbols of the loaded object are visible while loading other shared
objects (by default they are local). Note that these flags may not
be supported by your operating system. Check the documentation of
<code>dlopen()</code> or equivalent on your operating system. Unsupported
flags are silently ignored.
</p>
</dd>
<dt><code>close_shared_object(+<var>Handle</var>)</code></dt>
<dd><a name="index-close_005fshared_005fobject_002f1"></a>
<a name="index-close_005fshared_005fobject_002f1-1"></a>
<a name="index-close_005fshared_005fobject_002f1-2"></a>
<p> Detach the shared object identified by <var>Handle</var>.
</p>
</dd>
<dt><code>call_shared_object_function(+<var>Handle</var>, +<var>Function</var>)</code></dt>
<dd><a name="index-call_005fshared_005fobject_005ffunction_002f2"></a>
<a name="index-call_005fshared_005fobject_005ffunction_002f2-1"></a>
<a name="index-call_005fshared_005fobject_005ffunction_002f2-2"></a>
<p> Call the named function in the loaded shared library. The function
is called without arguments and the return-value is
ignored. In SWI-Prolog, normally this function installs foreign
language predicates using calls to <code>PL_register_foreign()</code>.
</p></dd>
</dl>
<hr>
<a name="Save_0026Rest"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Loading-Objects" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#YAP4-Notes" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Saving-and-Restoring"></a>
<h2 class="section">23.12 Saving and Restoring</h2>
<p>YAP4 currently does not support <code>save</code> and <code>restore</code> for object code
loaded with <code>load_foreign_files</code>. We plan to support save and restore
in future releases of YAP.
</p>
<hr>
<a name="YAP4-Notes"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Save_0026Rest" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dInterface" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Changes-to-the-C_002dInterface-in-YAP4"></a>
<h2 class="section">23.13 Changes to the C-Interface in YAP4</h2>
<p>YAP4 includes several changes over the previous <code>load_foreign_files</code>
interface. These changes were required to support the new binary code
formats, such as ELF used in Solaris2 and Linux.
</p><ul>
<li> All Names of YAP objects now start with <var>YAP_</var>. This is
designed to avoid clashes with other code. Use <code>YAPInterface.h</code> to
take advantage of the new interface. <code>c_interface.h</code> is still
available if you cannot port the code to the new interface.
</li><li> Access to elements in the new interface always goes through
<em>functions</em>. This includes access to the argument registers,
<code>YAP_ARG1</code> to <code>YAP_ARG16</code>. This change breaks code such as
<code>unify(&amp;ARG1,&amp;t)</code>, which is nowadays:
<div class="example">
<pre class="example">{
YAP_Unify(ARG1, t);
}
</pre></div>
</li><li> <code>cut_fail()</code> and <code>cut_succeed()</code> are now functions.
</li><li> The use of <code>Deref</code> is deprecated. All functions that return
Prolog terms, including the ones that access arguments, already
dereference their arguments.
</li><li> 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.
</li></ul>
<hr>
<a name="YAPLibrary"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#C_002dInterface" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAP4-Notes" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Using-YAP-as-a-Library"></a>
<h1 class="chapter">24 Using YAP as a Library</h1>
<p>YAP can be used as a library to be called from other
programs. To do so, you must first create the YAP library:
</p><div class="example">
<pre class="example">make library
make install_library
</pre></div>
<p>This will install a file <code>libyap.a</code> in <var>LIBDIR</var> and the Prolog
headers in <var>INCLUDEDIR</var>. The library contains all the functionality
available in YAP, except the foreign function loader and for
<code>YAP</code>&rsquo;s startup routines.
</p>
<p>To actually use this library you must follow a five step process:
</p>
<ol>
<li>
You must initialize the YAP environment. A single function,
<code>YAP_FastInit</code> asks for a contiguous chunk in your memory space, fills
it in with the data-base, and sets up YAP&rsquo;s stacks and
execution registers. You can use a saved space from a standard system by
calling <code>save_program/1</code>.
</li><li> You then have to prepare a query to give to
YAP. A query is a Prolog term, and you just have to use the same
functions that are available in the C-interface.
</li><li> You can then use <code>YAP_RunGoal(query)</code> to actually evaluate your
query. The argument is the query term <code>query</code>, and the result is 1
if the query succeeded, and 0 if it failed.
</li><li> You can use the term destructor functions to check how
arguments were instantiated.
</li><li> If you want extra solutions, you can use
<code>YAP_RestartGoal()</code> to obtain the next solution.
</li></ol>
<p>The next program shows how to use this system. We assume the saved
program contains two facts for the procedure <tt>b</tt>:
</p>
<div class="example">
<table class="cartouche" border="1"><tr><td>
<pre class="example">#include &lt;stdio.h&gt;
#include &quot;YAP/YAPInterface.h&quot;
int
main(int argc, char *argv[]) {
if (YAP_FastInit(&quot;saved_state&quot;) == YAP_BOOT_ERROR)
exit(1);
if (YAP_RunGoal(YAP_MkAtomTerm(YAP_LookupAtom(&quot;do&quot;)))) {
printf(&quot;Success\n&quot;);
while (YAP_RestartGoal())
printf(&quot;Success\n&quot;);
}
printf(&quot;NO\n&quot;);
}
</pre></td></tr></table>
</div>
<p>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.
</p>
<p>To compile this program it should be sufficient to do:
</p>
<div class="example">
<pre class="example">cc -o exem -I../YAP4.3.0 test.c -lYAP -lreadline -lm
</pre></div>
<p>You may need to adjust the libraries and library paths depending on the
Operating System and your installation of YAP.
</p>
<p>Note that YAP4.3.0 provides the first version of the interface. The
interface may change and improve in the future.
</p>
<p>The following C-functions are available from YAP:
</p>
<ul>
<li> YAP_CompileClause(<code>YAP_Term</code> <var>Clause</var>)
<a name="index-YAP_005fCompileClause_002f1"></a>
Compile the Prolog term <var>Clause</var> and assert it as the last clause
for the corresponding procedure.
</li><li> <code>int</code> YAP_ContinueGoal(<code>void</code>)
<a name="index-YAP_005fContinueGoal_002f0"></a>
Continue execution from the point where it stopped.
</li><li> <code>void</code> YAP_Error(<code>int</code> <var>ID</var>,<code>YAP_Term</code> <var>Cause</var>,<code>char *</code> <var>error_description</var>)
<a name="index-YAP_005fError_002f1"></a>
Generate an YAP System Error with description given by the string
<var>error_description</var>. <var>ID</var> is the error ID, if known, or
<code>0</code>. <var>Cause</var> is the term that caused the crash.
</li><li> <code>void</code> YAP_Exit(<code>int</code> <var>exit_code</var>)
<a name="index-YAP_005fExit_002f1"></a>
Exit YAP immediately. The argument <var>exit_code</var> gives the error code
and is supposed to be 0 after successful execution in Unix and Unix-like
systems.
</li><li> <code>YAP_Term</code> YAP_GetValue(<code>Atom</code> <var>at</var>)
<a name="index-YAP_005fGetValue_002f1"></a>
Return the term <var>value</var> associated with the atom <var>at</var>. If no
such term exists the function will return the empty list.
</li><li> YAP_FastInit(<code>char *</code> <var>SavedState</var>)
<a name="index-YAP_005fFastInit_002f1"></a>
Initialize a copy of YAP from <var>SavedState</var>. The copy is
monolithic and currently must be loaded at the same address where it was
saved. <code>YAP_FastInit</code> is a simpler version of <code>YAP_Init</code>.
</li><li> YAP_Init(<var>InitInfo</var>)
<a name="index-YAP_005fInit_002f1"></a>
Initialize YAP. The arguments are in a <code>C</code>
structure of type <code>YAP_init_args</code>.
<p>The fields of <var>InitInfo</var> are <code>char *</code> <var>SavedState</var>,
<code>int</code> <var>HeapSize</var>, <code>int</code> <var>StackSize</var>, <code>int</code>
<var>TrailSize</var>, <code>int</code> <var>NumberofWorkers</var>, <code>int</code>
<var>SchedulerLoop</var>, <code>int</code> <var>DelayedReleaseLoad</var>, <code>int</code>
<var>argc</var>, <code>char **</code> <var>argv</var>, <code>int</code> <var>ErrorNo</var>, and
<code>char *</code> <var>ErrorCause</var>. The function returns an integer, which
indicates the current status. If the result is <code>YAP_BOOT_ERROR</code>
booting failed.
</p>
<p>If <var>SavedState</var> is not NULL, try to open and restore the file
<var>SavedState</var>. Initially YAP will search in the current directory. If
the saved state does not exist in the current directory YAP will use
either the default library directory or the directory given by the
environment variable <code>YAPLIBDIR</code>. Note that currently
the saved state must be loaded at the same address where it was saved.
</p>
<p>If <var>HeapSize</var> is different from 0 use <var>HeapSize</var> as the minimum
size of the Heap (or code space). If <var>StackSize</var> is different from 0
use <var>HeapSize</var> as the minimum size for the Stacks. If
<var>TrailSize</var> is different from 0 use <var>TrailSize</var> as the minimum
size for the Trails.
</p>
<p>The <var>NumberofWorkers</var>, <var>NumberofWorkers</var>, and
<var>DelayedReleaseLoad</var> are only of interest to the or-parallel system.
</p>
<p>The argument count <var>argc</var> and string of arguments <var>argv</var>
arguments are to be passed to user programs as the arguments used to
call YAP.
</p>
<p>If booting failed you may consult <code>ErrorNo</code> and <code>ErrorCause</code>
for the cause of the error, or call
<code>YAP_Error(ErrorNo,0L,ErrorCause)</code> to do default processing.
</p>
</li><li> <code>void</code> YAP_PutValue(<code>Atom</code> <var>at</var>, <code>YAP_Term</code> <var>value</var>)
<a name="index-YAP_005fPutValue_002f2"></a>
Associate the term <var>value</var> with the atom <var>at</var>. The term
<var>value</var> must be a constant. This functionality is used by YAP as a
simple way for controlling and communicating with the Prolog run-time.
</li><li> <code>YAP_Term</code> YAP_Read(<code>int (*)(void)</code> <var>GetC</var>)
<a name="index-YAP_005fRead_002f1"></a>
Parse a Term using the function <var>GetC</var> to input characters.
</li><li> <code>YAP_Term</code> YAP_Write(<code>YAP_Term</code> <var>t</var>)
<a name="index-YAP_005fCopyTerm_002f1"></a>
Copy a Term <var>t</var> and all associated constraints. May call the garbage
collector and returns <code>0L</code> on error (such as no space being
available).
</li><li> <code>void</code> YAP_Write(<code>YAP_Term</code> <var>t</var>, <code>void (*)(int)</code>
<var>PutC</var>, <code>int</code> <var>flags</var>)
<a name="index-YAP_005fWrite_002f3"></a>
Write a Term <var>t</var> using the function <var>PutC</var> to output
characters. The term is written according to a mask of the following
flags in the <code>flag</code> argument: <code>YAP_WRITE_QUOTED</code>,
<code>YAP_WRITE_HANDLE_VARS</code>, and <code>YAP_WRITE_IGNORE_OPS</code>.
</li><li> <code>void</code> YAP_WriteBuffer(<code>YAP_Term</code> <var>t</var>, <code>char *</code>
<var>buff</var>, <code>unsigned int</code>
<var>size</var>, <code>int</code> <var>flags</var>)
<a name="index-YAP_005fWriteBuffer_002f4"></a>
Write a YAP_Term <var>t</var> to buffer <var>buff</var> with size <var>size</var>. The
term is written according to a mask of the following flags in the
<code>flag</code> argument: <code>YAP_WRITE_QUOTED</code>,
<code>YAP_WRITE_HANDLE_VARS</code>, and <code>YAP_WRITE_IGNORE_OPS</code>.
</li><li> <code>void</code> YAP_InitConsult(<code>int</code> <var>mode</var>, <code>char *</code> <var>filename</var>)
<a name="index-YAP_005fInitConsult_002f2"></a>
Enter consult mode on file <var>filename</var>. 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.
<p>If <var>mode</var> is <code>TRUE</code> 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
<code>compile/1</code> or <code>consult/1</code> to do compilation.
</p>
<p>Note that it is up to the user to open the file <var>filename</var>. The
<code>YAP_InitConsult</code> function only uses the file name for internal
bookkeeping.
</p>
</li><li> <code>void</code> YAP_EndConsult(<code>void</code>)
<a name="index-YAP_005fEndConsult_002f0"></a>
Finish consult mode.
</li></ul>
<p>Some observations:
</p>
<ul>
<li> 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 <code>mmap</code>. This problem will be addressed in future
versions of YAP.
</li><li> Currently, the YAP library will pollute the name
space for your program.
</li><li> 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).
</li><li> You can generate your own saved states. Look at the
<code>boot.yap</code> and <code>init.yap</code> files.
</li></ul>
<hr>
<a name="Compatibility"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#YAPLibrary" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#YAPLibrary" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Compatibility-with-Other-Prolog-systems"></a>
<h1 class="chapter">25 Compatibility with Other Prolog systems</h1>
<p>YAP has been designed to be as compatible as possible with
other Prolog systems, and initially with C-Prolog. More recent work on
YAP has included features initially proposed for the Quintus
and SICStus Prolog systems.
</p>
<p>Developments since <code>YAP4.1.6</code> we have striven at making
YAP compatible with the ISO-Prolog standard.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#C_002dProlog">25.1 Compatibility with the C-Prolog interpreter</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#SICStus-Prolog">25.2 Compatibility with the Quintus and SICStus Prolog systems</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> Compatibility with the SICStus Prolog system
</td></tr>
<tr><td align="left" valign="top"><a href="#ISO-Prolog">25.3 Compatibility with the ISO Prolog standard</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
</table>
<hr>
<a name="C_002dProlog"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Major-Differences-with-C_002dProlog" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Compatibility-with-the-C_002dProlog-interpreter"></a>
<h2 class="section">25.1 Compatibility with the C-Prolog interpreter</h2>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">C-Prolog Compatibility
</pre></th></tr><tr><td align="left" valign="top"><a href="#Major-Differences-with-C_002dProlog">25.1.1 Major Differences between YAP and C-Prolog.</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Fully-C_002dProlog-Compatible">25.1.2 YAP predicates fully compatible with C-Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Not-Strictly-C_002dProlog-Compatible">25.1.3 YAP predicates not strictly compatible with C-Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> YAP predicates not strictly as C-Prolog
</td></tr>
<tr><td align="left" valign="top"><a href="#Not-in-C_002dProlog">25.1.4 YAP predicates not available in C-Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Not-in-YAP">25.1.5 YAP predicates not available in C-Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> C-Prolog predicates not available in YAP
</td></tr>
</table>
<hr>
<a name="Major-Differences-with-C_002dProlog"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Fully-C_002dProlog-Compatible" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Major-Differences-between-YAP-and-C_002dProlog_002e"></a>
<h3 class="subsection">25.1.1 Major Differences between YAP and C-Prolog.</h3>
<p>YAP includes several extensions over the original C-Prolog system. Even
so, most C-Prolog programs should run under YAP without changes.
</p>
<p>The most important difference between YAP and C-Prolog is that, being
YAP a compiler, some changes should be made if predicates such as
<code>assert</code>, <code>clause</code> and <code>retract</code> are used. First
predicates which will change during execution should be declared as
<code>dynamic</code> by using commands like:
</p>
<div class="example">
<pre class="example">:- dynamic f/n.
</pre></div>
<p>where <code>f</code> is the predicate name and n is the arity of the
predicate. Note that several such predicates can be declared in a
single command:
</p><div class="example">
<pre class="example"> :- dynamic f/2, ..., g/1.
</pre></div>
<p>Primitive predicates such as <code>retract</code> apply only to dynamic
predicates. Finally note that not all the C-Prolog primitive predicates
are implemented in YAP. They can easily be detected using the
<code>unknown</code> system predicate provided by YAP.
</p>
<p>Last, by default YAP enables character escapes in strings. You can
disable the special interpretation for the escape character by using:
</p><div class="example">
<pre class="example"><code>:- yap_flag(character_escapes,off).</code>
</pre></div>
<p>or by using:
</p><div class="example">
<pre class="example"><code>:- yap_flag(language,cprolog).</code>
</pre></div>
<hr>
<a name="Fully-C_002dProlog-Compatible"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Major-Differences-with-C_002dProlog" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Not-Strictly-C_002dProlog-Compatible" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="YAP-predicates-fully-compatible-with-C_002dProlog"></a>
<h3 class="subsection">25.1.2 YAP predicates fully compatible with C-Prolog</h3>
<p>These are the Prolog built-ins that are fully compatible in both
C-Prolog and YAP:
</p>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-1"><b>!</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-2"><b>,</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-3"><b>;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-4"><b>&lt;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-5"><b>=</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-6"><b>&gt;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-7"><b>@</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-8"><b>[</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-9"><b>\</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-K"><b>K</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-W"><b>W</b></a>
&nbsp;
</td></tr></table>
<table class="index-cy" border="0">
<tr><td></td><th align="left">Index Entry</th><td>&nbsp;</td><th align="left"> Section</th></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-1">!</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0021_002f0-2">!/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-2">,</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002c_002f2-2">,/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-3">;</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003b_002f2-2">;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-4">&lt;</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003c_002f2-2">&lt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-5">=</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_002e_002e_002f2-2">=../2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_003a_003d_002f2-2">=:=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_003c_002f2-2">=&lt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_003d_002f2-2">==/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_005c_003d_002f2-2">=\=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-6">&gt;</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003e_002f2-2">&gt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003e_003d_002f2-2">&gt;=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-7">@</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003c_002f2-2">@&lt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003c_002f2-4">@&lt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003e_002f2-2">@&gt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003e_003d_002f2-2">@&gt;=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-8">[</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005b_002d_005d_002f1-2">[-]/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005b_005d_002f1-2">[]/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-9">\</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005c_002b_002f1-2">\+/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005c_003d_003d_002f2-2">\==/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-A">A</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-abort_002f0-2">abort/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_002f1-2">atom/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_002f1-2">atomic/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-B">B</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-bagof_002f3-2">bagof/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-break_002f0-2">break/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-C">C</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_002f1-2">call/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_002f1-2">close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compare_002f3-2">compare/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-consult_002f1-2">consult/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fatom_002f1-2">current_atom/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fpredicate_002f1-2">current_predicate/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-D">D</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005freference_002f1-1">db_reference/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-debug_002f0-2">debug/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-debugging_002f0-2">debugging/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-display_002f1-2">display/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-E">E</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-erase_002f1-2">erase/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-erased_002f1-2">erased/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exists_002f1-2">exists/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expand_005fexprs_002f2-2">expand_exprs/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expand_005fterm_002f2-2">expand_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-F">F</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-fail_002f0-2">fail/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fileerrors_002f0-2">fileerrors/0</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-findall_002f3-2">findall/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-functor_002f3-2">functor/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-G">G</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_002f1-2">get/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get0_002f1-2">get0/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-H">H</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-halt_002f0-2">halt/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-I">I</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-instance_002f2-2">instance/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-integer_002f1-2">integer/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-K">K</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-keysort_002f2-2">keysort/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-L">L</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-leash_002f1-2">leash/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-length_002f2-2">length/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-N">N</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-name_002f2-2">name/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nl_002f0-2">nl/0</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nodebug_002f0-2">nodebug/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nofileerrors_002f0-2">nofileerrors/0</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nonvar_002f1-2">nonvar/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nospy_002f1-2">nospy/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-not_002f1-2">not/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-notrace_002f0-2">notrace/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_002f1-2">number/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-O">O</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-op_002f3-2">op/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-P">P</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-primitive_002f1-2">primitive/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_002f1-2">print/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prompt_002f2-2">prompt/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_002f1-2">put/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-R">R</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-rational_002f1-2">rational/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_002f1-2">read/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reconsult_002f1-2">reconsult/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorda_002f3-2">recorda/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorded_002f3-2">recorded/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordz_002f3-2">recordz/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rename_002f2-2">rename/2</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-repeat_002f0-2">repeat/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-S">S</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_002f1-2">save/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-see_002f1-2">see/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-seeing_002f1-2">seeing/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-seen_002f0-2">seen/0</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setof_002f3-2">setof/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sh_002f0-2">sh/0</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-skip_002f1-2">skip/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sort_002f2-2">sort/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-spy_002f1-2">spy/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-statistics_002f0-2">statistics/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_002f1-2">system/1</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-T">T</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-tab_002f1-2">tab/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tell_002f1-2">tell/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-telling_002f1-2">telling/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fexpansion_002f2-2">term_expansion/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-told_002f0-2">told/0</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trace_002f0-2">trace/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-true_002f0-2">true/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-V">V</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-var_002f1-2">var/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-W">W</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_002f1-2">write/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-writeq_002f1-2">writeq/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
</table>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-1"><b>!</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-2"><b>,</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-3"><b>;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-4"><b>&lt;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-5"><b>=</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-6"><b>&gt;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-7"><b>@</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-8"><b>[</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_symbol-9"><b>\</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-K"><b>K</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-C_002dProlog_cy_letter-W"><b>W</b></a>
&nbsp;
</td></tr></table>
<hr>
<a name="Not-Strictly-C_002dProlog-Compatible"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Fully-C_002dProlog-Compatible" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Not-in-C_002dProlog" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="YAP-predicates-not-strictly-compatible-with-C_002dProlog"></a>
<h3 class="subsection">25.1.3 YAP predicates not strictly compatible with C-Prolog</h3>
<p>These are YAP built-ins that are also available in C-Prolog, but
that are not fully compatible:
</p>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-R"><b>R</b></a>
&nbsp;
</td></tr></table>
<table class="index-ca" border="0">
<tr><td></td><th align="left">Index Entry</th><td>&nbsp;</td><th align="left"> Section</th></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-A">A</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_002f1-2">abolish/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_002f2-2">abolish/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assert_002f1-2">assert/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assert_002f2-2">assert/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-asserta_002f1-2">asserta/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-asserta_002f2-2">asserta/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assertz_002f1-2">assertz/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assertz_002f2-2">assertz/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-C">C</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-clause_002f2-2">clause/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-clause_002f3-2">clause/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-I">I</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_002f2-2">is/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-L">L</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-listing_002f0-2">listing/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-listing_002f1-2">listing/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-N">N</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_005fclause_002f3-2">nth_clause/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-R">R</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-retract_002f2-2">retract/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
</table>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-C_002dProlog_ca_letter-R"><b>R</b></a>
&nbsp;
</td></tr></table>
<hr>
<a name="Not-in-C_002dProlog"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Not-Strictly-C_002dProlog-Compatible" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Not-in-YAP" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="YAP-predicates-not-available-in-C_002dProlog"></a>
<h3 class="subsection">25.1.4 YAP predicates not available in C-Prolog</h3>
<p>These are YAP built-ins not available in C-Prolog.
</p>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_symbol-1"><b>-</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_symbol-2"><b>=</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_symbol-3"><b>\</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-J"><b>J</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-K"><b>K</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-M"><b>M</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-Q"><b>Q</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-W"><b>W</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-Y"><b>Y</b></a>
&nbsp;
</td></tr></table>
<table class="index-cn" border="0">
<tr><td></td><th align="left">Index Entry</th><td>&nbsp;</td><th align="left"> Section</th></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_symbol-1">-</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002d_003e_002a_002f2-2">-&gt;*/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002d_003e_002f2-2">-&gt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_symbol-2">=</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_002f2-2">=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_002f2-5">=/=2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_0040_003d_002f2-2">=@=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_symbol-3">\</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005c_003d_002f2-2">\=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-A">A</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_005fall_005ftables_002f0-2">abolish_all_tables/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_005ftable_002f1-2">abolish_table/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-absolute_005ffile_005fname_002f2-2">absolute_file_name/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-absolute_005ffile_005fname_002f3-2">absolute_file_name/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fedges_002f3-2">add_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fto_005farray_005felement_002f4-2">add_to_array_element/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fto_005fheap_002f4-2">add_to_heap/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fvertices_002f3-2">add_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_002f3-2">aggregate/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_002f4-2">aggregate/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_005fall_002f3-2">aggregate_all/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_005fall_002f4-2">aggregate_all/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-alarm_002f3-2">alarm/3</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-all_002f3-2">all/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-always_005fprompt_005fuser_002f0-2">always_prompt_user/0</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-append_002f2-2">append/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-append_002f3-2">append/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-append_002f3-5">append/3</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-arg_002f3-2">arg/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-array_002f2-2">array/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-array_005felement_002f3-2">array_element/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-asserta_005fstatic_002f1-2">asserta_static/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assertz_005fstatic_002f1-2">assertz_static/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assert_005fstatic_002f1-2">assert_static/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assoc_005fto_005flist_002f2-2">assoc_to_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_005fconcat_002f2-2">atomic_concat/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_005flist_005fconcat_002f2-2">atomic_list_concat/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_005flist_005fconcat_002f3-2">atomic_list_concat/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fchars_002f2-2">atom_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fcodes_002f2-2">atom_codes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fconcat_002f2-2">atom_concat/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fconcat_002f3-2">atom_concat/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005flength_002f2-2">atom_length/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fnumber_002f2-2">atom_number/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fto_005fchars_002f2-2">atom_to_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fto_005fchars_002f3-2">atom_to_chars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fto_005fterm_002f3-2">atom_to_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attribute_005fgoal_002f2-2">attribute_goal/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Displaying-Attributes">11.2.4 Displaying Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attribute_005fgoals_002f2-2">attribute_goals/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attr_005fportray_005fhook_002f2-2">attr_portray_hook/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attr_005funify_005fhook_002f2-2">attr_unify_hook/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attvar_002f1-2">attvar/1</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attvar_002f1-5">attvar/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Attributed-Unification">11.2.3 Attributed Unification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-at_005fend_005fof_005fstream_002f0-2">at_end_of_stream/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-at_005fend_005fof_005fstream_002f1-2">at_end_of_stream/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-avl_005finsert_002f4-2">avl_insert/4</a></td><td>&nbsp;</td><td valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-avl_005flookup_002f3-2">avl_lookup/3</a></td><td>&nbsp;</td><td valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-avl_005fnew_002f1-2">avl_new/1</a></td><td>&nbsp;</td><td valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-B">B</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fdelete_002f2-2">bb_delete/2</a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fget_002f2-2">bb_get/2</a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fput_002f2-2">bb_put/2</a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fupdate_002f3-2">bb_update/3</a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-between_002f3-2">between/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-between_002f3-5">between/3</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fgetval_002f2-2">b_getval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fgetval_002f2-5">b_getval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fsetval_002f2-2">b_setval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fsetval_002f2-5">b_setval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-C">C</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-C_002f3-2">C/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_002fn-2">call/n</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-callable_002f1-2">callable/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcleanup_002f1-2">call_cleanup/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcleanup_002f2-2">call_cleanup/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcount_005fdata_002f0-2">call_count_data/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcount_005fdata_002f3-2">call_count_data/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcount_005fdata_002f3-5">call_count_data/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fresidue_002f2-2">call_residue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fresidue_005fvars_002f2-2">call_residue_vars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fshared_005fobject_005ffunction_002f2-2">call_shared_object_function/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fwith_005fargs_002fn-2">call_with_args/n</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-catch_002f3-2">catch/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cd_002f1-2">cd/1</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-character_005fcount_002f2-2">character_count/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-char_005fcode_002f2-2">char_code/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-char_005fconversion_002f2-2">char_conversion/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-char_005ftype_002f2-2">char_type/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-chdir_002f1-2">chdir/1</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-checklist_002f2-2">checklist/2</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-checknodes_002f3-2">checknodes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cleanup_005fall_002f0-2">cleanup_all/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_002f2-2">close/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_005fmatlab_002f0-2">close_matlab/0</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_005fshared_005fobject_002f1-2">close_shared_object/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_005fstatic_005farray_002f1-2">close_static_array/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-code_005ftype_002f2-2">code_type/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compile_002f1-2">compile/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compile_002f1-4">compile/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compile_002f1-_0028directive_0029-1">compile/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compile_005fexpressions_002f0-2">compile_expressions/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-complement_002f2-2">complement/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compose_002f3-2">compose/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compound_002f1-2">compound/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-concat_005fatom_002f2-2">concat_atom/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-concat_005fatom_002f3-2">concat_atom/3</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-convlist_002f3-2">convlist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fline_002f2-2">copy_line/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fline_002f2-5">copy_line/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fterm_002f2-2">copy_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fterm_002f3-2">copy_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fterm_005fnat_002f2-2">copy_term_nat/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-create_005fmutable_002f2-2">create_mutable/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-create_005fprolog_005fflag_002f2-2">create_prolog_flag/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fchar_005fconversion_002f2-2">current_char_conversion/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fforeign_005flibrary_002f2-2">current_foreign_library/2</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005finput_002f1-2">current_input/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fkey_002f2-2">current_key/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fline_005fnumber_002f1-2">current_line_number/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fline_005fnumber_002f2-2">current_line_number/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fmodule_002f1-2">current_module/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Preds">6.21 Predicate Information</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fmodule_002f2-2">current_module/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Preds">6.21 Predicate Information</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fmutex_002f3-2">current_mutex/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fop_002f3-2">current_op/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005foutput_002f1-2">current_output/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fpredicate_002f2-2">current_predicate/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fprolog_005fflag_002f2-2">current_prolog_flag/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fstream_002f3-2">current_stream/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fthread_002f2-2">current_thread/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cyclic_005fterm_002f1-2">cyclic_term/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cyclic_005fterm_002f1-5">cyclic_term/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-D">D</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-datime_002f1-2">datime/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fassert_002f1-2">db_assert/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fassert_002f2-2">db_assert/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fclose_002f1-2">db_close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdatalog_005fdescribe_002f1-2">db_datalog_describe/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdatalog_005fdescribe_002f2-2">db_datalog_describe/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdescribe_002f1-2">db_describe/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdescribe_002f2-2">db_describe/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fget_005fattributes_005ftypes_002f2-2">db_get_attributes_types/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Types-of-Attributes">15.9 Types of Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fget_005fattributes_005ftypes_002f3-2">db_get_attributes_types/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Types-of-Attributes">15.9 Types of Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fimport_002f2-2">db_import/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-a-Relation">15.5 Accessing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fimport_002f3-2">db_import/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-a-Relation">15.5 Accessing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005finsert_002f2-2">db_insert/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005finsert_002f3-2">db_insert/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmodule_002f1-2">db_module/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmy_005fresult_005fset_002f1-2">db_my_result_set/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmy_005fsql_005fmode_002f1-2">db_my_sql_mode/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmy_005fsql_005fmode_002f2-2">db_my_sql_mode/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fnumber_005fof_005ffields_002f2-2">db_number_of_fields/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Number-of-Fields">15.10 Number of Fields</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fnumber_005fof_005ffields_002f3-2">db_number_of_fields/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Number-of-Fields">15.10 Number of Fields</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fopen_002f4-2">db_open/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fopen_002f5-2">db_open/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fshow_005ftables_002f1-2">db_show_tables/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Enumerating-Relations">15.12 Enumeration Relations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fshow_005ftables_002f2-2">db_show_tables/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Enumerating-Relations">15.12 Enumeration Relations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fsql_002f2-2">db_sql/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-Tables-in-Data-Sources-Using-SQL">15.7 Accessing Tables in Data Sources Using SQL</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fsql_002f3-2">db_sql/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-Tables-in-Data-Sources-Using-SQL">15.7 Accessing Tables in Data Sources Using SQL</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005ftop_005flevel_002f4-2">db_top_level/4</a></td><td>&nbsp;</td><td valign="top"><a href="#The-MYDDAS-MySQL-Top-Level">15.13 The MYDDAS MySQL Top Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005ftop_005flevel_002f5-2">db_top_level/5</a></td><td>&nbsp;</td><td valign="top"><a href="#The-MYDDAS-MySQL-Top-Level">15.13 The MYDDAS MySQL Top Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fview_002f2-2">db_view/2</a></td><td>&nbsp;</td><td valign="top"><a href="#View-Level-Interface">15.6 View Level Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fview_002f3-2">db_view/3</a></td><td>&nbsp;</td><td valign="top"><a href="#View-Level-Interface">15.6 View Level Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-delete_002f3-2">delete/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-delete_005ffile_002f1-2">delete_file/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-delete_005ffile_002f2-2">delete_file/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fassoc_002f4-2">del_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fattr_002f2-2">del_attr/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fattrs_002f1-2">del_attrs/1</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fedges_002f3-2">del_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fmax_005fassoc_002f4-2">del_max_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fmin_005fassoc_002f4-2">del_min_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fvertices_002f3-2">del_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fedge_002f4-2">dgraph_add_edge/4</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fedges_002f3-2">dgraph_add_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fvertex_002f3-2">dgraph_add_vertex/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fvertices_002f3-2">dgraph_add_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fcomplement_002f2-2">dgraph_complement/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fcompose_002f3-2">dgraph_compose/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fedge_002f4-2">dgraph_del_edge/4</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fedges_002f3-2">dgraph_del_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fvertex_002f3-2">dgraph_del_vertex/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fvertices_002f3-2">dgraph_del_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fedge_002f2-2">dgraph_edge/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fedges_002f2-2">dgraph_edges/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fisomorphic_002f4-2">dgraph_isomorphic/4</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fmax_005fpath_002f5-2">dgraph_max_path/5</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fmin_005fpath_002f5-2">dgraph_min_path/5</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fmin_005fpaths_002f3-2">dgraph_min_paths/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fneighbors_002f3-2">dgraph_neighbors/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fneighbours_002f3-2">dgraph_neighbours/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fnew_002f1-2">dgraph_new/1</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fpath_002f3-2">dgraph_path/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fpath_002f3-5">dgraph_path/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fsymmetric_005fclosure_002f2-2">dgraph_symmetric_closure/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftop_005fsort_002f2-2">dgraph_top_sort/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftop_005fsort_002f3-2">dgraph_top_sort/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fto_005fugraph_002f2-2">dgraph_to_ugraph/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fto_005fundgraph_002f2-2">dgraph_to_undgraph/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftransitive_005fclosure_002f2-2">dgraph_transitive_closure/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftranspose_002f2-2">dgraph_transpose/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fvertices_002f2-2">dgraph_vertices/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dif_002f2-2">dif/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-directory_005ffiles_002f2-2">directory_files/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-discontiguous_002f1-_0028directive_0029-2">discontiguous/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-display_002f1-5">display/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-display_002f2-2">display/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-do_005fnot_005fcompile_005fexpressions_002f0-2">do_not_compile_expressions/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-duplicate_005fterm_002f2-2">duplicate_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dynamic_002f1-2">dynamic/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Database">6.10 Using the Clausal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dynamic_005fpredicate_002f2-2">dynamic_predicate/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Database">6.10 Using the Clausal Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-E">E</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-edges_002f2-2">edges/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-elif_002f1-1">elif/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-else_002f0-1">else/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-empty_005fassoc_002f1-2">empty_assoc/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-empty_005fheap_002f1-2">empty_heap/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-empty_005fqueue_002f1-2">empty_queue/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-endif_002f0-1">endif/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environ_002f2-2">environ/2</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environ_002f2-5">environ/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-eraseall_002f1-2">eraseall/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exception_002f3-2">exception/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exclude_002f3-2">exclude/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exec_002f3-2">exec/3</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-F">F</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-false_002f0-2">false/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fields_002f2-2">fields/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fields_002f3-2">fields/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fbase_005fname_002f2-2">file_base_name/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fexists_002f1-2">file_exists/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fexists_002f2-2">file_exists/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005ffilter_002f3-2">file_filter/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005ffilter_005fwith_005finit_002f5-2">file_filter_with_init/5</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fname_005fextension_002f3-2">file_name_extension/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fproperty_002f2-2">file_property/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fsearch_005fpath_002f2-2">file_search_path/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-filter_002f3-2">filter/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-findall_002f4-2">findall/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-flatten_002f2-2">flatten/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-float_002f1-2">float/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-flush_005foutput_002f0-2">flush_output/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-flush_005foutput_002f1-2">flush_output/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-forall_002f2-2">forall/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-forall_002f2-5">forall/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Forall">8.2 Forall</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-foreach_002f2-2">foreach/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_002f1-2">format/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_002f2-2">format/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_002f3-2">format/3</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_005fto_005fchars_002f3-2">format_to_chars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_005fto_005fchars_002f4-2">format_to_chars/4</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fragile-2">fragile</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-freeze_002f2-2">freeze/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-free_005fvariables_002f4-2">free_variables/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-frozen_002f2-2">frozen/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-G">G</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-garbage_005fcollect_002f0-2">garbage_collect/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-garbage_005fcollect_005fatoms_002f0-2">garbage_collect_atoms/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-gc_002f0-2">gc/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-gen_005fassoc_002f3-2">gen_assoc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_002f2-2">get/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get0_002f2-2">get0/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-getcwd_002f1-2">getcwd/1</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-getrand_002f1-2">getrand/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fassoc_002f3-2">get_assoc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fassoc_002f5-2">get_assoc/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fattr_002f3-2">get_attr/3</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fattrs_002f2-2">get_attrs/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fatts_002f2-2">get_atts/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Attribute-Manipulation">11.2.2 Attribute Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fbyte_002f1-2">get_byte/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fbyte_002f2-2">get_byte/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fchar_002f1-2">get_char/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fchar_002f2-2">get_char/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fcode_002f1-2">get_code/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fcode_002f2-2">get_code/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005ffrom_005fheap_002f4-2">get_from_heap/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005flabel_002f3-2">get_label/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fmutable_002f2-2">get_mutable/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fmutable_002f2-5">get_mutable/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fnext_005fassoc_002f4-2">get_next_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fprev_005fassoc_002f4-2">get_prev_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fvalue_002f2-2">get_value/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-glue_002f3-2">glue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-goal_005fexpansion_002f3-2">goal_expansion/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ground_002f1-2">ground/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-grow_005fheap_002f1-1">grow_heap/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-grow_005fstack_002f1-2">grow_stack/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-H">H</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-halt_002f1-2">halt/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-head_005fqueue_002f2-2">head_queue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-heap_005fsize_002f2-2">heap_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-heap_005fto_005flist_002f2-2">heap_to_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-hide_002f1-2">hide/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-hide_005fpredicate_002f1-2">hide_predicate/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-host_005fid_002f1-2">host_id/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-host_005fname_002f1-2">host_name/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-I">I</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-if_002f1-1">if/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-if_002f3-2">if/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ignore_002f1-2">ignore/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-include_002f3-2">include/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-incore_002f1-2">incore/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-initialization_002f0-2">initialization/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-initialization_002f1-_0028directive_0029-2">initialization/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-initialization_002f2-_0028directive_0029-2">initialization/2 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-intersection_002f3-2">intersection/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005fassoc_002f1-2">is_assoc/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005flist_002f1-2">is_list/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005fmutable_002f1-2">is_mutable/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005frbtree_002f1-2">is_rbtree/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005fstream_002f1-2">is_stream/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005ftabled_002f1-2">is_tabled/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-J">J</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-join_005fqueue_002f3-2">join_queue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-jump_005fqueue_002f3-2">jump_queue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-K">K</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-key_005fstatistics_002f3-2">key_statistics/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-key_005fstatistics_002f4-2">key_statistics/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-kill_002f2-2">kill/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-L">L</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-last_002f2-2">last/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-length_005fqueue_002f2-2">length_queue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-library_005fdirectory_002f1-2">library_directory/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-library_005fdirectory_002f1-5">library_directory/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-line_005fcount_002f2-2">line_count/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-line_005fposition_002f2-2">line_position/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fconcat_002f2-2">list_concat/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fjoin_005fqueue_002f3-2">list_join_queue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fjump_005fqueue_002f3-2">list_jump_queue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005fassoc_002f2-2">list_to_assoc/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005fheap_002f2-2">list_to_heap/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005ford_005fset_002f2-2">list_to_ord_set/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005fqueue_002f2-2">list_to_queue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005frbtree_002f2-2">list_to_rbtree/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005frbtree_002f2-5">list_to_rbtree/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005ftree_002f2-2">list_to_tree/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-load_005ffiles_002f2-2">load_files/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-load_005fforeign_005flibrary_002f1-2">load_foreign_library/1</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-load_005fforeign_005flibrary_002f2-2">load_foreign_library/2</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-M">M</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-make_002f0-2">make/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-make_005fdirectory_002f2-2">make_directory/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-make_005fqueue_002f1-2">make_queue/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mapargs_002f3-2">mapargs/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f2-2">maplist/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f3-2">maplist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f3-5">maplist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f3-8">maplist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f4-2">maplist/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f4-5">maplist/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f5-2">maplist/5</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mapnodes_002f3-2">mapnodes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-map_005fassoc_002f2-2">map_assoc/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-map_005fassoc_002f3-2">map_assoc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-map_005ftree_002f3-2">map_tree/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fcells_002f2-2">matlab_cells/2</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fcells_002f3-2">matlab_cells/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005feval_005fstring_002f1-2">matlab_eval_string/1</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005feval_005fstring_002f2-2">matlab_eval_string/2</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fget_005fvariable_002f2-2">matlab_get_variable/2</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005finitialized_005fcells_002f4-2">matlab_initialized_cells/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f3-2">matlab_item/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f3-5">matlab_item/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f4-2">matlab_item/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f4-5">matlab_item/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fmatrix_002f4-2">matlab_matrix/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fon_002f0-2">matlab_on/0</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fsequence_002f3-2">matlab_sequence/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fset_002f4-2">matlab_set/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fvector_002f4-2">matlab_vector/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f2-2">matlab_zeros/2</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f3-2">matlab_zeros/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f4-2">matlab_zeros/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f4-5">matlab_zeros/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fadd_002f3-2">matrix_add/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fagg_005fcols_002f2-2">matrix_agg_cols/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fagg_005flines_002f2-2">matrix_agg_lines/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005farg_005fto_005foffset_002f3-2">matrix_arg_to_offset/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fdec_002f2-2">matrix_dec/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fdec_002f3-2">matrix_dec/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fdims_002f2-2">matrix_dims/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fexpand_002f3-2">matrix_expand/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fget_002f3-2">matrix_get/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005finc_002f2-2">matrix_inc/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005finc_002f3-2">matrix_inc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fmax_002f2-2">matrix_max/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fmaxarg_002f2-2">matrix_maxarg/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fmin_002f2-2">matrix_min/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fminarg_002f2-2">matrix_minarg/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fndims_002f2-2">matrix_ndims/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fnew_002f3-2">matrix_new/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fnew_002f4-2">matrix_new/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fnew_005fset_002f4-2">matrix_new_set/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005foffset_005fto_005farg_002f3-2">matrix_offset_to_arg/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_002f4-2">matrix_op/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_002f4-5">matrix_op/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_005fto_005fcols_002f4-2">matrix_op_to_cols/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_005fto_005flines_002f4-2">matrix_op_to_lines/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005freorder_002f3-2">matrix_reorder/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005frow_002f3-2">matrix_row/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fselect_002f4-2">matrix_select/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fset_002f3-2">matrix_set/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fset_005fall_002f2-2">matrix_set_all/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fshuffle_002f3-2">matrix_shuffle/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fsize_002f2-2">matrix_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fsum_002f2-2">matrix_sum/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fto_005flist_002f2-2">matrix_to_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005ftype_002f2-2">matrix_type/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005fassoc_002f3-2">max_assoc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005flist_002f2-2">max_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-member_002f2-2">member/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-memberchk_002f2-2">memberchk/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-merge_002f3-2">merge/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fhook_002f3-2">message_hook/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fqueue_005fcreate_002f1-2">message_queue_create/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fqueue_005fdestroy_002f1-2">message_queue_destroy/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fto_005fstring_002f2-2">message_to_string/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-meta_005fpredicate_002f1-_0028directive_0029-2">meta_predicate/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Meta_002dPredicates-in-Modules">5.4 Meta-Predicates in Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005fassoc_002f3-2">min_assoc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005flist_002f2-2">min_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005fof_005fheap_002f3-2">min_of_heap/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005fof_005fheap_002f5-2">min_of_heap/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mktemp_002f2-2">mktemp/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mktime_002f2-2">mktime/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_002f1-2">module/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_002f2-_0028directive_0029-2">module/2 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_002f3-_0028directive_0029-2">module/3 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_005ftransparent_002f1-_0028directive_0029-2">module_transparent/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Meta_002dPredicates-in-Modules">5.4 Meta-Predicates in Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbarrier_002f0-2">mpi_barrier/0</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbcast_002f2-2">mpi_bcast/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbcast_002f3-2">mpi_bcast/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbcast_002f3-5">mpi_bcast/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fcomm_005frank_002f1-2">mpi_comm_rank/1</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fcomm_005fsize_002f1-2">mpi_comm_size/1</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005ffinalize_002f0-2">mpi_finalize/0</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fgc_002f0-2">mpi_gc/0</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005finit_002f0-2">mpi_init/0</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005firecv_002f3-2">mpi_irecv/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fisend_002f4-2">mpi_isend/4</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005frecv_002f3-2">mpi_recv/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fsend_002f3-2">mpi_send/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005ftest_002f2-2">mpi_test/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005ftest_005frecv_002f3-2">mpi_test_recv/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fversion_002f2-2">mpi_version/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fwait_002f2-2">mpi_wait/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fwait_005frecv_002f3-2">mpi_wait_recv/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-multifile_002f1-_0028directive_0029-2">multifile/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005fcreate_002f1-2">mutex_create/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005fdestroy_002f1-2">mutex_destroy/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005flock_002f1-2">mutex_lock/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005fstatistics_002f0-2">mutex_statistics/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005ftrylock_002f1-2">mutex_trylock/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005funlock_002f1-2">mutex_unlock/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005funlock_005fall_002f0-2">mutex_unlock_all/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-N">N</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_002f1-2">nb_beam/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fadd_002f3-2">nb_beam_add/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fclose_002f1-2">nb_beam_close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fdel_002f3-2">nb_beam_del/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fempty_002f1-2">nb_beam_empty/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fpeek_002f3-2">nb_beam_peek/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fsize_002f2-2">nb_beam_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fcurrent_002f2-2">nb_current/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fcurrent_002f2-5">nb_current/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fdelete_002f1-2">nb_delete/1</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fdelete_002f2-2">nb_delete/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fgetval_002f2-2">nb_getval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fgetval_002f2-5">nb_getval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_002f1-2">nb_heap/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fadd_002f3-2">nb_heap_add/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fclose_002f1-2">nb_heap_close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fdel_002f3-2">nb_heap_del/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fempty_002f1-2">nb_heap_empty/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fpeek_002f3-2">nb_heap_peek/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fsize_002f2-2">nb_heap_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005flinkarg_002f3-1">nb_linkarg/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005flinkval_002f2-2">nb_linkval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_002f1-2">nb_queue/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fclose_002f3-2">nb_queue_close/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fdequeue_002f2-2">nb_queue_dequeue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fempty_002f1-2">nb_queue_empty/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fenqueue_002f2-2">nb_queue_enqueue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fpeek_002f2-2">nb_queue_peek/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fsize_002f2-2">nb_queue_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fsetarg_002f3-2">nb_setarg/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fsetval_002f2-2">nb_setval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fsetval_002f2-5">nb_setval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fset_005fshared_005farg_002f3-2">nb_set_shared_arg/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fset_005fshared_005fval_002f2-2">nb_set_shared_val/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-neighbors_002f3-2">neighbors/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-neighbours_002f3-2">neighbours/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-new_005fvariables_005fin_005fterm_002f3-2">new_variables_in_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nl_002f1-2">nl/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nogc_002f0-2">nogc/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nospyall_002f0-2">nospyall/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-no_005fsource_002f0-2">no_source/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_002f3-2">nth/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_002f4-2">nth/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth0_002f3-2">nth0/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth0_002f4-2">nth0/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth1_002f3-2">nth1/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth1_002f3-5">nth1/3</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth1_002f4-2">nth1/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_005finstance_002f3-2">nth_instance/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_005finstance_002f4-2">nth_instance/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-numbervars_002f3-2">numbervars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fatom_002f2-2">number_atom/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fchars_002f2-2">number_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fcodes_002f2-2">number_codes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fto_005fchars_002f2-2">number_to_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fto_005fchars_002f3-2">number_to_chars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-numlist_002f3-2">numlist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-O">O</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-once_002f1-2">once/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-on_005fcleanup_002f1-2">on_cleanup/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-on_005fsignal_002f3-2">on_signal/3</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_002f3-2">open/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_002f4-2">open/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fchars_005fstream_002f2-2">open_chars_stream/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fshared_005fobject_002f2-2">open_shared_object/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fshared_005fobject_002f3-2">open_shared_object/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ordsubset_002f2-2">ordsubset/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fadd_005felement_002f3-2">ord_add_element/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fdel_005felement_002f3-2">ord_del_element/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fdisjoint_002f2-2">ord_disjoint/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005finsert_002f3-2">ord_insert/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fintersect_002f2-2">ord_intersect/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fintersect_002f3-2">ord_intersect/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fintersect_002f4-2">ord_intersect/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005flist_005fto_005fassoc_002f2-2">ord_list_to_assoc/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fmember_002f2-2">ord_member/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fseteq_002f2-2">ord_seteq/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fsetproduct_002f3-2">ord_setproduct/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fsubtract_002f3-2">ord_subtract/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fsymdiff_002f3-2">ord_symdiff/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005funion_002f2-2">ord_union/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005funion_002f3-2">ord_union/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005funion_002f4-2">ord_union/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-P">P</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-partition_002f4-2">partition/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-partition_002f5-2">partition/5</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-path_002f1-2">path/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-path_002f1-4">path/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-path_002f1-6">path/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fbyte_002f1-2">peek_byte/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fbyte_002f2-2">peek_byte/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fchar_002f1-2">peek_char/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fchar_002f2-2">peek_char/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fcode_002f1-2">peek_code/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fcode_002f2-2">peek_code/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-permutation_002f2-2">permutation/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-phrase_002f2-2">phrase/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-phrase_002f3-2">phrase/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-pid_002f1-2">pid/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-plus_002f3-2">plus/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-popen_002f3-2">popen/3</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-portray_005fclause_002f1-2">portray_clause/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-portray_005fclause_002f2-2">portray_clause/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-predicate_005fproperty_002f2-2">predicate_property/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-predsort_002f3-2">predsort/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_002f2-2">print/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_005fmessage_002f2-2">print_message/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_005fmessage_005flines_002f3-2">print_message_lines/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-process_002f2-2">process/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profiled_005freset_002f0-2">profiled_reset/0</a></td><td>&nbsp;</td><td valign="top"><a href="#The-Count-Profiler">6.18.1 The Count Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profile_005fdata_002f3-2">profile_data/3</a></td><td>&nbsp;</td><td valign="top"><a href="#The-Count-Profiler">6.18.1 The Count Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profinit_002f0-2">profinit/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profoff_002f0-2">profoff/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profon_002f0-2">profon/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-project_005fattributes_002f2-2">project_attributes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Displaying-Attributes">11.2.4 Displaying Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-project_005fattributes_002f2-5">project_attributes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Projecting-Attributes">11.2.5 Projecting Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005ffile_005fname_002f2-1">prolog_file_name/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005fflag_002f3-2">prolog_flag/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005finitialization_002f1-2">prolog_initialization/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005fload_005fcontext_002f2-2">prolog_load_context/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-public_002f1-_0028directive_0029-2">public/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_002f2-2">put/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-putenv_002f2-2">putenv/2</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fassoc_002f4-2">put_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fattr_002f3-2">put_attr/3</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fattrs_002f2-2">put_attrs/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fatts_002f2-2">put_atts/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Attribute-Manipulation">11.2.2 Attribute Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fbyte_002f1-2">put_byte/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fbyte_002f2-2">put_byte/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fchar_002f1-2">put_char/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fchar_002f2-2">put_char/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fcode_002f1-2">put_code/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fcode_002f2-2">put_code/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005flabel_002f4-2">put_label/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-Q">Q</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-queue_005fto_005flist_002f2-2">queue_to_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-R">R</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-random_002f1-2">random/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-random_002f3-2">random/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-randseq_002f3-2">randseq/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-randset_002f3-2">randset/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rannum_002f1-2">rannum/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ranstart_002f0-2">ranstart/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ranstart_002f1-2">ranstart/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ranunif_002f2-2">ranunif/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fapply_002f4-2">rb_apply/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fclone_002f3-2">rb_clone/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdelete_002f3-2">rb_delete/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdelete_002f4-2">rb_delete/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdel_005fmax_002f4-2">rb_del_max/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdel_005fmin_002f4-2">rb_del_min/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fempty_002f1-2">rb_empty/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005finsert_002f4-2">rb_insert/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005finsert_005fnew_002f4-1">rb_insert_new/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fkeys_002f2-2">rb_keys/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005flookup_002f3-2">rb_lookup/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005flookupall_002f3-2">rb_lookupall/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fmap_002f3-2">rb_map/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fmax_002f3-2">rb_max/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fmin_002f3-2">rb_min/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fnew_002f1-2">rb_new/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fnext_002f4-2">rb_next/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fpartial_005fmap_002f4-2">rb_partial_map/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fprevious_002f4-2">rb_previous/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fsize_002f2-2">rb_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fupdate_002f4-2">rb_update/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fvisit_002f2-2">rb_visit/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reachable_002f3-2">reachable/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_002f2-2">read/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005ffile_005fto_005fcodes_002f3-2">read_file_to_codes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005ffile_005fto_005fterms_002f3-2">read_file_to_terms/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005ffrom_005fchars_002f2-2">read_from_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fline_005fto_005fcodes_002f2-2">read_line_to_codes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fline_005fto_005fcodes_002f3-2">read_line_to_codes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fstream_005fto_005fcodes_002f3-2">read_stream_to_codes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fstream_005fto_005fcodes_002f3-5">read_stream_to_codes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fterm_002f2-2">read_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fterm_002f3-2">read_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorda_002f3-5">recorda/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordaifnot_002f3-2">recordaifnot/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordaifnot_002f3-5">recordaifnot/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorda_005fat_002f3-2">recorda_at/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordzifnot_002f3-2">recordzifnot/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordz_005fat_002f3-2">recordz_at/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reexport_002f1-2">reexport/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Re_002dExporting-Modules">5.5 Re-Exporting Predicates From Other Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reexport_002f2-2">reexport/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Re_002dExporting-Modules">5.5 Re-Exporting Predicates From Other Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-regexp_002f3-2">regexp/3</a></td><td>&nbsp;</td><td valign="top"><a href="#RegExp">7.18 Regular Expressions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-regexp_002f4-2">regexp/4</a></td><td>&nbsp;</td><td valign="top"><a href="#RegExp">7.18 Regular Expressions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-remove_005fduplicates_002f2-2">remove_duplicates/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-remove_005ffrom_005fpath_002f1-2">remove_from_path/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rename_005ffile_002f2-2">rename_file/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reset_005fop_005fcounters_002f0-2">reset_op_counters/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reset_005fstatic_005farray_002f1-2">reset_static_array/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-resize_005fstatic_005farray_002f3-2">resize_static_array/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-restore_002f1-2">restore/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-retract_002f1-2">retract/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-retractall_002f1-2">retractall/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reverse_002f2-2">reverse/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-S">S</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-same_005flength_002f2-2">same_length/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_002f2-2">save/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_005fprogram_002f1-2">save_program/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_005fprogram_002f2-2">save_program/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scan_005finteger_002f3-2">scan_integer/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scan_005fnatural_002f3-2">scan_natural/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-search_005ffor_002f2-2">search_for/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-search_005ffor_002f2-5">search_for/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-search_005ffor_002f2-8">search_for/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-select_002f3-2">select/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-selectchk_002f3-2">selectchk/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-selectlist_002f3-2">selectlist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-serve_005fqueue_002f3-2">serve_queue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setarg_002f3n-2">setarg/3n</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setenv_002f2-2">setenv/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setrand_002f1-2">setrand/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setup_005fcall_005fcatcher_005fcleanup_002f4-2">setup_call_catcher_cleanup/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setup_005fcall_005fcleanup_002f3-2">setup_call_cleanup/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005finput_002f1-2">set_input/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005foutput_002f1-2">set_output/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005fprolog_005fflag_002f2-2">set_prolog_flag/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005fstream_005fposition_002f2-2">set_stream_position/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005fvalue_002f2-2">set_value/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-shell_002f0-2">shell/0</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-shell_002f1-2">shell/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-shell_002f1-5">shell/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-showprofres_002f0-2">showprofres/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-showprofres_002f1-2">showprofres/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-show_005fops_005fby_005fgroup_002f1-2">show_ops_by_group/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-show_005fop_005fcounters_002f1-2">show_op_counters/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-show_005ftable_002f1-2">show_table/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-simple_002f1-2">simple/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-skip_002f2-2">skip/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sleep_002f1-2">sleep/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_002f2-2">socket/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_002f4-2">socket/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005faccept_002f2-2">socket_accept/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005faccept_002f2-5">socket_accept/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005faccept_002f3-2">socket_accept/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fbind_002f2-2">socket_bind/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fbuffering_002f4-2">socket_buffering/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fclose_002f1-2">socket_close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fconnect_002f3-2">socket_connect/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005flisten_002f2-2">socket_listen/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fselect_002f5-2">socket_select/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_002f0-2">source/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005ffile_002f1-2">source_file/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005ffile_002f2-2">source_file/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005flocation_002f2-2">source_location/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005fmode_002f2-2">source_mode/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005faccess_002f5-2">splay_access/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005fdelete_002f4-2">splay_delete/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005finit_002f3-2">splay_init/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005finsert_002f4-2">splay_insert/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005fjoin_002f3-2">splay_join/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005fsplit_002f5-2">splay_split/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-split_002f2-2">split/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-split_002f3-2">split/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-spy_005fwrite_002f2-2">spy_write/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-srandom_002f1-2">srandom/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-start_005flow_005flevel_005ftrace_002f0-2">start_low_level_trace/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Tracing">19 Tracing at Low Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-start_005flow_005flevel_005ftrace_002f0-5">start_low_level_trace/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Tracing">19 Tracing at Low Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-start_005fmatlab_002f1-2">start_matlab/1</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_002f3-2">static_array/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_002f3-5">static_array/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_005flocation_002f4-2">static_array_location/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_005fproperties_002f3-2">static_array_properties/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_005fto_005fterm_002f3-2">static_array_to_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-statistics_002f2-2">statistics/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fposition_002f2-2">stream_position/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fposition_005fdata_002f3-2">stream_position_data/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fproperty_002f2-2">stream_property/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fselect_002f3-2">stream_select/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-style_005fcheck_002f1-2">style_check/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-style_005fcheck_002f1-4">style_check/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sublist_002f2-2">sublist/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-subsumes_002f2-2">subsumes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-subsumes_005fchk_002f2-2">subsumes_chk/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-subsumes_005fterm_002f2-2">subsumes_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sub_005fatom_002f5-2">sub_atom/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-succ_002f3-2">succ/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-suffix_002f2-2">suffix/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumargs_002f4-2">sumargs/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumlist_002f2-2">sumlist/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumlist_002f4-2">sumlist/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumnodes_002f4-2">sumnodes/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sum_005flist_002f2-2">sum_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sum_005flist_002f3-2">sum_list/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_002f0-2">system/0</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_002f2-2">system/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_005fpredicate_002f2-2">system_predicate/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-T">T</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-tab_002f2-2">tab/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-table_002f1-2">table/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-table_005fstatistics_002f1-2">table_statistics/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tabling_005fmode_002f2-2">tabling_mode/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tabling_005fstatistics_002f0-2">tabling_statistics/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fattvars_002f2-2">term_attvars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fhash_002f2-2">term_hash/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fhash_002f4-2">term_hash/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fto_005fatom_002f2-2">term_to_atom/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fto_005fatom_002f2-5">term_to_atom/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fvariables_002f2-2">term_variables/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-threads_002f0-2">threads/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fat_005fexit_002f1-2">thread_at_exit/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fcreate_002f1-2">thread_create/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fcreate_002f2-2">thread_create/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fcreate_002f3-2">thread_create/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fdetach_002f1-2">thread_detach/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fexit_002f1-2">thread_exit/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fget_005fmessage_002f1-2">thread_get_message/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fget_005fmessage_002f2-2">thread_get_message/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fjoin_002f2-2">thread_join/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005flocal_002f1-_0028directive_0029-2">thread_local/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Threads-and-Dynamic-Predicates">16.3.3 Threads and Dynamic Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fpeek_005fmessage_002f1-2">thread_peek_message/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fpeek_005fmessage_002f2-2">thread_peek_message/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fproperty_002f2-2">thread_property/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fself_002f1-2">thread_self/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsend_005fmessage_002f1-2">thread_send_message/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsend_005fmessage_002f2-2">thread_send_message/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsetconcurrency_002f2-2">thread_setconcurrency/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsignal_002f2-2">thread_signal/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Signalling-Threads">16.3.2 Signalling Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsleep_002f1-2">thread_sleep/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fstatistics_002f3-2">thread_statistics/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fyield_002f0-2">thread_yield/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-throw_002f1-2">throw/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-time_002f1-2">time/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-time_005ffile_002f2-2">time_file/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-time_005fout_002f3-2">time_out/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Timeout">7.26 Calls With Timeout</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tmpnam_002f1-2">tmpnam/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tmp_005ffile_002f2-2">tmp_file/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-top_005fsort_002f2-2">top_sort/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-top_005fsort_002f3-2">top_sort/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-transitive_005fclosure_002f2-2">transitive_closure/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-transpose_002f3-2">transpose/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tree_005fsize_002f2-2">tree_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tree_005fto_005flist_002f2-2">tree_to_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fcheck_005fentry_002f3-2">trie_check_entry/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fclose_002f1-2">trie_close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fclose_005fall_002f0-2">trie_close_all/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fget_005fentry_002f2-2">trie_get_entry/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fload_002f2-2">trie_load/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fmax_005fstats_002f4-2">trie_max_stats/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fmode_002f1-2">trie_mode/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fopen_002f1-2">trie_open/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fprint_002f1-2">trie_print/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fput_005fentry_002f3-2">trie_put_entry/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fremove_005fentry_002f1-2">trie_remove_entry/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fremove_005fsubtree_002f1-2">trie_remove_subtree/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fsave_002f2-2">trie_save/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fstats_002f4-2">trie_stats/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fusage_002f4-2">trie_usage/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyget_002f1-2">ttyget/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyget0_002f1-2">ttyget0/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttynl_002f0-2">ttynl/0</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyput_002f1-2">ttyput/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyskip_002f1-2">ttyskip/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttytab_002f1-2">ttytab/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-U">U</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-ugraph_005fto_005fdgraph_002f2-2">ugraph_to_dgraph/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fadd_005fedges_002f3-2">undgraph_add_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fadd_005fvertices_002f3-2">undgraph_add_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fcomplement_002f2-2">undgraph_complement/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fdel_005fedges_002f3-2">undgraph_del_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fdel_005fvertices_002f3-2">undgraph_del_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fedge_002f2-2">undgraph_edge/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fedges_002f2-2">undgraph_edges/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fneighbors_002f3-2">undgraph_neighbors/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fneighbours_002f3-2">undgraph_neighbours/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fnew_002f1-2">undgraph_new/1</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fvertices_002f2-2">undgraph_vertices/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unhide_002f1-2">unhide/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unifiable_002f3-2">unifiable/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unify_005fwith_005foccurs_005fcheck_002f2-2">unify_with_occurs_check/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unix_002f1-2">unix/1</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unknown_002f2-2">unknown/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unknown_005fpredicate_005fhandler_002f3-2">unknown_predicate_handler/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unload_005fforeign_005flibrary_002f1-2">unload_foreign_library/1</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unload_005fforeign_005flibrary_002f2-2">unload_foreign_library/2</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-update_005farray_002f3-2">update_array/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-update_005fmutable_002f2-2">update_mutable/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fforeign_005flibrary_002f1-2">use_foreign_library/1</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fforeign_005flibrary_002f2-2">use_foreign_library/2</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fmodule_002f1-2">use_module/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fmodule_002f2-2">use_module/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fmodule_002f3-2">use_module/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-V">V</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-variables_005fwithin_005fterm_002f3-2">variables_within_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-variable_005fin_005fterm_002f2-2">variable_in_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-variant_002f2-2">variant/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-verify_005fattributes_002f3-2">verify_attributes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Attributed-Unification">11.2.3 Attributed Unification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-version_002f0-2">version/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-version_002f1-2">version/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-vertices_002f2-2">vertices/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-vertices_005fedges_005fto_005fugraph_002f3-2">vertices_edges_to_ugraph/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-W">W</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-wait_002f2-2">wait/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-when_002f2-2">when/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005fmutex_002f2-2">with_mutex/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_002f2-2">with_output_to/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_005fchars_002f2-2">with_output_to_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_005fchars_002f3-2">with_output_to_chars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_005fchars_002f4-2">with_output_to_chars/4</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-working_005fdirectory_002f2-2">working_directory/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-working_005fdirectory_002f2-5">working_directory/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_002f2-2">write/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-writeln_002f1-2">writeln/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-writeq_002f2-2">writeq/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fcanonical_002f1-2">write_canonical/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fcanonical_002f2-2">write_canonical/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fdepth_002f3-2">write_depth/3</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fterm_002f2-2">write_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fterm_002f3-2">write_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fto_005fchars_002f2-2">write_to_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fto_005fchars_002f3-2">write_to_chars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-C_002dProlog_cn_letter-Y">Y</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-yap_005fflag_002f2-2">yap_flag/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
</table>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_symbol-1"><b>-</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_symbol-2"><b>=</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_symbol-3"><b>\</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-J"><b>J</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-K"><b>K</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-M"><b>M</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-Q"><b>Q</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-W"><b>W</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-C_002dProlog_cn_letter-Y"><b>Y</b></a>
&nbsp;
</td></tr></table>
<hr>
<a name="Not-in-YAP"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Not-in-C_002dProlog" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#C_002dProlog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#SICStus-Prolog" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="YAP-predicates-not-available-in-C_002dProlog-1"></a>
<h3 class="subsection">25.1.5 YAP predicates not available in C-Prolog</h3>
<p>These are C-Prolog built-ins not available in YAP:
</p>
<dl compact="compact">
<dt><code>'LC'</code></dt>
<dd><p>The following Prolog text uses lower case letters.
</p>
</dd>
<dt><code>'NOLC'</code></dt>
<dd><p>The following Prolog text uses upper case letters only.
</p></dd>
</dl>
<hr>
<a name="SICStus-Prolog"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Not-in-YAP" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Major-Differences-with-SICStus" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Compatibility-with-the-Quintus-and-SICStus-Prolog-systems"></a>
<h2 class="section">25.2 Compatibility with the Quintus and SICStus Prolog systems</h2>
<p>The Quintus Prolog system was the first Prolog compiler to use Warren&rsquo;s
Abstract Machine. This system was very influential in the Prolog
community. Quintus Prolog implemented compilation into an abstract
machine code, which was then emulated. Quintus Prolog also included
several new built-ins, an extensive library, and in later releases a
garbage collector. The SICStus Prolog system, developed at SICS (Swedish
Institute of Computer Science), is an emulator based Prolog system
largely compatible with Quintus Prolog. SICStus Prolog has evolved
through several versions. The current version includes several
extensions, such as an object implementation, co-routining, and
constraints.
</p>
<p>Recent work in YAP has been influenced by work in Quintus and
SICStus Prolog. Wherever possible, we have tried to make YAP
compatible with recent versions of these systems, and specifically of
SICStus Prolog. You should use
</p><div class="example">
<pre class="example">:- yap_flag(language, sicstus).
</pre></div>
<p>for maximum compatibility with SICStus Prolog.
</p>
<table class="menu" border="0" cellspacing="0">
<tr><th colspan="3" align="left" valign="top"><pre class="menu-comment">SICStus Compatibility
</pre></th></tr><tr><td align="left" valign="top"><a href="#Major-Differences-with-SICStus">25.2.1 Major Differences between YAP and SICStus Prolog.</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Fully-SICStus-Compatible">25.2.2 YAP predicates fully compatible with SICStus Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
<tr><td align="left" valign="top"><a href="#Not-Strictly-SICStus-Compatible">25.2.3 YAP predicates not strictly compatible with SICStus Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"> YAP predicates not strictly as
SICStus Prolog
</td></tr>
<tr><td align="left" valign="top"><a href="#Not-in-SICStus-Prolog">25.2.4 YAP predicates not available in SICStus Prolog</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"></td></tr>
</table>
<hr>
<a name="Major-Differences-with-SICStus"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SICStus-Prolog" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SICStus-Prolog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Fully-SICStus-Compatible" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Major-Differences-between-YAP-and-SICStus-Prolog_002e"></a>
<h3 class="subsection">25.2.1 Major Differences between YAP and SICStus Prolog.</h3>
<p>Both YAP and SICStus Prolog obey the Edinburgh Syntax and are based on
the WAM. Even so, there are quite a few important differences:
</p>
<ul>
<li> Differently from SICStus Prolog, YAP does not have a
notion of interpreted code. All code in YAP is compiled.
</li><li> YAP does not support an intermediate byte-code
representation, so the <code>fcompile/1</code> and <code>load/1</code> built-ins are
not available in YAP.
</li><li> YAP implements escape sequences as in the ISO standard. SICStus
Prolog implements Unix-like escape sequences.
</li><li> YAP implements <code>initialization/1</code> as per the ISO
standard. Use <code>prolog_initialization/1</code> for the SICStus Prolog
compatible built-in.
</li><li> Prolog flags are different in SICStus Prolog and in YAP.
</li><li> The SICStus Prolog <code>on_exception/3</code> and
<code>raise_exception</code> built-ins correspond to the ISO built-ins
<code>catch/3</code> and <code>throw/1</code>.
</li><li> The following SICStus Prolog v3 built-ins are not (currently)
implemented in YAP (note that this is only a partial list):
<code>file_search_path/2</code>,
<code>stream_interrupt/3</code>, <code>reinitialize/0</code>, <code>help/0</code>,
<code>help/1</code>, <code>trimcore/0</code>, <code>load_files/1</code>,
<code>load_files/2</code>, and <code>require/1</code>.
<p> The previous list is incomplete. We also cannot guarantee full
compatibility for other built-ins (although we will try to address any
such incompatibilities). Last, SICStus Prolog is an evolving system, so
one can be expect new incompatibilities to be introduced in future
releases of SICStus Prolog.
</p>
</li><li> YAP allows asserting and abolishing static code during
execution through the <code>assert_static/1</code> and <code>abolish/1</code>
built-ins. This is not allowed in Quintus Prolog or SICStus Prolog.
</li><li> The socket predicates, although designed to be compatible with
SICStus Prolog, are built-ins, not library predicates, in YAP.
</li><li> This list is incomplete.
</li></ul>
<p>The following differences only exist if the <code>language</code> flag is set
to <code>yap</code> (the default):
</p>
<ul>
<li> The <code>consult/1</code> predicate in YAP follows C-Prolog
semantics. That is, it adds clauses to the data base, even for
preexisting procedures. This is different from <code>consult/1</code> in
SICStus Prolog.
<a name="index-update-semantics"></a>
</li><li> By default, the data-base in YAP follows &quot;immediate update
semantics&quot;, instead of &quot;logical update semantics&quot;, as Quintus Prolog or
SICStus Prolog do. The difference is depicted in the next example:
<div class="example">
<pre class="example">:- dynamic a/1.
?- assert(a(1)).
?- retract(a(X)), X1 is X +1, assertz(a(X)).
</pre></div>
<p>With immediate semantics, new clauses or entries to the data base are
visible in backtracking. In this example, the first call to
<code>retract/1</code> will succeed. The call to <strong>assertz/1</strong> will then
succeed. On backtracking, the system will retry
<code>retract/1</code>. Because the newly asserted goal is visible to
<code>retract/1</code>, it can be retracted from the data base, and
<code>retract(a(X))</code> will succeed again. The process will continue
generating integers for ever. Immediate semantics were used in C-Prolog.
</p>
<p>With logical update semantics, any additions or deletions of clauses
for a goal <em>will not affect previous activations of the
goal</em>. In the example, the call to <code>assertz/1</code> will not see the
update performed by the <code>assertz/1</code>, and the query will have a
single solution.
</p>
<p>Calling <code>yap_flag(update_semantics,logical)</code> will switch
YAP to use logical update semantics.
</p>
</li><li> <code>dynamic/1</code> is a built-in, not a directive, in YAP.
</li><li> By default, YAP fails on undefined predicates. To follow default
SICStus Prolog use:
<div class="example">
<pre class="example">:- yap_flag(unknown,error).
</pre></div>
</li><li> By default, directives in YAP can be called from the top level.
</li></ul>
<hr>
<a name="Fully-SICStus-Compatible"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Major-Differences-with-SICStus" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SICStus-Prolog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Not-Strictly-SICStus-Compatible" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="YAP-predicates-fully-compatible-with-SICStus-Prolog"></a>
<h3 class="subsection">25.2.2 YAP predicates fully compatible with SICStus Prolog</h3>
<p>These are the Prolog built-ins that are fully compatible in both SICStus
Prolog and YAP:
</p>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-1"><b>!</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-2"><b>,</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-3"><b>-</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-4"><b>;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-5"><b>&lt;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-6"><b>=</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-7"><b>&gt;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-8"><b>@</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-9"><b>\</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-J"><b>J</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-K"><b>K</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-M"><b>M</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-Q"><b>Q</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-W"><b>W</b></a>
&nbsp;
</td></tr></table>
<table class="index-sy" border="0">
<tr><td></td><th align="left">Index Entry</th><td>&nbsp;</td><th align="left"> Section</th></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-1">!</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0021_002f0-1">!/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-2">,</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002c_002f2-1">,/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-3">-</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002d_003e_002f2-1">-&gt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-4">;</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003b_002f2-1">;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-5">&lt;</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003c_002f2-1">&lt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-6">=</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_002e_002e_002f2-1">=../2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_002f2-1">=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_002f2-4">=/=2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_003a_003d_002f2-1">=:=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_003c_002f2-1">=&lt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_003d_002f2-1">==/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_005c_003d_002f2-1">=\=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-7">&gt;</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003e_002f2-1">&gt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003e_003d_002f2-1">&gt;=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-8">@</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003c_002f2-1">@&lt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003c_002f2-3">@&lt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003e_002f2-1">@&gt;/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003e_003d_002f2-1">@&gt;=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-9">\</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005c_002b_002f1-1">\+/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005c_003d_003d_002f2-1">\==/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-A">A</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-abort_002f0-1">abort/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-absolute_005ffile_005fname_002f2-1">absolute_file_name/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-absolute_005ffile_005fname_002f3-1">absolute_file_name/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fedges_002f3-1">add_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fto_005fheap_002f4-1">add_to_heap/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fvertices_002f3-1">add_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_002f3-1">aggregate/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_002f4-1">aggregate/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_005fall_002f3-1">aggregate_all/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_005fall_002f4-1">aggregate_all/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-append_002f2-1">append/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-append_002f3-1">append/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-arg_002f3-1">arg/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assoc_005fto_005flist_002f2-1">assoc_to_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_002f1-1">atom/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_002f1-1">atomic/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fcodes_002f2-1">atom_codes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fconcat_002f2-1">atom_concat/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fnumber_002f2-1">atom_number/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fto_005fchars_002f2-1">atom_to_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fto_005fchars_002f3-1">atom_to_chars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fto_005fterm_002f3-1">atom_to_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attribute_005fgoal_002f2-1">attribute_goal/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Displaying-Attributes">11.2.4 Displaying Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-at_005fend_005fof_005fstream_002f0-1">at_end_of_stream/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-at_005fend_005fof_005fstream_002f1-1">at_end_of_stream/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-B">B</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fdelete_002f2-1">bb_delete/2</a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fget_002f2-1">bb_get/2</a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fput_002f2-1">bb_put/2</a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fupdate_002f3-1">bb_update/3</a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-between_002f3-1">between/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-break_002f0-1">break/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-C">C</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-C_002f3-1">C/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_002f1-1">call/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-callable_002f1-1">callable/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcleanup_002f1-1">call_cleanup/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcleanup_002f2-1">call_cleanup/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fresidue_002f2-1">call_residue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fresidue_005fvars_002f2-1">call_residue_vars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-character_005fcount_002f2-1">character_count/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-char_005fcode_002f2-1">char_code/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-char_005fconversion_002f2-1">char_conversion/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cleanup_005fall_002f0-1">cleanup_all/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_002f1-1">close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compare_002f3-1">compare/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compile_002f1-1">compile/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compile_002f1-3">compile/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-complement_002f2-1">complement/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compose_002f3-1">compose/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compound_002f1-1">compound/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fterm_002f2-1">copy_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fterm_002f3-1">copy_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fterm_005fnat_002f2-1">copy_term_nat/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-create_005fmutable_002f2-1">create_mutable/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fatom_002f1-1">current_atom/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fchar_005fconversion_002f2-1">current_char_conversion/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005finput_002f1-1">current_input/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fkey_002f2-1">current_key/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fmodule_002f1-1">current_module/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Preds">6.21 Predicate Information</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fmodule_002f2-1">current_module/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Preds">6.21 Predicate Information</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fop_002f3-1">current_op/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005foutput_002f1-1">current_output/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fpredicate_002f1-1">current_predicate/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fpredicate_002f2-1">current_predicate/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fstream_002f3-1">current_stream/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cyclic_005fterm_002f1-1">cyclic_term/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cyclic_005fterm_002f1-4">cyclic_term/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-D">D</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-datime_002f1-1">datime/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005freference_002f1">db_reference/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-debugging_002f0-1">debugging/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-delete_002f3-1">delete/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-delete_005ffile_002f1-1">delete_file/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-delete_005ffile_002f2-1">delete_file/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fassoc_002f4-1">del_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fedges_002f3-1">del_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fmax_005fassoc_002f4-1">del_max_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fmin_005fassoc_002f4-1">del_min_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fvertices_002f3-1">del_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fvertex_002f3-1">dgraph_del_vertex/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fvertices_002f3-1">dgraph_del_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dif_002f2-1">dif/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-directory_005ffiles_002f2-1">directory_files/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-discontiguous_002f1-_0028directive_0029-1">discontiguous/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-display_002f1-1">display/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-display_002f1-4">display/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-display_002f2-1">display/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-duplicate_005fterm_002f2-1">duplicate_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-E">E</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-edges_002f2-1">edges/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-empty_005fassoc_002f1-1">empty_assoc/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-empty_005fheap_002f1-1">empty_heap/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-empty_005fqueue_002f1-1">empty_queue/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environ_002f2-1">environ/2</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environ_002f2-4">environ/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exception_002f3-1">exception/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exec_002f3-1">exec/3</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expand_005fterm_002f2-1">expand_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-F">F</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-fail_002f0-1">fail/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-false_002f0-1">false/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fileerrors_002f0-1">fileerrors/0</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fexists_002f1-1">file_exists/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fexists_002f2-1">file_exists/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fproperty_002f2-1">file_property/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fsearch_005fpath_002f2-1">file_search_path/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-findall_002f3-1">findall/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-findall_002f4-1">findall/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-flatten_002f2-1">flatten/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-float_002f1-1">float/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-flush_005foutput_002f0-1">flush_output/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-flush_005foutput_002f1-1">flush_output/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-foreach_002f2-1">foreach/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_005fto_005fchars_002f3-1">format_to_chars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_005fto_005fchars_002f4-1">format_to_chars/4</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fragile-1">fragile</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-freeze_002f2-1">freeze/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-free_005fvariables_002f4-1">free_variables/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-frozen_002f2-1">frozen/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-functor_002f3-1">functor/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-G">G</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-garbage_005fcollect_002f0-1">garbage_collect/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-garbage_005fcollect_005fatoms_002f0-1">garbage_collect_atoms/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-gc_002f0-1">gc/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-gen_005fassoc_002f3-1">gen_assoc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_002f1-1">get/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_002f2-1">get/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get0_002f1-1">get0/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get0_002f2-1">get0/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-getrand_002f1-1">getrand/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fassoc_002f3-1">get_assoc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fassoc_002f5-1">get_assoc/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fatts_002f2-1">get_atts/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Attribute-Manipulation">11.2.2 Attribute Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005ffrom_005fheap_002f4-1">get_from_heap/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005flabel_002f3-1">get_label/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fmutable_002f2-1">get_mutable/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fmutable_002f2-4">get_mutable/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fnext_005fassoc_002f4-1">get_next_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fprev_005fassoc_002f4-1">get_prev_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ground_002f1-1">ground/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-H">H</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-halt_002f0-1">halt/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-halt_002f1-1">halt/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-head_005fqueue_002f2-1">head_queue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-heap_005fsize_002f2-1">heap_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-heap_005fto_005flist_002f2-1">heap_to_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-host_005fid_002f1-1">host_id/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-host_005fname_002f1-1">host_name/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-I">I</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-if_002f3-1">if/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-incore_002f1-1">incore/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-initialization_002f0-1">initialization/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-integer_002f1-1">integer/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-intersection_002f3-1">intersection/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_002f2-1">is/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005fassoc_002f1-1">is_assoc/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005flist_002f1-1">is_list/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005fmutable_002f1-1">is_mutable/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-J">J</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-join_005fqueue_002f3-1">join_queue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-jump_005fqueue_002f3-1">jump_queue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-K">K</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-keysort_002f2-1">keysort/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-kill_002f2-1">kill/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-L">L</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-last_002f2-1">last/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-leash_002f1-1">leash/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-length_002f2-1">length/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-length_005fqueue_002f2-1">length_queue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-line_005fcount_002f2-1">line_count/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-line_005fposition_002f2-1">line_position/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-listing_002f1-1">listing/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fjoin_005fqueue_002f3-1">list_join_queue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fjump_005fqueue_002f3-1">list_jump_queue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005fassoc_002f2-1">list_to_assoc/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005fheap_002f2-1">list_to_heap/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005ford_005fset_002f2-1">list_to_ord_set/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005fqueue_002f2-1">list_to_queue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005ftree_002f2-1">list_to_tree/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-load_005ffiles_002f2-1">load_files/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-M">M</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-make_005fdirectory_002f2-1">make_directory/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-make_005fqueue_002f1-1">make_queue/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-map_005fassoc_002f2-1">map_assoc/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-map_005fassoc_002f3-1">map_assoc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-map_005ftree_002f3-1">map_tree/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005fassoc_002f3-1">max_assoc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005flist_002f2-1">max_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-member_002f2-1">member/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-memberchk_002f2-1">memberchk/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-merge_002f3-1">merge/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fhook_002f3-1">message_hook/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-meta_005fpredicate_002f1-_0028directive_0029-1">meta_predicate/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Meta_002dPredicates-in-Modules">5.4 Meta-Predicates in Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005fassoc_002f3-1">min_assoc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005flist_002f2-1">min_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005fof_005fheap_002f3-1">min_of_heap/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005fof_005fheap_002f5-1">min_of_heap/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mktemp_002f2-1">mktemp/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_002f1-1">module/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_002f2-_0028directive_0029-1">module/2 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_002f3-_0028directive_0029-1">module/3 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_005ftransparent_002f1-_0028directive_0029-1">module_transparent/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Meta_002dPredicates-in-Modules">5.4 Meta-Predicates in Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-multifile_002f1-_0028directive_0029-1">multifile/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-N">N</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-name_002f2-1">name/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-neighbors_002f3-1">neighbors/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-neighbours_002f3-1">neighbours/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nl_002f0-1">nl/0</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nl_002f1-1">nl/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nodebug_002f0-1">nodebug/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nofileerrors_002f0-1">nofileerrors/0</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nogc_002f0-1">nogc/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nonvar_002f1-1">nonvar/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nospy_002f1-1">nospy/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nospyall_002f0-1">nospyall/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-notrace_002f0-1">notrace/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_002f3-1">nth/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_002f4-1">nth/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth0_002f3-1">nth0/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth0_002f4-1">nth0/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth1_002f3-1">nth1/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth1_002f4-1">nth1/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_002f1-1">number/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-numbervars_002f3-1">numbervars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fcodes_002f2-1">number_codes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fto_005fchars_002f2-1">number_to_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fto_005fchars_002f3-1">number_to_chars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-numlist_002f3-1">numlist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-O">O</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-on_005fcleanup_002f1-1">on_cleanup/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-op_002f3-1">op/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_002f3-1">open/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fchars_005fstream_002f2-1">open_chars_stream/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ordsubset_002f2-1">ordsubset/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fadd_005felement_002f3-1">ord_add_element/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fdel_005felement_002f3-1">ord_del_element/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fdisjoint_002f2-1">ord_disjoint/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005finsert_002f3-1">ord_insert/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fintersect_002f2-1">ord_intersect/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fintersect_002f3-1">ord_intersect/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fintersect_002f4-1">ord_intersect/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005flist_005fto_005fassoc_002f2-1">ord_list_to_assoc/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fmember_002f2-1">ord_member/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fseteq_002f2-1">ord_seteq/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fsetproduct_002f3-1">ord_setproduct/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fsubtract_002f3-1">ord_subtract/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fsymdiff_002f3-1">ord_symdiff/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005funion_002f2-1">ord_union/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005funion_002f3-1">ord_union/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005funion_002f4-1">ord_union/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-P">P</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fchar_002f1-1">peek_char/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-permutation_002f2-1">permutation/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-phrase_002f2-1">phrase/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-phrase_002f3-1">phrase/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-pid_002f1-1">pid/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-plus_002f3-1">plus/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-popen_002f3-1">popen/3</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-portray_005fclause_002f1-1">portray_clause/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-portray_005fclause_002f2-1">portray_clause/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-primitive_002f1-1">primitive/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_002f1-1">print/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_002f2-1">print/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_005fmessage_002f2-1">print_message/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_005fmessage_005flines_002f3-1">print_message_lines/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-project_005fattributes_002f2-1">project_attributes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Displaying-Attributes">11.2.4 Displaying Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-project_005fattributes_002f2-4">project_attributes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Projecting-Attributes">11.2.5 Projecting Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005ffile_005fname_002f1">prolog_file_name/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005fflag_002f3-1">prolog_flag/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005fload_005fcontext_002f2-1">prolog_load_context/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prompt_002f2-1">prompt/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_002f1-1">put/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_002f2-1">put/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fassoc_002f4-1">put_assoc/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fatts_002f2-1">put_atts/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Attribute-Manipulation">11.2.2 Attribute Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005flabel_002f4-1">put_label/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-Q">Q</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-queue_005fto_005flist_002f2-1">queue_to_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-R">R</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-random_002f1-1">random/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-random_002f3-1">random/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-randseq_002f3-1">randseq/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-randset_002f3-1">randset/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rational_002f1-1">rational/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reachable_002f3-1">reachable/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_002f1-1">read/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_002f2-1">read/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005ffrom_005fchars_002f2-1">read_from_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-remove_005fduplicates_002f2-1">remove_duplicates/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rename_005ffile_002f2-1">rename_file/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-repeat_002f0-1">repeat/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-restore_002f1-1">restore/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reverse_002f2-1">reverse/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-S">S</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-same_005flength_002f2-1">same_length/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_005fprogram_002f1-1">save_program/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_005fprogram_002f2-1">save_program/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-see_002f1-1">see/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-seeing_002f1-1">seeing/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-seen_002f0-1">seen/0</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-select_002f3-1">select/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-serve_005fqueue_002f3-1">serve_queue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setrand_002f1-1">setrand/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005finput_002f1-1">set_input/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005foutput_002f1-1">set_output/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005fstream_005fposition_002f2-1">set_stream_position/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-shell_002f0-1">shell/0</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-shell_002f1-1">shell/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-shell_002f1-4">shell/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-simple_002f1-1">simple/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-skip_002f1-1">skip/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-skip_002f2-1">skip/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sleep_002f1-1">sleep/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_002f2-1">socket/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_002f4-1">socket/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005faccept_002f2-1">socket_accept/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005faccept_002f2-4">socket_accept/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005faccept_002f3-1">socket_accept/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fbind_002f2-1">socket_bind/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fbuffering_002f4-1">socket_buffering/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fclose_002f1-1">socket_close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fconnect_002f3-1">socket_connect/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005flisten_002f2-1">socket_listen/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fselect_002f5-1">socket_select/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sort_002f2-1">sort/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005ffile_002f1-1">source_file/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005ffile_002f2-1">source_file/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005flocation_002f2-1">source_location/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-spy_002f1-1">spy/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fposition_002f2-1">stream_position/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fposition_005fdata_002f3-1">stream_position_data/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fselect_002f3-1">stream_select/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sublist_002f2-1">sublist/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-subsumes_002f2-1">subsumes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-subsumes_005fchk_002f2-1">subsumes_chk/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-subsumes_005fterm_002f2-1">subsumes_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-succ_002f3-1">succ/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-suffix_002f2-1">suffix/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumlist_002f2-1">sumlist/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sum_005flist_002f2-1">sum_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sum_005flist_002f3-1">sum_list/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_002f0-1">system/0</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_002f2-1">system/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_005fpredicate_002f2-1">system_predicate/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-T">T</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-tab_002f1-1">tab/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tab_002f2-1">tab/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tell_002f1-1">tell/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-telling_002f1-1">telling/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fexpansion_002f2-1">term_expansion/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fhash_002f2-1">term_hash/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fhash_002f4-1">term_hash/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fto_005fatom_002f2-1">term_to_atom/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fvariables_002f2-1">term_variables/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-time_005fout_002f3-1">time_out/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Timeout">7.26 Calls With Timeout</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tmpnam_002f1-1">tmpnam/1</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-told_002f0-1">told/0</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-top_005fsort_002f2-1">top_sort/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-top_005fsort_002f3-1">top_sort/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trace_002f0-1">trace/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-transitive_005fclosure_002f2-1">transitive_closure/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-transpose_002f3-1">transpose/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tree_005fsize_002f2-1">tree_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tree_005fto_005flist_002f2-1">tree_to_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-true_002f0-1">true/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyget_002f1-1">ttyget/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyget0_002f1-1">ttyget0/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttynl_002f0-1">ttynl/0</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyput_002f1-1">ttyput/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyskip_002f1-1">ttyskip/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttytab_002f1-1">ttytab/1</a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-U">U</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fdel_005fvertices_002f3-1">undgraph_del_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unifiable_002f3-1">unifiable/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unify_005fwith_005foccurs_005fcheck_002f2-1">unify_with_occurs_check/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unknown_005fpredicate_005fhandler_002f3-1">unknown_predicate_handler/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-update_005fmutable_002f2-1">update_mutable/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fmodule_002f1-1">use_module/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fmodule_002f2-1">use_module/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fmodule_002f3-1">use_module/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-V">V</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-var_002f1-1">var/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-variant_002f2-1">variant/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-verify_005fattributes_002f3-1">verify_attributes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Attributed-Unification">11.2.3 Attributed Unification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-version_002f1-1">version/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-vertices_002f2-1">vertices/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-vertices_005fedges_005fto_005fugraph_002f3-1">vertices_edges_to_ugraph/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-W">W</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-wait_002f2-1">wait/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-when_002f2-1">when/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_005fchars_002f2-1">with_output_to_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_005fchars_002f3-1">with_output_to_chars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_005fchars_002f4-1">with_output_to_chars/4</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-working_005fdirectory_002f2-1">working_directory/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_002f1-1">write/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_002f2-1">write/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-writeq_002f1-1">writeq/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-writeq_002f2-1">writeq/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fcanonical_002f1-1">write_canonical/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fcanonical_002f2-1">write_canonical/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fterm_002f2-1">write_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fterm_002f3-1">write_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fto_005fchars_002f2-1">write_to_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fto_005fchars_002f3-1">write_to_chars/3</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
</table>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-1"><b>!</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-2"><b>,</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-3"><b>-</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-4"><b>;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-5"><b>&lt;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-6"><b>=</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-7"><b>&gt;</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-8"><b>@</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_symbol-9"><b>\</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-J"><b>J</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-K"><b>K</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-M"><b>M</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-Q"><b>Q</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-fully-compatible-with-SICStus-Prolog_sy_letter-W"><b>W</b></a>
&nbsp;
</td></tr></table>
<hr>
<a name="Not-Strictly-SICStus-Compatible"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Fully-SICStus-Compatible" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SICStus-Prolog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Not-in-SICStus-Prolog" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog"></a>
<h3 class="subsection">25.2.3 YAP predicates not strictly compatible with SICStus Prolog</h3>
<p>These are YAP built-ins that are also available in SICStus Prolog, but
that are not fully compatible:
</p>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_symbol-1"><b>[</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-W"><b>W</b></a>
&nbsp;
</td></tr></table>
<table class="index-sa" border="0">
<tr><td></td><th align="left">Index Entry</th><td>&nbsp;</td><th align="left"> Section</th></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_symbol-1">[</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005b_002d_005d_002f1-1">[-]/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005b_005d_002f1-1">[]/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-A">A</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_002f1-1">abolish/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_002f2-1">abolish/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assert_002f1-1">assert/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assert_002f2-1">assert/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-asserta_002f1-1">asserta/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-asserta_002f2-1">asserta/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assertz_002f1-1">assertz/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assertz_002f2-1">assertz/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fchars_002f2-1">atom_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-B">B</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-bagof_002f3-1">bagof/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-C">C</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-clause_002f2-1">clause/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-clause_002f3-1">clause/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_002f2-1">close/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fline_005fnumber_002f1-1">current_line_number/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fline_005fnumber_002f2-1">current_line_number/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-D">D</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-debug_002f0-1">debug/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dynamic_002f1-1">dynamic/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Database">6.10 Using the Clausal Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-E">E</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-erase_002f1-1">erase/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-erased_002f1-1">erased/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-F">F</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_002f1-1">format/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_002f2-1">format/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_002f3-1">format/3</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-I">I</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-instance_002f2-1">instance/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-L">L</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-listing_002f0-1">listing/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-N">N</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_005fclause_002f3-1">nth_clause/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_005finstance_002f3-1">nth_instance/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_005finstance_002f4-1">nth_instance/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fchars_002f2-1">number_chars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-O">O</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_002f4-1">open/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-P">P</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-predicate_005fproperty_002f2-1">predicate_property/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005finitialization_002f1-1">prolog_initialization/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-R">R</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fterm_002f2-1">read_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fterm_002f3-1">read_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorda_002f3-1">recorda/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordaifnot_002f3-1">recordaifnot/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorded_002f3-1">recorded/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordz_002f3-1">recordz/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-retract_002f1-1">retract/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-retract_002f2-1">retract/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-retractall_002f1-1">retractall/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-S">S</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-setof_002f3-1">setof/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-statistics_002f0-1">statistics/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-statistics_002f2-1">statistics/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-U">U</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-unknown_002f2-1">unknown/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-V">V</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-version_002f0-1">version/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-W">W</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_002f2-1">with_output_to/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
</table>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_symbol-1"><b>[</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-strictly-compatible-with-SICStus-Prolog_sa_letter-W"><b>W</b></a>
&nbsp;
</td></tr></table>
<hr>
<a name="Not-in-SICStus-Prolog"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Not-Strictly-SICStus-Compatible" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#SICStus-Prolog" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#ISO-Prolog" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="YAP-predicates-not-available-in-SICStus-Prolog"></a>
<h3 class="subsection">25.2.4 YAP predicates not available in SICStus Prolog</h3>
<p>These are YAP built-ins not available in SICStus Prolog.
</p>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_symbol-1"><b>-</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_symbol-2"><b>=</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_symbol-3"><b>\</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-K"><b>K</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-M"><b>M</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-W"><b>W</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-Y"><b>Y</b></a>
&nbsp;
</td></tr></table>
<table class="index-sn" border="0">
<tr><td></td><th align="left">Index Entry</th><td>&nbsp;</td><th align="left"> Section</th></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_symbol-1">-</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002d_003e_002a_002f2-1">-&gt;*/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_symbol-2">=</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_0040_003d_002f2-1">=@=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_symbol-3">\</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005c_003d_002f2-1">\=/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-A">A</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_005fall_005ftables_002f0-1">abolish_all_tables/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_005ftable_002f1-1">abolish_table/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fto_005farray_005felement_002f4-1">add_to_array_element/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-alarm_002f3-1">alarm/3</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-all_002f3-1">all/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-always_005fprompt_005fuser_002f0-1">always_prompt_user/0</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-append_002f3-4">append/3</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-array_002f2-1">array/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-array_005felement_002f3-1">array_element/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-asserta_005fstatic_002f1-1">asserta_static/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assertz_005fstatic_002f1-1">assertz_static/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assert_005fstatic_002f1-1">assert_static/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_005fconcat_002f2-1">atomic_concat/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_005flist_005fconcat_002f2-1">atomic_list_concat/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_005flist_005fconcat_002f3-1">atomic_list_concat/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fconcat_002f3-1">atom_concat/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005flength_002f2-1">atom_length/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attribute_005fgoals_002f2-1">attribute_goals/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attr_005fportray_005fhook_002f2-1">attr_portray_hook/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attr_005funify_005fhook_002f2-1">attr_unify_hook/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attvar_002f1-1">attvar/1</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attvar_002f1-4">attvar/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Attributed-Unification">11.2.3 Attributed Unification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-avl_005finsert_002f4-1">avl_insert/4</a></td><td>&nbsp;</td><td valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-avl_005flookup_002f3-1">avl_lookup/3</a></td><td>&nbsp;</td><td valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-avl_005fnew_002f1-1">avl_new/1</a></td><td>&nbsp;</td><td valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-B">B</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-between_002f3-4">between/3</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fgetval_002f2-1">b_getval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fgetval_002f2-4">b_getval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fsetval_002f2-1">b_setval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fsetval_002f2-4">b_setval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-C">C</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_002fn-1">call/n</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcount_005fdata_002f0-1">call_count_data/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcount_005fdata_002f3-1">call_count_data/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcount_005fdata_002f3-4">call_count_data/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fshared_005fobject_005ffunction_002f2-1">call_shared_object_function/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fwith_005fargs_002fn-1">call_with_args/n</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-catch_002f3-1">catch/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cd_002f1-1">cd/1</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-char_005ftype_002f2-1">char_type/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-chdir_002f1-1">chdir/1</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-checklist_002f2-1">checklist/2</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-checknodes_002f3-1">checknodes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_005fmatlab_002f0-1">close_matlab/0</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_005fshared_005fobject_002f1-1">close_shared_object/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_005fstatic_005farray_002f1-1">close_static_array/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-code_005ftype_002f2-1">code_type/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compile_002f1-_0028directive_0029">compile/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compile_005fexpressions_002f0-1">compile_expressions/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-concat_005fatom_002f2-1">concat_atom/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-concat_005fatom_002f3-1">concat_atom/3</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-consult_002f1-1">consult/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-convlist_002f3-1">convlist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fline_002f2-1">copy_line/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fline_002f2-4">copy_line/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-create_005fprolog_005fflag_002f2-1">create_prolog_flag/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fforeign_005flibrary_002f2-1">current_foreign_library/2</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fmutex_002f3-1">current_mutex/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fprolog_005fflag_002f2-1">current_prolog_flag/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fthread_002f2-1">current_thread/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-D">D</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fassert_002f1-1">db_assert/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fassert_002f2-1">db_assert/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fclose_002f1-1">db_close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdatalog_005fdescribe_002f1-1">db_datalog_describe/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdatalog_005fdescribe_002f2-1">db_datalog_describe/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdescribe_002f1-1">db_describe/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdescribe_002f2-1">db_describe/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fget_005fattributes_005ftypes_002f2-1">db_get_attributes_types/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Types-of-Attributes">15.9 Types of Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fget_005fattributes_005ftypes_002f3-1">db_get_attributes_types/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Types-of-Attributes">15.9 Types of Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fimport_002f2-1">db_import/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-a-Relation">15.5 Accessing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fimport_002f3-1">db_import/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-a-Relation">15.5 Accessing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005finsert_002f2-1">db_insert/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005finsert_002f3-1">db_insert/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmodule_002f1-1">db_module/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmy_005fresult_005fset_002f1-1">db_my_result_set/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmy_005fsql_005fmode_002f1-1">db_my_sql_mode/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmy_005fsql_005fmode_002f2-1">db_my_sql_mode/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fnumber_005fof_005ffields_002f2-1">db_number_of_fields/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Number-of-Fields">15.10 Number of Fields</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fnumber_005fof_005ffields_002f3-1">db_number_of_fields/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Number-of-Fields">15.10 Number of Fields</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fopen_002f4-1">db_open/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fopen_002f5-1">db_open/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fshow_005ftables_002f1-1">db_show_tables/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Enumerating-Relations">15.12 Enumeration Relations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fshow_005ftables_002f2-1">db_show_tables/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Enumerating-Relations">15.12 Enumeration Relations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fsql_002f2-1">db_sql/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-Tables-in-Data-Sources-Using-SQL">15.7 Accessing Tables in Data Sources Using SQL</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fsql_002f3-1">db_sql/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-Tables-in-Data-Sources-Using-SQL">15.7 Accessing Tables in Data Sources Using SQL</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005ftop_005flevel_002f4-1">db_top_level/4</a></td><td>&nbsp;</td><td valign="top"><a href="#The-MYDDAS-MySQL-Top-Level">15.13 The MYDDAS MySQL Top Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005ftop_005flevel_002f5-1">db_top_level/5</a></td><td>&nbsp;</td><td valign="top"><a href="#The-MYDDAS-MySQL-Top-Level">15.13 The MYDDAS MySQL Top Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fview_002f2-1">db_view/2</a></td><td>&nbsp;</td><td valign="top"><a href="#View-Level-Interface">15.6 View Level Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fview_002f3-1">db_view/3</a></td><td>&nbsp;</td><td valign="top"><a href="#View-Level-Interface">15.6 View Level Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fattr_002f2-1">del_attr/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fattrs_002f1-1">del_attrs/1</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fedge_002f4-1">dgraph_add_edge/4</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fedges_002f3-1">dgraph_add_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fvertex_002f3-1">dgraph_add_vertex/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fvertices_002f3-1">dgraph_add_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fcomplement_002f2-1">dgraph_complement/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fcompose_002f3-1">dgraph_compose/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fedge_002f4-1">dgraph_del_edge/4</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fedges_002f3-1">dgraph_del_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fedge_002f2-1">dgraph_edge/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fedges_002f2-1">dgraph_edges/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fisomorphic_002f4-1">dgraph_isomorphic/4</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fmax_005fpath_002f5-1">dgraph_max_path/5</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fmin_005fpath_002f5-1">dgraph_min_path/5</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fmin_005fpaths_002f3-1">dgraph_min_paths/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fneighbors_002f3-1">dgraph_neighbors/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fneighbours_002f3-1">dgraph_neighbours/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fnew_002f1-1">dgraph_new/1</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fpath_002f3-1">dgraph_path/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fpath_002f3-4">dgraph_path/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fsymmetric_005fclosure_002f2-1">dgraph_symmetric_closure/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftop_005fsort_002f2-1">dgraph_top_sort/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftop_005fsort_002f3-1">dgraph_top_sort/3</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fto_005fugraph_002f2-1">dgraph_to_ugraph/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fto_005fundgraph_002f2-1">dgraph_to_undgraph/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftransitive_005fclosure_002f2-1">dgraph_transitive_closure/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftranspose_002f2-1">dgraph_transpose/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fvertices_002f2-1">dgraph_vertices/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-do_005fnot_005fcompile_005fexpressions_002f0-1">do_not_compile_expressions/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dynamic_005fpredicate_002f2-1">dynamic_predicate/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Database">6.10 Using the Clausal Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-E">E</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-elif_002f1">elif/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-else_002f0">else/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-endif_002f0">endif/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-eraseall_002f1-1">eraseall/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exclude_002f3-1">exclude/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exists_002f1-1">exists/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expand_005fexprs_002f2-1">expand_exprs/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-F">F</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-fields_002f2-1">fields/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fields_002f3-1">fields/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fbase_005fname_002f2-1">file_base_name/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005ffilter_002f3-1">file_filter/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005ffilter_005fwith_005finit_002f5-1">file_filter_with_init/5</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fname_005fextension_002f3-1">file_name_extension/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-filter_002f3-1">filter/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-forall_002f2-1">forall/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-forall_002f2-4">forall/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Forall">8.2 Forall</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-G">G</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-getcwd_002f1-1">getcwd/1</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fattr_002f3-1">get_attr/3</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fattrs_002f2-1">get_attrs/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fbyte_002f1-1">get_byte/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fbyte_002f2-1">get_byte/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fchar_002f1-1">get_char/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fchar_002f2-1">get_char/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fcode_002f1-1">get_code/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fcode_002f2-1">get_code/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fvalue_002f2-1">get_value/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-glue_002f3-1">glue/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-goal_005fexpansion_002f3-1">goal_expansion/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-grow_005fheap_002f1">grow_heap/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-grow_005fstack_002f1-1">grow_stack/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-H">H</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-hide_002f1-1">hide/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-hide_005fpredicate_002f1-1">hide_predicate/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-I">I</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-if_002f1">if/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ignore_002f1-1">ignore/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-include_002f3-1">include/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-initialization_002f1-_0028directive_0029-1">initialization/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-initialization_002f2-_0028directive_0029-1">initialization/2 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005frbtree_002f1-1">is_rbtree/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005fstream_002f1-1">is_stream/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005ftabled_002f1-1">is_tabled/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-K">K</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-key_005fstatistics_002f3-1">key_statistics/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-key_005fstatistics_002f4-1">key_statistics/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-L">L</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-library_005fdirectory_002f1-1">library_directory/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-library_005fdirectory_002f1-4">library_directory/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fconcat_002f2-1">list_concat/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005frbtree_002f2-1">list_to_rbtree/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005frbtree_002f2-4">list_to_rbtree/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-load_005fforeign_005flibrary_002f1-1">load_foreign_library/1</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-load_005fforeign_005flibrary_002f2-1">load_foreign_library/2</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-M">M</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-make_002f0-1">make/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mapargs_002f3-1">mapargs/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f2-1">maplist/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f3-1">maplist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f3-4">maplist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f3-7">maplist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f4-1">maplist/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f4-4">maplist/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f5-1">maplist/5</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mapnodes_002f3-1">mapnodes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fcells_002f2-1">matlab_cells/2</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fcells_002f3-1">matlab_cells/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005feval_005fstring_002f1-1">matlab_eval_string/1</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005feval_005fstring_002f2-1">matlab_eval_string/2</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fget_005fvariable_002f2-1">matlab_get_variable/2</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005finitialized_005fcells_002f4-1">matlab_initialized_cells/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f3-1">matlab_item/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f3-4">matlab_item/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f4-1">matlab_item/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f4-4">matlab_item/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fmatrix_002f4-1">matlab_matrix/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fon_002f0-1">matlab_on/0</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fsequence_002f3-1">matlab_sequence/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fset_002f4-1">matlab_set/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fvector_002f4-1">matlab_vector/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f2-1">matlab_zeros/2</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f3-1">matlab_zeros/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f4-1">matlab_zeros/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f4-4">matlab_zeros/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fadd_002f3-1">matrix_add/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fagg_005fcols_002f2-1">matrix_agg_cols/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fagg_005flines_002f2-1">matrix_agg_lines/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005farg_005fto_005foffset_002f3-1">matrix_arg_to_offset/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fdec_002f2-1">matrix_dec/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fdec_002f3-1">matrix_dec/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fdims_002f2-1">matrix_dims/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fexpand_002f3-1">matrix_expand/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fget_002f3-1">matrix_get/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005finc_002f2-1">matrix_inc/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005finc_002f3-1">matrix_inc/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fmax_002f2-1">matrix_max/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fmaxarg_002f2-1">matrix_maxarg/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fmin_002f2-1">matrix_min/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fminarg_002f2-1">matrix_minarg/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fndims_002f2-1">matrix_ndims/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fnew_002f3-1">matrix_new/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fnew_002f4-1">matrix_new/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fnew_005fset_002f4-1">matrix_new_set/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005foffset_005fto_005farg_002f3-1">matrix_offset_to_arg/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_002f4-1">matrix_op/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_002f4-4">matrix_op/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_005fto_005fcols_002f4-1">matrix_op_to_cols/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_005fto_005flines_002f4-1">matrix_op_to_lines/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005freorder_002f3-1">matrix_reorder/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005frow_002f3-1">matrix_row/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fselect_002f4-1">matrix_select/4</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fset_002f3-1">matrix_set/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fset_005fall_002f2-1">matrix_set_all/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fshuffle_002f3-1">matrix_shuffle/3</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fsize_002f2-1">matrix_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fsum_002f2-1">matrix_sum/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fto_005flist_002f2-1">matrix_to_list/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005ftype_002f2-1">matrix_type/2</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fqueue_005fcreate_002f1-1">message_queue_create/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fqueue_005fdestroy_002f1-1">message_queue_destroy/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fto_005fstring_002f2-1">message_to_string/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mktime_002f2-1">mktime/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbarrier_002f0-1">mpi_barrier/0</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbcast_002f2-1">mpi_bcast/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbcast_002f3-1">mpi_bcast/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbcast_002f3-4">mpi_bcast/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fcomm_005frank_002f1-1">mpi_comm_rank/1</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fcomm_005fsize_002f1-1">mpi_comm_size/1</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005ffinalize_002f0-1">mpi_finalize/0</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fgc_002f0-1">mpi_gc/0</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005finit_002f0-1">mpi_init/0</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005firecv_002f3-1">mpi_irecv/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fisend_002f4-1">mpi_isend/4</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005frecv_002f3-1">mpi_recv/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fsend_002f3-1">mpi_send/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005ftest_002f2-1">mpi_test/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005ftest_005frecv_002f3-1">mpi_test_recv/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fversion_002f2-1">mpi_version/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fwait_002f2-1">mpi_wait/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fwait_005frecv_002f3-1">mpi_wait_recv/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005fcreate_002f1-1">mutex_create/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005fdestroy_002f1-1">mutex_destroy/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005flock_002f1-1">mutex_lock/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005fstatistics_002f0-1">mutex_statistics/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005ftrylock_002f1-1">mutex_trylock/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005funlock_002f1-1">mutex_unlock/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005funlock_005fall_002f0-1">mutex_unlock_all/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-N">N</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_002f1-1">nb_beam/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fadd_002f3-1">nb_beam_add/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fclose_002f1-1">nb_beam_close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fdel_002f3-1">nb_beam_del/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fempty_002f1-1">nb_beam_empty/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fpeek_002f3-1">nb_beam_peek/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fsize_002f2-1">nb_beam_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fcurrent_002f2-1">nb_current/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fcurrent_002f2-4">nb_current/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fdelete_002f1-1">nb_delete/1</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fdelete_002f2-1">nb_delete/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fgetval_002f2-1">nb_getval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fgetval_002f2-4">nb_getval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_002f1-1">nb_heap/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fadd_002f3-1">nb_heap_add/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fclose_002f1-1">nb_heap_close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fdel_002f3-1">nb_heap_del/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fempty_002f1-1">nb_heap_empty/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fpeek_002f3-1">nb_heap_peek/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fsize_002f2-1">nb_heap_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005flinkval_002f2-1">nb_linkval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005flnkarg_002f3">nb_lnkarg/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_002f1-1">nb_queue/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fclose_002f3-1">nb_queue_close/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fdequeue_002f2-1">nb_queue_dequeue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fempty_002f1-1">nb_queue_empty/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fenqueue_002f2-1">nb_queue_enqueue/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fpeek_002f2-1">nb_queue_peek/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fsize_002f2-1">nb_queue_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fsetarg_002f3-1">nb_setarg/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fsetval_002f2-1">nb_setval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fsetval_002f2-4">nb_setval/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fset_005fshared_005farg_002f3-1">nb_set_shared_arg/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fset_005fshared_005fval_002f2-1">nb_set_shared_val/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-new_005fvariables_005fin_005fterm_002f3-1">new_variables_in_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-not_002f1-1">not/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-no_005fsource_002f0-1">no_source/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth1_002f3-4">nth1/3</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fatom_002f2-1">number_atom/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-O">O</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-once_002f1-1">once/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-on_005fsignal_002f3-1">on_signal/3</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fshared_005fobject_002f2-1">open_shared_object/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fshared_005fobject_002f3-1">open_shared_object/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-P">P</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-partition_002f4-1">partition/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-partition_002f5-1">partition/5</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-path_002f1-1">path/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-path_002f1-3">path/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-path_002f1-5">path/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fbyte_002f1-1">peek_byte/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fbyte_002f2-1">peek_byte/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fchar_002f2-1">peek_char/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fcode_002f1-1">peek_code/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fcode_002f2-1">peek_code/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-predsort_002f3-1">predsort/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-process_002f2-1">process/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profiled_005freset_002f0-1">profiled_reset/0</a></td><td>&nbsp;</td><td valign="top"><a href="#The-Count-Profiler">6.18.1 The Count Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profile_005fdata_002f3-1">profile_data/3</a></td><td>&nbsp;</td><td valign="top"><a href="#The-Count-Profiler">6.18.1 The Count Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profinit_002f0-1">profinit/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profoff_002f0-1">profoff/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profon_002f0-1">profon/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-public_002f1-_0028directive_0029-1">public/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-putenv_002f2-1">putenv/2</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fattr_002f3-1">put_attr/3</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fattrs_002f2-1">put_attrs/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fbyte_002f1-1">put_byte/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fbyte_002f2-1">put_byte/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fchar_002f1-1">put_char/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fchar_002f2-1">put_char/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fcode_002f1-1">put_code/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fcode_002f2-1">put_code/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-R">R</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-rannum_002f1-1">rannum/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ranstart_002f0-1">ranstart/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ranstart_002f1-1">ranstart/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ranunif_002f2-1">ranunif/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fapply_002f4-1">rb_apply/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fclone_002f3-1">rb_clone/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdelete_002f3-1">rb_delete/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdelete_002f4-1">rb_delete/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdel_005fmax_002f4-1">rb_del_max/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdel_005fmin_002f4-1">rb_del_min/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fempty_002f1-1">rb_empty/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005finsert_002f4-1">rb_insert/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005finsert_005fnew_002f4">rb_insert_new/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fkeys_002f2-1">rb_keys/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005flookup_002f3-1">rb_lookup/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005flookupall_002f3-1">rb_lookupall/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fmap_002f3-1">rb_map/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fmax_002f3-1">rb_max/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fmin_002f3-1">rb_min/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fnew_002f1-1">rb_new/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fnext_002f4-1">rb_next/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fpartial_005fmap_002f4-1">rb_partial_map/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fprevious_002f4-1">rb_previous/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fsize_002f2-1">rb_size/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fupdate_002f4-1">rb_update/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fvisit_002f2-1">rb_visit/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005ffile_005fto_005fcodes_002f3-1">read_file_to_codes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005ffile_005fto_005fterms_002f3-1">read_file_to_terms/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fline_005fto_005fcodes_002f2-1">read_line_to_codes/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fline_005fto_005fcodes_002f3-1">read_line_to_codes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fstream_005fto_005fcodes_002f3-1">read_stream_to_codes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fstream_005fto_005fcodes_002f3-4">read_stream_to_codes/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reconsult_002f1-1">reconsult/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorda_002f3-4">recorda/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordaifnot_002f3-4">recordaifnot/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorda_005fat_002f3-1">recorda_at/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordzifnot_002f3-1">recordzifnot/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordz_005fat_002f3-1">recordz_at/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reexport_002f1-1">reexport/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Re_002dExporting-Modules">5.5 Re-Exporting Predicates From Other Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reexport_002f2-1">reexport/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Re_002dExporting-Modules">5.5 Re-Exporting Predicates From Other Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-regexp_002f3-1">regexp/3</a></td><td>&nbsp;</td><td valign="top"><a href="#RegExp">7.18 Regular Expressions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-regexp_002f4-1">regexp/4</a></td><td>&nbsp;</td><td valign="top"><a href="#RegExp">7.18 Regular Expressions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-remove_005ffrom_005fpath_002f1-1">remove_from_path/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rename_002f2-1">rename/2</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reset_005fop_005fcounters_002f0-1">reset_op_counters/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reset_005fstatic_005farray_002f1-1">reset_static_array/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-resize_005fstatic_005farray_002f3-1">resize_static_array/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-S">S</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_002f1-1">save/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_002f2-1">save/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scan_005finteger_002f3-1">scan_integer/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scan_005fnatural_002f3-1">scan_natural/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-search_005ffor_002f2-1">search_for/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-search_005ffor_002f2-4">search_for/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-search_005ffor_002f2-7">search_for/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-selectchk_002f3-1">selectchk/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-selectlist_002f3-1">selectlist/3</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setarg_002f3n-1">setarg/3n</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setenv_002f2-1">setenv/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setup_005fcall_005fcatcher_005fcleanup_002f4-1">setup_call_catcher_cleanup/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setup_005fcall_005fcleanup_002f3-1">setup_call_cleanup/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005fprolog_005fflag_002f2-1">set_prolog_flag/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005fvalue_002f2-1">set_value/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sh_002f0-1">sh/0</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-showprofres_002f0-1">showprofres/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-showprofres_002f1-1">showprofres/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-show_005fops_005fby_005fgroup_002f1-1">show_ops_by_group/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-show_005fop_005fcounters_002f1-1">show_op_counters/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-show_005ftable_002f1-1">show_table/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_002f0-1">source/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005fmode_002f2-1">source_mode/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005faccess_002f5-1">splay_access/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005fdelete_002f4-1">splay_delete/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005finit_002f3-1">splay_init/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005finsert_002f4-1">splay_insert/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005fjoin_002f3-1">splay_join/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005fsplit_002f5-1">splay_split/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-split_002f2-1">split/2</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-split_002f3-1">split/3</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-spy_005fwrite_002f2-1">spy_write/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-srandom_002f1-1">srandom/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-start_005flow_005flevel_005ftrace_002f0-1">start_low_level_trace/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Tracing">19 Tracing at Low Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-start_005flow_005flevel_005ftrace_002f0-4">start_low_level_trace/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Tracing">19 Tracing at Low Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-start_005fmatlab_002f1-1">start_matlab/1</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_002f3-1">static_array/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_002f3-4">static_array/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_005flocation_002f4-1">static_array_location/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_005fproperties_002f3-1">static_array_properties/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_005fto_005fterm_002f3-1">static_array_to_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fproperty_002f2-1">stream_property/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-style_005fcheck_002f1-1">style_check/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-style_005fcheck_002f1-3">style_check/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sub_005fatom_002f5-1">sub_atom/5</a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumargs_002f4-1">sumargs/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumlist_002f4-1">sumlist/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumnodes_002f4-1">sumnodes/4</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_002f1-1">system/1</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-T">T</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-table_002f1-1">table/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-table_005fstatistics_002f1-1">table_statistics/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tabling_005fmode_002f2-1">tabling_mode/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tabling_005fstatistics_002f0-1">tabling_statistics/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fattvars_002f2-1">term_attvars/2</a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fto_005fatom_002f2-4">term_to_atom/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-threads_002f0-1">threads/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fat_005fexit_002f1-1">thread_at_exit/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fcreate_002f1-1">thread_create/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fcreate_002f2-1">thread_create/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fcreate_002f3-1">thread_create/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fdetach_002f1-1">thread_detach/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fexit_002f1-1">thread_exit/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fget_005fmessage_002f1-1">thread_get_message/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fget_005fmessage_002f2-1">thread_get_message/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fjoin_002f2-1">thread_join/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005flocal_002f1-_0028directive_0029-1">thread_local/1 (directive)</a></td><td>&nbsp;</td><td valign="top"><a href="#Threads-and-Dynamic-Predicates">16.3.3 Threads and Dynamic Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fpeek_005fmessage_002f1-1">thread_peek_message/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fpeek_005fmessage_002f2-1">thread_peek_message/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fproperty_002f2-1">thread_property/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fself_002f1-1">thread_self/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsend_005fmessage_002f1-1">thread_send_message/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsend_005fmessage_002f2-1">thread_send_message/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsetconcurrency_002f2-1">thread_setconcurrency/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsignal_002f2-1">thread_signal/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Signalling-Threads">16.3.2 Signalling Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsleep_002f1-1">thread_sleep/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fstatistics_002f3-1">thread_statistics/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fyield_002f0-1">thread_yield/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-throw_002f1-1">throw/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-time_002f1-1">time/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-time_005ffile_002f2-1">time_file/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tmp_005ffile_002f2-1">tmp_file/2</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fcheck_005fentry_002f3-1">trie_check_entry/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fclose_002f1-1">trie_close/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fclose_005fall_002f0-1">trie_close_all/0</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fget_005fentry_002f2-1">trie_get_entry/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fload_002f2-1">trie_load/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fmax_005fstats_002f4-1">trie_max_stats/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fmode_002f1-1">trie_mode/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fopen_002f1-1">trie_open/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fprint_002f1-1">trie_print/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fput_005fentry_002f3-1">trie_put_entry/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fremove_005fentry_002f1-1">trie_remove_entry/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fremove_005fsubtree_002f1-1">trie_remove_subtree/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fsave_002f2-1">trie_save/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fstats_002f4-1">trie_stats/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fusage_002f4-1">trie_usage/4</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-U">U</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-ugraph_005fto_005fdgraph_002f2-1">ugraph_to_dgraph/2</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fadd_005fedges_002f3-1">undgraph_add_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fadd_005fvertices_002f3-1">undgraph_add_vertices/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fcomplement_002f2-1">undgraph_complement/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fdel_005fedges_002f3-1">undgraph_del_edges/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fedge_002f2-1">undgraph_edge/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fedges_002f2-1">undgraph_edges/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fneighbors_002f3-1">undgraph_neighbors/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fneighbours_002f3-1">undgraph_neighbours/3</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fnew_002f1-1">undgraph_new/1</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fvertices_002f2-1">undgraph_vertices/2</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unhide_002f1-1">unhide/1</a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unix_002f1-1">unix/1</a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unload_005fforeign_005flibrary_002f1-1">unload_foreign_library/1</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unload_005fforeign_005flibrary_002f2-1">unload_foreign_library/2</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-update_005farray_002f3-1">update_array/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fforeign_005flibrary_002f1-1">use_foreign_library/1</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fforeign_005flibrary_002f2-1">use_foreign_library/2</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-V">V</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-variables_005fwithin_005fterm_002f3-1">variables_within_term/3</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-variable_005fin_005fterm_002f2-1">variable_in_term/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-W">W</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005fmutex_002f2-1">with_mutex/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-working_005fdirectory_002f2-4">working_directory/2</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-writeln_002f1-1">writeln/1</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fdepth_002f2-1">write_depth/2</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fdepth_002f3-1">write_depth/3</a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-Y">Y</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-yap_005fflag_002f2-1">yap_flag/2</a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
</table>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_symbol-1"><b>-</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_symbol-2"><b>=</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_symbol-3"><b>\</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-K"><b>K</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-M"><b>M</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-W"><b>W</b></a>
&nbsp;
<a class="summary-letter" href="#YAP-predicates-not-available-in-SICStus-Prolog_sn_letter-Y"><b>Y</b></a>
&nbsp;
</td></tr></table>
<hr>
<a name="ISO-Prolog"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Not-in-SICStus-Prolog" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Compatibility-with-the-ISO-Prolog-standard"></a>
<h2 class="section">25.3 Compatibility with the ISO Prolog standard</h2>
<p>The Prolog standard was developed by ISO/IEC JTC1/SC22/WG17, the
international standardization working group for the programming language
Prolog. The book &quot;Prolog: The Standard&quot; by Deransart, Ed-Dbali and
Cervoni gives a complete description of this standard. Development in
YAP from YAP4.1.6 onwards have striven at making YAP
compatible with ISO Prolog. As such:
</p>
<ul>
<li> YAP now supports all of the built-ins required by the
ISO-standard, and,
</li><li> Error-handling is as required by the standard.
</li></ul>
<p>YAP by default is not fully ISO standard compliant. You can set the
<code>language</code> flag to <code>iso</code> to obtain very good
compatibility. Setting this flag changes the following:
</p>
<ul>
<li> By default, YAP uses &quot;immediate update semantics&quot; for its
database, and not &quot;logical update semantics&quot;, as per the standard,
(see section <a href="#SICStus-Prolog">Compatibility with the Quintus and SICStus Prolog systems</a>). This affects <code>assert/1</code>,
<code>retract/1</code>, and friends.
<p>Calling <code>set_prolog_flag(update_semantics,logical)</code> will switch
YAP to use logical update semantics.
</p>
</li><li> By default, YAP implements the <code>atom_chars/2</code>
(see section <a href="#Testing-Terms">Predicates on terms</a>), and <code>number_chars/2</code>, (see section <a href="#Testing-Terms">Predicates on terms</a>), built-ins as per the original Quintus Prolog definition, and
not as per the ISO definition.
<p>Calling <code>set_prolog_flag(to_chars_mode,iso)</code> will switch
YAP to use the ISO definition for
<code>atom_chars/2</code> and <code>number_chars/2</code>.
</p>
</li><li> By default, YAP fails on undefined predicates. To follow the ISO
Prolog standard use:
<div class="example">
<pre class="example">:- set_prolog_flag(unknown,error).
</pre></div>
</li><li> By default, YAP allows executable goals in directives. In ISO mode
most directives can only be called from top level (the exceptions are
<code>set_prolog_flag/2</code> and <code>op/3</code>).
</li><li> Error checking for meta-calls under ISO Prolog mode is stricter
than by default.
</li><li> The <code>strict_iso</code> flag automatically enables the ISO Prolog
standard. This feature should disable all features not present in the
standard.
</li></ul>
<p>The following incompatibilities between YAP and the ISO standard are
known to still exist:
</p>
<ul>
<li> Currently, YAP does not handle overflow errors in integer
operations, and handles floating-point errors only in some
architectures. Otherwise, YAP follows IEEE arithmetic.
</li></ul>
<p>Please inform the authors on other incompatibilities that may still
exist.
</p>
<hr>
<a name="Operators"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Compatibility" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#ISO-Prolog" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Predicate-Index" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Predicate-Index" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Summary-of-YAP-Predefined-Operators"></a>
<h1 class="appendix">Appendix A Summary of YAP Predefined Operators</h1>
<p> The Prolog syntax caters for operators of three main kinds:
</p>
<ul>
<li>
prefix;
</li><li>
infix;
</li><li>
postfix.
</li></ul>
<p> Each operator has precedence in the range 1 to 1200, and this
precedence is used to disambiguate expressions where the structure of the
term denoted is not made explicit using brackets. The operator of higher
precedence is the main functor.
</p>
<p> If there are two operators with the highest precedence, the ambiguity
is solved analyzing the types of the operators. The possible infix types are:
<var>xfx</var>, <var>xfy</var>, and <var>yfx</var>.
</p>
<p> With an operator of type <var>xfx</var> both sub-expressions must have lower
precedence than the operator itself, unless they are bracketed (which
assigns to them zero precedence). With an operator type <var>xfy</var> only the
left-hand sub-expression must have lower precedence. The opposite happens
for <var>yfx</var> type.
</p>
<p> A prefix operator can be of type <var>fx</var> or <var>fy</var>.
A postfix operator can be of type <var>xf</var> or <var>yf</var>.
The meaning of the notation is analogous to the above.
</p><div class="example">
<pre class="example">a + b * c
</pre></div>
<p>means
</p><div class="example">
<pre class="example">a + (b * c)
</pre></div>
<p>as + and * have the following types and precedences:
</p><div class="example">
<pre class="example">:-op(500,yfx,'+').
:-op(400,yfx,'*').
</pre></div>
<p>Now defining
</p><div class="example">
<pre class="example">:-op(700,xfy,'++').
:-op(700,xfx,'=:=').
a ++ b =:= c
</pre></div>
<p>means
</p><div class="example">
<pre class="example">a ++ (b =:= c)
</pre></div>
<p>The following is the list of the declarations of the predefined operators:
</p>
<div class="example">
<pre class="example">:-op(1200,fx,['?-', ':-']).
:-op(1200,xfx,[':-','--&gt;']).
:-op(1150,fx,[block,dynamic,mode,public,multifile,meta_predicate,
sequential,table,initialization]).
:-op(1100,xfy,[';','|']).
:-op(1050,xfy,-&gt;).
:-op(1000,xfy,',').
:-op(999,xfy,'.').
:-op(900,fy,['\+', not]).
:-op(900,fx,[nospy, spy]).
:-op(700,xfx,[@&gt;=,@=&lt;,@&lt;,@&gt;,&lt;,=,&gt;,=:=,=\=,\==,&gt;=,=&lt;,==,\=,=..,is]).
:-op(500,yfx,['\/','/\','+','-']).
:-op(500,fx,['+','-']).
:-op(400,yfx,['&lt;&lt;','&gt;&gt;','//','*','/']).
:-op(300,xfx,mod).
:-op(200,xfy,['^','**']).
:-op(50,xfx,same).
</pre></div>
<hr>
<a name="Predicate-Index"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Operators" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Operators" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Concept-Index" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="#Concept-Index" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Predicate-Index-1"></a>
<h1 class="unnumbered">Predicate Index</h1>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#Predicate-Index-1_fn_symbol-1"><b>!</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-2"><b>,</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-3"><b>-</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-4"><b>;</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-5"><b>&lt;</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-6"><b>=</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-7"><b>&gt;</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-8"><b>@</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-9"><b>[</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-10"><b>\</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-J"><b>J</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-K"><b>K</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-M"><b>M</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-Q"><b>Q</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-W"><b>W</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-Y"><b>Y</b></a>
&nbsp;
</td></tr></table>
<table class="index-fn" border="0">
<tr><td></td><th align="left">Index Entry</th><td>&nbsp;</td><th align="left"> Section</th></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_symbol-1">!</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0021_002f0"><code>!/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_symbol-2">,</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002c_002f2"><code>,/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_symbol-3">-</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002d_003e_002a_002f2"><code>-&gt;*/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_002d_003e_002f2"><code>-&gt;/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_symbol-4">;</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003b_002f2"><code>;/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_symbol-5">&lt;</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003c_002f2"><code>&lt;/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_symbol-6">=</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_002e_002e_002f2"><code>=../2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_002f2"><code>=/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_002f2-3"><code>=/=2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_003a_003d_002f2"><code>=:=/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_003c_002f2"><code>=&lt;/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_003d_002f2"><code>==/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_0040_003d_002f2"><code>=@=/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003d_005c_003d_002f2"><code>=\=/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_symbol-7">&gt;</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003e_002f2"><code>&gt;/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_003e_003d_002f2"><code>&gt;=/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_symbol-8">@</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003c_002f2"><code>@&lt;/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003d_003c_002f2"><code>@=&lt;/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003e_002f2"><code>@&gt;/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_0040_003e_003d_002f2"><code>@&gt;=/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_symbol-9">[</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005b_002d_005d_002f1"><code>[-]/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005b_005d_002f1"><code>[]/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_symbol-10">\</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005c_002b_002f1"><code>\+/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005c_003d_002f2"><code>\=/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-_005c_003d_003d_002f2"><code>\==/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-A">A</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_002f1"><code>abolish/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_002f2"><code>abolish/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_005fall_005ftables_002f0"><code>abolish_all_tables/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-abolish_005ftable_002f1"><code>abolish_table/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-abort_002f0"><code>abort/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-absolute_005ffile_005fname_002f2"><code>absolute_file_name/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-absolute_005ffile_005fname_002f3"><code>absolute_file_name/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fedges_002f3"><code>add_edges/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fto_005farray_005felement_002f4"><code>add_to_array_element/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fto_005fheap_002f4"><code>add_to_heap/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fto_005fpath_002f1"><code>add_to_path/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fto_005fpath_002f2"><code>add_to_path/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-add_005fvertices_002f3"><code>add_vertices/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-agc_005fmargin-_0028yap_005fflag_002f2-option_0029"><code>agc_margin (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_002f3"><code>aggregate/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_002f4"><code>aggregate/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_005fall_002f3"><code>aggregate_all/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate_005fall_002f4"><code>aggregate_all/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-alarm_002f3"><code>alarm/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-all_002f3"><code>all/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-always_005fprompt_005fuser_002f0"><code>always_prompt_user/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-append_002f2"><code>append/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-append_002f3"><code>append/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-append_002f3-3"><code>append/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-arg_002f3"><code>arg/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-argv-_0028yap_005fflag_002f2-option_0029"><code>argv (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-array_002f2"><code>array/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-array_005felement_002f3"><code>array_element/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assert_002f1"><code>assert/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assert_002f2"><code>assert/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-asserta_002f1"><code>asserta/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-asserta_002f2"><code>asserta/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-asserta_005fstatic_002f1"><code>asserta_static/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assertz_002f1"><code>assertz/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assertz_002f2"><code>assertz/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assertz_005fstatic_002f1"><code>assertz_static/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assert_005fstatic_002f1"><code>assert_static/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-assoc_005fto_005flist_002f2"><code>assoc_to_list/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_002f1"><code>atom/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_002f1"><code>atomic/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_005fconcat_002f2"><code>atomic_concat/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_005flist_005fconcat_002f2"><code>atomic_list_concat/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atomic_005flist_005fconcat_002f3"><code>atomic_list_concat/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atoms-_0028statistics_002f2-option_0029"><code>atoms (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fchars_002f2"><code>atom_chars/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fcodes_002f2"><code>atom_codes/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fconcat_002f2"><code>atom_concat/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fconcat_002f3"><code>atom_concat/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005flength_002f2"><code>atom_length/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fnumber_002f2"><code>atom_number/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fto_005fchars_002f2"><code>atom_to_chars/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fto_005fchars_002f3"><code>atom_to_chars/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom_005fto_005fterm_002f3"><code>atom_to_term/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attribute_002f1-_0028declaration_0029"><code>attribute/1 (declaration)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Attribute-Declarations">11.2.1 Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attribute_005fgoal_002f2"><code>attribute_goal/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Displaying-Attributes">11.2.4 Displaying Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attribute_005fgoals_002f2"><code>attribute_goals/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attr_005fportray_005fhook_002f2"><code>attr_portray_hook/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attr_005funify_005fhook_002f2"><code>attr_unify_hook/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attvar_002f1"><code>attvar/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attvar_002f1-3"><code>attvar/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Attributed-Unification">11.2.3 Attributed Unification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-at_005fend_005fof_005fstream_002f0"><code>at_end_of_stream/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-at_005fend_005fof_005fstream_002f1"><code>at_end_of_stream/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-avl_005finsert_002f4"><code>avl_insert/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-avl_005flookup_002f3"><code>avl_lookup/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-avl_005fnew_002f1"><code>avl_new/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-B">B</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-bagof_002f3"><code>bagof/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fdelete_002f2"><code>bb_delete/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fget_002f2"><code>bb_get/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fput_002f2"><code>bb_put/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bb_005fupdate_002f3"><code>bb_update/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#BlackBoard">6.12 The Blackboard</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-between_002f3"><code>between/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-between_002f3-3"><code>between/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-bounded-_0028yap_005fflag_002f2-option_0029"><code>bounded (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-break_002f0"><code>break/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fgetval_002f2"><code>b_getval/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fgetval_002f2-3"><code>b_getval/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fsetval_002f2"><code>b_setval/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-b_005fsetval_002f2-3"><code>b_setval/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-C">C</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-C_002f3"><code>C/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_002f1"><code>call/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_002fn"><code>call/n</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-callable_002f1"><code>callable/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcleanup_002f1"><code>call_cleanup/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcleanup_002f2"><code>call_cleanup/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcounting-_0028yap_005fflag_002f2-option_0029"><code>call_counting (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcount_005fdata_002f0"><code>call_count_data/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcount_005fdata_002f3"><code>call_count_data/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fcount_005fdata_002f3-3"><code>call_count_data/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fresidue_002f2"><code>call_residue/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fresidue_005fvars_002f2"><code>call_residue_vars/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fshared_005fobject_005ffunction_002f2"><code>call_shared_object_function/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-call_005fwith_005fargs_002fn"><code>call_with_args/n</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-catch_002f3"><code>catch/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cd_002f1"><code>cd/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-character_005fcount_002f2"><code>character_count/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-character_005fescapes-_0028yap_005fflag_002f2-option_0029"><code>character_escapes (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-char_005fcode_002f2"><code>char_code/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-char_005fconversion-_0028yap_005fflag_002f2-option_0029"><code>char_conversion (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-char_005fconversion_002f2"><code>char_conversion/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-char_005ftype_002f2"><code>char_type/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-chdir_002f1"><code>chdir/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-checklist_002f2"><code>checklist/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-checknodes_002f3"><code>checknodes/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-clause_002f2"><code>clause/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-clause_002f3"><code>clause/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cleanup_005fall_002f0"><code>cleanup_all/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_002f1"><code>close/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_002f2"><code>close/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_005fmatlab_002f0"><code>close_matlab/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_005fshared_005fobject_002f1"><code>close_shared_object/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-close_005fstatic_005farray_002f1"><code>close_static_array/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-code_005ftype_002f2"><code>code_type/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Characters">6.6 Predicates on Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compare_002f3"><code>compare/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compile_002f1"><code>compile/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compile_005fexpressions_002f0"><code>compile_expressions/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-complement_002f2"><code>complement/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compose_002f3"><code>compose/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-compound_002f1"><code>compound/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-concat_005fatom_002f2"><code>concat_atom/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-concat_005fatom_002f3"><code>concat_atom/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-consult_002f1"><code>consult/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-convlist_002f3"><code>convlist/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fline_002f2"><code>copy_line/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fline_002f2-3"><code>copy_line/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fterm_002f2"><code>copy_term/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fterm_002f3"><code>copy_term/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-copy_005fterm_005fnat_002f2"><code>copy_term_nat/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cputime-_0028statistics_002f2-option_0029"><code>cputime (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-create_005fmutable_002f2"><code>create_mutable/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-create_005fprolog_005fflag_002f2"><code>create_prolog_flag/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fatom_002f1"><code>current_atom/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fchar_005fconversion_002f2"><code>current_char_conversion/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fforeign_005flibrary_002f2"><code>current_foreign_library/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005finput_002f1"><code>current_input/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fkey_002f2"><code>current_key/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fline_005fnumber_002f1"><code>current_line_number/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fline_005fnumber_002f2"><code>current_line_number/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fmodule_002f1"><code>current_module/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Preds">6.21 Predicate Information</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fmodule_002f2"><code>current_module/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Preds">6.21 Predicate Information</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fmutex_002f3"><code>current_mutex/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fop_002f3"><code>current_op/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005foutput_002f1"><code>current_output/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fpredicate_002f1"><code>current_predicate/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fpredicate_002f2"><code>current_predicate/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fprolog_005fflag_002f2"><code>current_prolog_flag/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fstream_002f3"><code>current_stream/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-current_005fthread_002f2"><code>current_thread/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cyclic_005fterm_002f1"><code>cyclic_term/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-cyclic_005fterm_002f1-3"><code>cyclic_term/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-D">D</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-datime_002f1"><code>datime/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fassert_002f1"><code>db_assert/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fassert_002f2"><code>db_assert/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fclose_002f1"><code>db_close/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdatalog_005fdescribe_002f1"><code>db_datalog_describe/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdatalog_005fdescribe_002f2"><code>db_datalog_describe/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdescribe_002f1"><code>db_describe/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fdescribe_002f2"><code>db_describe/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Describing-a-Relation">15.11 Describing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fget_005fattributes_005ftypes_002f2"><code>db_get_attributes_types/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Types-of-Attributes">15.9 Types of Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fget_005fattributes_005ftypes_002f3"><code>db_get_attributes_types/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Types-of-Attributes">15.9 Types of Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fimport_002f2"><code>db_import/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-a-Relation">15.5 Accessing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fimport_002f3"><code>db_import/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-a-Relation">15.5 Accessing a Relation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005finsert_002f2"><code>db_insert/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005finsert_002f3"><code>db_insert/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Insertion-of-Rows">15.8 Insertion of Rows</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmodule_002f1"><code>db_module/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmy_005fresult_005fset_002f1"><code>db_my_result_set/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmy_005fsql_005fmode_002f1"><code>db_my_sql_mode/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fmy_005fsql_005fmode_002f2"><code>db_my_sql_mode/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Other-MYDDAS-Properties">15.14 Other MYDDAS Properties</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fnumber_005fof_005ffields_002f2"><code>db_number_of_fields/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Number-of-Fields">15.10 Number of Fields</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fnumber_005fof_005ffields_002f3"><code>db_number_of_fields/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Number-of-Fields">15.10 Number of Fields</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fopen_002f4"><code>db_open/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fopen_002f5"><code>db_open/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Connecting-to-and-disconnecting-from-a-Database-Server">15.4 Connecting to and disconnecting from a Database Server</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005freference_002f1C"><code>db_reference/1C</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fshow_005ftables_002f1"><code>db_show_tables/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Enumerating-Relations">15.12 Enumeration Relations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fshow_005ftables_002f2"><code>db_show_tables/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Enumerating-Relations">15.12 Enumeration Relations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fsql_002f2"><code>db_sql/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-Tables-in-Data-Sources-Using-SQL">15.7 Accessing Tables in Data Sources Using SQL</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fsql_002f3"><code>db_sql/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Accessing-Tables-in-Data-Sources-Using-SQL">15.7 Accessing Tables in Data Sources Using SQL</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005ftop_005flevel_002f4"><code>db_top_level/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#The-MYDDAS-MySQL-Top-Level">15.13 The MYDDAS MySQL Top Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005ftop_005flevel_002f5"><code>db_top_level/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#The-MYDDAS-MySQL-Top-Level">15.13 The MYDDAS MySQL Top Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fview_002f2"><code>db_view/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#View-Level-Interface">15.6 View Level Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-db_005fview_002f3"><code>db_view/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#View-Level-Interface">15.6 View Level Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-debug-_0028yap_005fflag_002f2-option_0029"><code>debug (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-debug_002f0"><code>debug/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-debugger_005fprint_005foptions-_0028yap_005fflag_002f2-option_0029"><code>debugger_print_options (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-debugging_002f0"><code>debugging/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-delete_002f3"><code>delete/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-delete_005ffile_002f1"><code>delete_file/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-delete_005ffile_002f2"><code>delete_file/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fassoc_002f4"><code>del_assoc/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fattr_002f2"><code>del_attr/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fattrs_002f1"><code>del_attrs/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fedges_002f3"><code>del_edges/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fmax_005fassoc_002f4"><code>del_max_assoc/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fmin_005fassoc_002f4"><code>del_min_assoc/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-del_005fvertices_002f3"><code>del_vertices/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fedge_002f4"><code>dgraph_add_edge/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fedges_002f3"><code>dgraph_add_edges/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fvertex_002f3"><code>dgraph_add_vertex/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fadd_005fvertices_002f3"><code>dgraph_add_vertices/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fcomplement_002f2"><code>dgraph_complement/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fcompose_002f3"><code>dgraph_compose/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fedge_002f4"><code>dgraph_del_edge/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fedges_002f3"><code>dgraph_del_edges/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fvertex_002f3"><code>dgraph_del_vertex/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fdel_005fvertices_002f3"><code>dgraph_del_vertices/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fedge_002f2"><code>dgraph_edge/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fedges_002f2"><code>dgraph_edges/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fisomorphic_002f4"><code>dgraph_isomorphic/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fmax_005fpath_002f5"><code>dgraph_max_path/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fmin_005fpath_002f5"><code>dgraph_min_path/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fmin_005fpaths_002f3"><code>dgraph_min_paths/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fneighbors_002f3"><code>dgraph_neighbors/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fneighbours_002f3"><code>dgraph_neighbours/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fnew_002f1"><code>dgraph_new/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fpath_002f3"><code>dgraph_path/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fpath_002f3-3"><code>dgraph_path/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fsymmetric_005fclosure_002f2"><code>dgraph_symmetric_closure/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftop_005fsort_002f2"><code>dgraph_top_sort/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftop_005fsort_002f3"><code>dgraph_top_sort/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fto_005fugraph_002f2"><code>dgraph_to_ugraph/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fto_005fundgraph_002f2"><code>dgraph_to_undgraph/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftransitive_005fclosure_002f2"><code>dgraph_transitive_closure/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005ftranspose_002f2"><code>dgraph_transpose/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dgraph_005fvertices_002f2"><code>dgraph_vertices/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dialect-_0028yap_005fflag_002f2-option_0029"><code>dialect (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dif_002f2"><code>dif/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-directory-_0028prolog_005fload_005fcontext_002f2-option_0029"><code>directory (prolog_load_context/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-directory_005ffiles_002f2"><code>directory_files/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-discontiguous_002f1-_0028directive_0029"><code>discontiguous/1 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-discontiguous_005fwarnings-_0028yap_005fflag_002f2-option_0029"><code>discontiguous_warnings (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-discontiguous_005fwarnings-_0028yap_005fflag_002f2-option_0029-1"><code>discontiguous_warnings (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-display_002f1"><code>display/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-display_002f1-3"><code>display/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-display_002f2"><code>display/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dollar_005fas_005flower_005fcase-_0028yap_005fflag_002f2-option_0029"><code>dollar_as_lower_case (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-double_005fquotes-_0028yap_005fflag_002f2-option_0029"><code>double_quotes (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-do_005fnot_005fcompile_005fexpressions_002f0"><code>do_not_compile_expressions/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-duplicate_005fterm_002f2"><code>duplicate_term/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dynamic_002f1"><code>dynamic/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Database">6.10 Using the Clausal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dynamic_005fcode-_0028statistics_002f2-option_0029"><code>dynamic_code (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-dynamic_005fpredicate_002f2"><code>dynamic_predicate/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Database">6.10 Using the Clausal Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-E">E</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-edges_002f2"><code>edges/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-elif_002f1-directive"><code>elif/1 directive</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-else_002f0-directive"><code>else/0 directive</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-empty_005fassoc_002f1"><code>empty_assoc/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-empty_005fheap_002f1"><code>empty_heap/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-empty_005fqueue_002f1"><code>empty_queue/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-endif_002f0-directive"><code>endif/0 directive</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ensure_005floaded_002f1"><code>ensure_loaded/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environ_002f2"><code>environ/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environ_002f2-3"><code>environ/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-erase_002f1"><code>erase/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-eraseall_002f1"><code>eraseall/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-erased_002f1"><code>erased/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exception_002f3"><code>exception/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exclude_002f3"><code>exclude/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exec_002f3"><code>exec/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-executable_0028yap_005fflag_002f2-option_0029"><code>executable(yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-exists_002f1"><code>exists/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expand_005fexprs_002f2"><code>expand_exprs/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-expand_005fterm_002f2"><code>expand_term/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-F">F</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-fail_002f0"><code>fail/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-false_002f0"><code>false/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fast-_0028yap_005fflag_002f2-option_0029"><code>fast (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fields_002f2"><code>fields/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fields_002f3"><code>fields/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file-_0028prolog_005fload_005fcontext_002f2-option_0029"><code>file (prolog_load_context/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file-_0028prolog_005fload_005fcontext_002f2-option_0029-1"><code>file (prolog_load_context/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file-_0028prolog_005fload_005fcontext_002f2-option_0029-2"><code>file (prolog_load_context/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file-_0028prolog_005fload_005fcontext_002f2-option_0029-3"><code>file (prolog_load_context/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fileerrors-_0028yap_005fflag_002f2-option_0029"><code>fileerrors (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fileerrors_002f0"><code>fileerrors/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fbase_005fname_002f2"><code>file_base_name/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fexists_002f1"><code>file_exists/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fexists_002f2"><code>file_exists/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005ffilter_002f3"><code>file_filter/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005ffilter_005fwith_005finit_002f5"><code>file_filter_with_init/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fname_005fextension_002f3"><code>file_name_extension/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fproperty_002f2"><code>file_property/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-file_005fsearch_005fpath_002f2"><code>file_search_path/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-filter_002f3"><code>filter/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-findall_002f3"><code>findall/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-findall_002f4"><code>findall/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-flatten_002f2"><code>flatten/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-float_002f1"><code>float/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-float_005fformat-_0028yap_005fflag_002f2-option_0029"><code>float_format (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-flush_005foutput_002f0"><code>flush_output/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-flush_005foutput_002f1"><code>flush_output/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-forall_002f2"><code>forall/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-forall_002f2-3"><code>forall/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Forall">8.2 Forall</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-foreach_002f2"><code>foreach/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_002f1"><code>format/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_002f2"><code>format/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_002f3"><code>format/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_005fto_005fchars_002f3"><code>format_to_chars/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-format_005fto_005fchars_002f4"><code>format_to_chars/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-fragile"><code>fragile</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-freeze_002f2"><code>freeze/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-free_005fvariables_002f4"><code>free_variables/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-frozen_002f2"><code>frozen/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-functor_002f3"><code>functor/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-G">G</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-garbage_005fcollect_002f0"><code>garbage_collect/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-garbage_005fcollection-_0028statistics_002f2-option_0029"><code>garbage_collection (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-garbage_005fcollect_005fatoms_002f0"><code>garbage_collect_atoms/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-gc-_0028yap_005fflag_002f2-option_0029"><code>gc (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-gc_002f0"><code>gc/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-gc_005fmargin-_0028yap_005fflag_002f2-option_0029"><code>gc_margin (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-gc_005ftrace-_0028yap_005fflag_002f2-option_0029"><code>gc_trace (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-generate_005fdebugging_005finfo-_0028yap_005fflag_002f2-option_0029"><code>generate_debugging_info (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-gen_005fassoc_002f3"><code>gen_assoc/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_002f1"><code>get/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_002f2"><code>get/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get0_002f1"><code>get0/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get0_002f2"><code>get0/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-getcwd_002f1"><code>getcwd/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-getrand_002f1"><code>getrand/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fassoc_002f3"><code>get_assoc/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fassoc_002f5"><code>get_assoc/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fattr_002f3"><code>get_attr/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fattrs_002f2"><code>get_attrs/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fatts_002f2"><code>get_atts/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Attribute-Manipulation">11.2.2 Attribute Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fbyte_002f1"><code>get_byte/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fbyte_002f2"><code>get_byte/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fchar_002f1"><code>get_char/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fchar_002f2"><code>get_char/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fcode_002f1"><code>get_code/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fcode_002f2"><code>get_code/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005ffrom_005fheap_002f4"><code>get_from_heap/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005flabel_002f3"><code>get_label/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fmutable_002f2"><code>get_mutable/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fmutable_002f2-3"><code>get_mutable/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fnext_005fassoc_002f4"><code>get_next_assoc/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fprev_005fassoc_002f4"><code>get_prev_assoc/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-get_005fvalue_002f2"><code>get_value/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-global_005fstack-_0028statistics_002f2-option_0029"><code>global_stack (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-glue_002f3"><code>glue/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-goal_005fexpansion_002f3"><code>goal_expansion/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ground_002f1"><code>ground/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-grow_005fstack_002f1"><code>grow_stack/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-H">H</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-halt_002f0"><code>halt/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-halt_002f1"><code>halt/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-head_005fqueue_002f2"><code>head_queue/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-heap-_0028statistics_002f2-option_0029"><code>heap (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-heap_005fsize_002f2"><code>heap_size/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-heap_005fto_005flist_002f2"><code>heap_to_list/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-hide_002f1"><code>hide/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-hide_005fpredicate_002f1"><code>hide_predicate/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-host_005fid_002f1"><code>host_id/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-host_005fname_002f1"><code>host_name/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-host_005ftype-_0028yap_005fflag_002f2-option_0029"><code>host_type (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-I">I</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-if_002f1-directive"><code>if/1 directive</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Conditional-Compilation">4.3 Conditional Compilation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-if_002f3"><code>if/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ignore_002f1"><code>ignore/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-include_002f1-_0028directive_0029"><code>include/1 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-include_002f3"><code>include/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-incore_002f1"><code>incore/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-index-_0028yap_005fflag_002f2-option_0029"><code>index (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-informational_005fmessages-_0028yap_005fflag_002f2-option_0029"><code>informational_messages (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-initialization_002f0"><code>initialization/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-initialization_002f1-_0028directive_0029"><code>initialization/1 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-initialization_002f2-_0028directive_0029"><code>initialization/2 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-instance_002f2"><code>instance/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-integer_002f1"><code>integer/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-integer_005frounding_005ffunction-_0028yap_005fflag_002f2-option_0029"><code>integer_rounding_function (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-intersection_002f3"><code>intersection/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_002f2"><code>is/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005fassoc_002f1"><code>is_assoc/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005flist_002f1"><code>is_list/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005fmutable_002f1"><code>is_mutable/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005frbtree_002f1"><code>is_rbtree/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005fstream_002f1"><code>is_stream/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-is_005ftabled_002f1"><code>is_tabled/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-J">J</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-join_005fqueue_002f3"><code>join_queue/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-jump_005fqueue_002f3"><code>jump_queue/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-K">K</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-keysort_002f2"><code>keysort/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-key_005fstatistics_002f3"><code>key_statistics/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-key_005fstatistics_002f4"><code>key_statistics/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-kill_002f2"><code>kill/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-L">L</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-language-_0028yap_005fflag_002f2-option_0029"><code>language (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-last_002f2"><code>last/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-leash_002f1"><code>leash/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-length_002f2"><code>length/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-length_005fqueue_002f2"><code>length_queue/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-library_005fdirectory_002f1"><code>library_directory/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-library_005fdirectory_002f1-3"><code>library_directory/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-line_005fcount_002f2"><code>line_count/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-line_005fposition_002f2"><code>line_position/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-listing_002f0"><code>listing/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-listing_002f1"><code>listing/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fconcat_002f2"><code>list_concat/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fjoin_005fqueue_002f3"><code>list_join_queue/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fjump_005fqueue_002f3"><code>list_jump_queue/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005fassoc_002f2"><code>list_to_assoc/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005fheap_002f2"><code>list_to_heap/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005ford_005fset_002f2"><code>list_to_ord_set/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005fqueue_002f2"><code>list_to_queue/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005frbtree_002f2"><code>list_to_rbtree/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005frbtree_002f2-3"><code>list_to_rbtree/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list_005fto_005ftree_002f2"><code>list_to_tree/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-load_005ffiles_002f2"><code>load_files/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-load_005fforeign_005flibrary_002f1"><code>load_foreign_library/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-load_005fforeign_005flibrary_002f2"><code>load_foreign_library/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-local_005fstack-_0028statistics_002f2-option_0029"><code>local_stack (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-M">M</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-make_002f0"><code>make/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-make_005fdirectory_002f2"><code>make_directory/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-make_005fqueue_002f1"><code>make_queue/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mapargs_002f3"><code>mapargs/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f2"><code>maplist/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f3"><code>maplist/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f3-3"><code>maplist/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f3-6"><code>maplist/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f4"><code>maplist/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f4-3"><code>maplist/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Invoking-Predicates-on-all-Members-of-a-List">8.1 Invoking Predicates on all Members of a List</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-maplist_002f5"><code>maplist/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mapnodes_002f3"><code>mapnodes/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-map_005fassoc_002f2"><code>map_assoc/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-map_005fassoc_002f3"><code>map_assoc/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-map_005ftree_002f3"><code>map_tree/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fcells_002f2"><code>matlab_cells/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fcells_002f3"><code>matlab_cells/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005feval_005fstring_002f1"><code>matlab_eval_string/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005feval_005fstring_002f2"><code>matlab_eval_string/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fget_005fvariable_002f2"><code>matlab_get_variable/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005finitialized_005fcells_002f4"><code>matlab_initialized_cells/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f3"><code>matlab_item/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f3-3"><code>matlab_item/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f4"><code>matlab_item/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fitem_002f4-3"><code>matlab_item/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fmatrix_002f4"><code>matlab_matrix/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fon_002f0"><code>matlab_on/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fsequence_002f3"><code>matlab_sequence/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fset_002f4"><code>matlab_set/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fvector_002f4"><code>matlab_vector/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f2"><code>matlab_zeros/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f3"><code>matlab_zeros/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f4"><code>matlab_zeros/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matlab_005fzeros_002f4-3"><code>matlab_zeros/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fadd_002f3"><code>matrix_add/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fagg_005fcols_002f2"><code>matrix_agg_cols/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fagg_005flines_002f2"><code>matrix_agg_lines/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005farg_005fto_005foffset_002f3"><code>matrix_arg_to_offset/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fdec_002f2"><code>matrix_dec/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fdec_002f3"><code>matrix_dec/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fdims_002f2"><code>matrix_dims/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fexpand_002f3"><code>matrix_expand/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fget_002f3"><code>matrix_get/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005finc_002f2"><code>matrix_inc/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005finc_002f3"><code>matrix_inc/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fmax_002f2"><code>matrix_max/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fmaxarg_002f2"><code>matrix_maxarg/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fmin_002f2"><code>matrix_min/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fminarg_002f2"><code>matrix_minarg/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fndims_002f2"><code>matrix_ndims/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fnew_002f3"><code>matrix_new/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fnew_002f4"><code>matrix_new/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fnew_005fset_002f4"><code>matrix_new_set/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005foffset_005fto_005farg_002f3"><code>matrix_offset_to_arg/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_002f4"><code>matrix_op/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_002f4-3"><code>matrix_op/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_005fto_005fcols_002f4"><code>matrix_op_to_cols/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fop_005fto_005flines_002f4"><code>matrix_op_to_lines/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005freorder_002f3"><code>matrix_reorder/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005frow_002f3"><code>matrix_row/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fselect_002f4"><code>matrix_select/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fset_002f3"><code>matrix_set/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fset_005fall_002f2"><code>matrix_set_all/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fshuffle_002f3"><code>matrix_shuffle/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fsize_002f2"><code>matrix_size/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fsum_002f2"><code>matrix_sum/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005fto_005flist_002f2"><code>matrix_to_list/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-matrix_005ftype_002f2"><code>matrix_type/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005farity-_0028yap_005fflag_002f2-option_0029"><code>max_arity (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005fassoc_002f3"><code>max_assoc/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005finteger-_0028yap_005fflag_002f2-option_0029"><code>max_integer (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005flist_002f2"><code>max_list/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005ftagged_005finteger-_0028yap_005fflag_002f2-option_0029"><code>max_tagged_integer (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005ftagged_005finteger-_0028yap_005fflag_002f2-option_0029-1"><code>max_tagged_integer (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005fthreads-_0028yap_005fflag_002f2-option_0029"><code>max_threads (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-max_005fworkers-_0028yap_005fflag_002f2-option_0029"><code>max_workers (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-member_002f2"><code>member/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-memberchk_002f2"><code>memberchk/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-merge_002f3"><code>merge/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fhook_002f3"><code>message_hook/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fqueue_005fcreate_002f1"><code>message_queue_create/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fqueue_005fdestroy_002f1"><code>message_queue_destroy/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-message_005fto_005fstring_002f2"><code>message_to_string/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-meta_005fpredicate_002f1-_0028directive_0029"><code>meta_predicate/1 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Meta_002dPredicates-in-Modules">5.4 Meta-Predicates in Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005fassoc_002f3"><code>min_assoc/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005finteger-_0028yap_005fflag_002f2-option_0029"><code>min_integer (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005flist_002f2"><code>min_list/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005fof_005fheap_002f3"><code>min_of_heap/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-min_005fof_005fheap_002f5"><code>min_of_heap/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mktemp_002f2"><code>mktemp/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mktime_002f2"><code>mktime/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module-_0028prolog_005fload_005fcontext_002f2-option_0029"><code>module (prolog_load_context/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_002f1"><code>module/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_002f2-_0028directive_0029"><code>module/2 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_002f3-_0028directive_0029"><code>module/3 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Defining-Modules">5.2 Defining a New Module</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-module_005ftransparent_002f1-_0028directive_0029"><code>module_transparent/1 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Meta_002dPredicates-in-Modules">5.4 Meta-Predicates in Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbarrier_002f0"><code>mpi_barrier/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbcast_002f2"><code>mpi_bcast/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbcast_002f3"><code>mpi_bcast/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fbcast_002f3-3"><code>mpi_bcast/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fcomm_005frank_002f1"><code>mpi_comm_rank/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fcomm_005fsize_002f1"><code>mpi_comm_size/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005ffinalize_002f0"><code>mpi_finalize/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fgc_002f0"><code>mpi_gc/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005finit_002f0"><code>mpi_init/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005firecv_002f3"><code>mpi_irecv/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fisend_002f4"><code>mpi_isend/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005frecv_002f3"><code>mpi_recv/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fsend_002f3"><code>mpi_send/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005ftest_002f2"><code>mpi_test/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005ftest_005frecv_002f3"><code>mpi_test_recv/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fversion_002f2"><code>mpi_version/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fwait_002f2"><code>mpi_wait/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mpi_005fwait_005frecv_002f3"><code>mpi_wait_recv/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-multifile_002f1-_0028directive_0029"><code>multifile/1 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005fcreate_002f1"><code>mutex_create/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005fdestroy_002f1"><code>mutex_destroy/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005flock_002f1"><code>mutex_lock/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005fstatistics_002f0"><code>mutex_statistics/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005ftrylock_002f1"><code>mutex_trylock/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005funlock_002f1"><code>mutex_unlock/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutex_005funlock_005fall_002f0"><code>mutex_unlock_all/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-N">N</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-name_002f2"><code>name/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_002f1"><code>nb_beam/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fadd_002f3"><code>nb_beam_add/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fclose_002f1"><code>nb_beam_close/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fdel_002f3"><code>nb_beam_del/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fempty_002f1"><code>nb_beam_empty/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fpeek_002f3"><code>nb_beam_peek/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fbeam_005fsize_002f2"><code>nb_beam_size/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fcurrent_002f2"><code>nb_current/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fcurrent_002f2-3"><code>nb_current/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fdelete_002f1"><code>nb_delete/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fdelete_002f2"><code>nb_delete/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fgetval_002f2"><code>nb_getval/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fgetval_002f2-3"><code>nb_getval/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_002f1"><code>nb_heap/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fadd_002f3"><code>nb_heap_add/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fclose_002f1"><code>nb_heap_close/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fdel_002f3"><code>nb_heap_del/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fempty_002f1"><code>nb_heap_empty/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fpeek_002f3"><code>nb_heap_peek/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fheap_005fsize_002f2"><code>nb_heap_size/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005flinkarg_002f3"><code>nb_linkarg/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005flinkval_002f2"><code>nb_linkval/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_002f1"><code>nb_queue/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fclose_002f3"><code>nb_queue_close/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fdequeue_002f2"><code>nb_queue_dequeue/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fempty_002f1"><code>nb_queue_empty/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fenqueue_002f2"><code>nb_queue_enqueue/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fpeek_002f2"><code>nb_queue_peek/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fqueue_005fsize_002f2"><code>nb_queue_size/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Non_002dBacktrackable-Data-Structures">7.11 Non-Backtrackable Data Structures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fsetarg_002f3"><code>nb_setarg/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fsetval_002f2"><code>nb_setval/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fsetval_002f2-3"><code>nb_setval/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog-Global-Variables">9 SWI Global variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fset_005fshared_005farg_002f3"><code>nb_set_shared_arg/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nb_005fset_005fshared_005fval_002f2"><code>nb_set_shared_val/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-neighbors_002f3"><code>neighbors/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-neighbours_002f3"><code>neighbours/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-new_005fvariables_005fin_005fterm_002f3"><code>new_variables_in_term/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nl_002f0"><code>nl/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nl_002f1"><code>nl/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nodebug_002f0"><code>nodebug/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nofileerrors_002f0"><code>nofileerrors/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nogc_002f0"><code>nogc/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nonvar_002f1"><code>nonvar/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nospy_002f1"><code>nospy/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nospyall_002f0"><code>nospyall/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-not_002f1"><code>not/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-notrace_002f0"><code>notrace/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-no_005fsource_002f0"><code>no_source/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-no_005fstyle_005fcheck_002f1"><code>no_style_check/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_002f3"><code>nth/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_002f4"><code>nth/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth0_002f3"><code>nth0/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth0_002f4"><code>nth0/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth1_002f3"><code>nth1/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth1_002f3-3"><code>nth1/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth1_002f4"><code>nth1/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_005fclause_002f3"><code>nth_clause/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_005finstance_002f3"><code>nth_instance/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-nth_005finstance_002f4"><code>nth_instance/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_002f1"><code>number/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-numbervars_002f3"><code>numbervars/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fatom_002f2"><code>number_atom/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fchars_002f2"><code>number_chars/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fcodes_002f2"><code>number_codes/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fto_005fchars_002f2"><code>number_to_chars/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-number_005fto_005fchars_002f3"><code>number_to_chars/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-numlist_002f3"><code>numlist/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-n_005fof_005finteger_005fkeys_005fin_005fbb-_0028yap_005fflag_002f2-option_0029"><code>n_of_integer_keys_in_bb (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-n_005fof_005finteger_005fkeys_005fin_005fdb-_0028yap_005fflag_002f2-option_0029"><code>n_of_integer_keys_in_db (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-O">O</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-once_002f1"><code>once/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-on_005fcleanup_002f1"><code>on_cleanup/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-on_005fsignal_002f3"><code>on_signal/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-op_002f3"><code>op/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_002f3"><code>open/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_002f4"><code>open/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fchars_005fstream_002f2"><code>open_chars_stream/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fexpands_005ffilename-_0028yap_005fflag_002f2-option_0029"><code>open_expands_filename (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fshared_005fobject-_0028yap_005fflag_002f2-option_0029"><code>open_shared_object (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fshared_005fobject_002f2"><code>open_shared_object/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-open_005fshared_005fobject_002f3"><code>open_shared_object/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Loading-Objects">23.11 Loading Object Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ordsubset_002f2"><code>ordsubset/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fadd_005felement_002f3"><code>ord_add_element/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fdel_005felement_002f3"><code>ord_del_element/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fdisjoint_002f2"><code>ord_disjoint/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005finsert_002f3"><code>ord_insert/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fintersect_002f2"><code>ord_intersect/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fintersect_002f3"><code>ord_intersect/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fintersect_002f4"><code>ord_intersect/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005flist_005fto_005fassoc_002f2"><code>ord_list_to_assoc/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fmember_002f2"><code>ord_member/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fseteq_002f2"><code>ord_seteq/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fsetproduct_002f3"><code>ord_setproduct/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fsubtract_002f3"><code>ord_subtract/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005fsymdiff_002f3"><code>ord_symdiff/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005funion_002f2"><code>ord_union/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005funion_002f3"><code>ord_union/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ord_005funion_002f4"><code>ord_union/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-P">P</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-partition_002f4"><code>partition/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-partition_002f5"><code>partition/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-path_002f1"><code>path/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fbyte_002f1"><code>peek_byte/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fbyte_002f2"><code>peek_byte/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fchar_002f1"><code>peek_char/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fchar_002f2"><code>peek_char/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fcode_002f1"><code>peek_code/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-peek_005fcode_002f2"><code>peek_code/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-permutation_002f2"><code>permutation/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-phrase_002f2"><code>phrase/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-phrase_002f3"><code>phrase/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-pid_002f1"><code>pid/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-plus_002f3"><code>plus/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-popen_002f3"><code>popen/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-portray_005fclause_002f1"><code>portray_clause/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-portray_005fclause_002f2"><code>portray_clause/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-predicate_005fproperty_002f2"><code>predicate_property/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-predsort_002f3"><code>predsort/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-primitive_002f1"><code>primitive/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_002f1"><code>print/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_002f2"><code>print/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_005fmessage_002f2"><code>print_message/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-print_005fmessage_005flines_002f3"><code>print_message_lines/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Messages">6.3 Message Handling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-process_002f2"><code>process/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profiled_005freset_002f0"><code>profiled_reset/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#The-Count-Profiler">6.18.1 The Count Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profile_005fdata_002f3"><code>profile_data/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#The-Count-Profiler">6.18.1 The Count Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profiling-_0028yap_005fflag_002f2-option_0029"><code>profiling (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profinit_002f0"><code>profinit/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profoff_002f0"><code>profoff/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profon_002f0"><code>profon/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-program-_0028statistics_002f2-option_0029"><code>program (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-project_005fattributes_002f2"><code>project_attributes/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Displaying-Attributes">11.2.4 Displaying Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-project_005fattributes_002f2-3"><code>project_attributes/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Projecting-Attributes">11.2.5 Projecting Attributes</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005ffile_005fname_002f2"><code>prolog_file_name/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005fflag_002f3"><code>prolog_flag/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005finitialization_002f1"><code>prolog_initialization/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prolog_005fload_005fcontext_002f2"><code>prolog_load_context/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prompt_002f2"><code>prompt/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-prompt_005falternatives_005fon--_0028yap_005fflag_002f2-option_0029"><code>prompt_alternatives_on (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-public_002f1-_0028directive_0029"><code>public/1 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_002f1"><code>put/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_002f2"><code>put/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-putenv_002f2"><code>putenv/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fassoc_002f4"><code>put_assoc/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fattr_002f3"><code>put_attr/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fattrs_002f2"><code>put_attrs/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fatts_002f2"><code>put_atts/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Attribute-Manipulation">11.2.2 Attribute Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fbyte_002f1"><code>put_byte/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fbyte_002f2"><code>put_byte/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fchar_002f1"><code>put_char/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fchar_002f2"><code>put_char/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fcode_002f1"><code>put_code/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005fcode_002f2"><code>put_code/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-put_005flabel_002f4"><code>put_label/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-Q">Q</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-queue_005fto_005flist_002f2"><code>queue_to_list/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-R">R</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-random_002f1"><code>random/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-random_002f3"><code>random/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-randseq_002f3"><code>randseq/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-randset_002f3"><code>randset/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rannum_002f1"><code>rannum/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ranstart_002f0"><code>ranstart/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ranstart_002f1"><code>ranstart/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ranunif_002f2"><code>ranunif/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rational_002f1"><code>rational/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fapply_002f4"><code>rb_apply/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fclone_002f3"><code>rb_clone/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdelete_002f3"><code>rb_delete/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdelete_002f4"><code>rb_delete/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdel_005fmax_002f4"><code>rb_del_max/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fdel_005fmin_002f4"><code>rb_del_min/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fempty_002f1"><code>rb_empty/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005finsert_002f4"><code>rb_insert/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fkeys_002f2"><code>rb_keys/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005flookup_002f3"><code>rb_lookup/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005flookupall_002f3"><code>rb_lookupall/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fmap_002f3"><code>rb_map/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fmax_002f3"><code>rb_max/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fmin_002f3"><code>rb_min/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fnew_002f1"><code>rb_new/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fnext_002f4"><code>rb_next/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fpartial_005fmap_002f4"><code>rb_partial_map/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fprevious_002f4"><code>rb_previous/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fsize_002f2"><code>rb_size/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fupdate_002f4"><code>rb_update/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rb_005fvisit_002f2"><code>rb_visit/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reachable_002f3"><code>reachable/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_002f1"><code>read/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_002f2"><code>read/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005ffile_005fto_005fcodes_002f3"><code>read_file_to_codes/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005ffile_005fto_005fterms_002f3"><code>read_file_to_terms/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005ffrom_005fchars_002f2"><code>read_from_chars/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fline_005fto_005fcodes_002f2"><code>read_line_to_codes/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fline_005fto_005fcodes_002f3"><code>read_line_to_codes/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fstream_005fto_005fcodes_002f3"><code>read_stream_to_codes/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fstream_005fto_005fcodes_002f3-3"><code>read_stream_to_codes/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Read-Utilities">7.16 Read Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fterm_002f2"><code>read_term/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-read_005fterm_002f3"><code>read_term/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reconsult_002f1"><code>reconsult/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Compiling">4.1 Program loading and updating</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorda_002f3"><code>recorda/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorda_002f3-3"><code>recorda/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordaifnot_002f3"><code>recordaifnot/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordaifnot_002f3-3"><code>recordaifnot/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorda_005fat_002f3"><code>recorda_at/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recorded_002f3"><code>recorded/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordz_002f3"><code>recordz/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordzifnot_002f3"><code>recordzifnot/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-recordz_005fat_002f3"><code>recordz_at/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reexport_002f1"><code>reexport/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Re_002dExporting-Modules">5.5 Re-Exporting Predicates From Other Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reexport_002f2"><code>reexport/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Re_002dExporting-Modules">5.5 Re-Exporting Predicates From Other Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-regexp_002f3"><code>regexp/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#RegExp">7.18 Regular Expressions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-regexp_002f4"><code>regexp/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#RegExp">7.18 Regular Expressions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-remove_005fduplicates_002f2"><code>remove_duplicates/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-remove_005ffrom_005fpath_002f1"><code>remove_from_path/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rename_002f2"><code>rename/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-rename_005ffile_002f2"><code>rename_file/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-repeat_002f0"><code>repeat/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reset_005fop_005fcounters_002f0"><code>reset_op_counters/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reset_005fstatic_005farray_002f1"><code>reset_static_array/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-resize_005fstatic_005farray_002f3"><code>resize_static_array/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-restore_002f1"><code>restore/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-retract_002f1"><code>retract/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-retract_002f2"><code>retract/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Database-References">6.10.3 Using Data Base References</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-retractall_002f1"><code>retractall/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Modifying-the-Database">6.10.1 Modification of the Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-reverse_002f2"><code>reverse/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-runtime-_0028statistics_002f2-option_0029"><code>runtime (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-S">S</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-same_005flength_002f2"><code>same_length/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_002f1"><code>save/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_002f2"><code>save/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_005fprogram_002f1"><code>save_program/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-save_005fprogram_002f2"><code>save_program/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Saving">4.4 Saving and Loading Prolog States</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scan_005finteger_002f3"><code>scan_integer/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-scan_005fnatural_002f3"><code>scan_natural/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-search_005ffor_002f2"><code>search_for/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-search_005ffor_002f2-3"><code>search_for/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-search_005ffor_002f2-6"><code>search_for/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-see_002f1"><code>see/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-seeing_002f1"><code>seeing/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-seen_002f0"><code>seen/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-select_002f3"><code>select/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-selectchk_002f3"><code>selectchk/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-selectlist_002f3"><code>selectlist/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-serve_005fqueue_002f3"><code>serve_queue/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setarg_002f3n"><code>setarg/3n</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setenv_002f2"><code>setenv/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setof_002f3"><code>setof/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sets">6.13 Collecting Solutions to a Goal</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setrand_002f1"><code>setrand/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setup_005fcall_005fcatcher_005fcleanup_002f4"><code>setup_call_catcher_cleanup/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-setup_005fcall_005fcleanup_002f3"><code>setup_call_cleanup/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005finput_002f1"><code>set_input/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005foutput_002f1"><code>set_output/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005fprolog_005fflag_002f2"><code>set_prolog_flag/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005fstream_005fposition_002f2"><code>set_stream_position/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-set_005fvalue_002f2"><code>set_value/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Internal-Database">6.11 Internal Data Base</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sh_002f0"><code>sh/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-shared_005fobject_005fsearch_005fpath-_0028yap_005fflag_002f2-option_0029"><code>shared_object_search_path (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-shell_002f0"><code>shell/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-shell_002f1"><code>shell/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-shell_002f1-3"><code>shell/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-showprofres_002f0"><code>showprofres/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-showprofres_002f1"><code>showprofres/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tick-Profiler">6.18.2 Tick Profiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-show_005fops_005fby_005fgroup_002f1"><code>show_ops_by_group/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-show_005fop_005fcounters_002f1"><code>show_op_counters/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Profiling">20 Profiling the Abstract Machine</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-show_005ftable_002f1"><code>show_table/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-simple_002f1"><code>simple/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-singletons_002f1-_0028read_005fterm_002f2-option_0029"><code>singletons/1 (read_term/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-single_005fvar_005fwarnings-_0028yap_005fflag_002f2-option_0029"><code>single_var_warnings (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-skip_002f1"><code>skip/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-skip_002f2"><code>skip/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sleep_002f1"><code>sleep/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_002f2"><code>socket/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_002f4"><code>socket/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005faccept_002f2"><code>socket_accept/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005faccept_002f2-3"><code>socket_accept/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005faccept_002f3"><code>socket_accept/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fbind_002f2"><code>socket_bind/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fbuffering_002f4"><code>socket_buffering/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fclose_002f1"><code>socket_close/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fconnect_002f3"><code>socket_connect/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005flisten_002f2"><code>socket_listen/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-socket_005fselect_002f5"><code>socket_select/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Sockets">6.9.8 Using Sockets From YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sort_002f2"><code>sort/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Comparing-Terms">6.7 Comparing Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_002f0"><code>source/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005ffile_002f1"><code>source_file/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005ffile_002f2"><code>source_file/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005flocation_002f2"><code>source_location/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-source_005fmode_002f2"><code>source_mode/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005faccess_002f5"><code>splay_access/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005fdelete_002f4"><code>splay_delete/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005finit_002f3"><code>splay_init/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005finsert_002f4"><code>splay_insert/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005fjoin_002f3"><code>splay_join/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay_005fsplit_002f5"><code>splay_split/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-split_002f2"><code>split/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-split_002f3"><code>split/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-spy_002f1"><code>spy/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-spy_005fwrite_002f2"><code>spy_write/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-srandom_002f1"><code>srandom/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stack_005fdump_005fon_005ferror-_0028yap_005fflag_002f2-option_0029"><code>stack_dump_on_error (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stack_005fshifts-_0028statistics_002f2-option_0029"><code>stack_shifts (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-start_005flow_005flevel_005ftrace_002f0"><code>start_low_level_trace/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Tracing">19 Tracing at Low Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-start_005flow_005flevel_005ftrace_002f0-3"><code>start_low_level_trace/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Low-Level-Tracing">19 Tracing at Low Level</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-start_005fmatlab_002f1"><code>start_matlab/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_002f3"><code>static_array/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_002f3-3"><code>static_array/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_005flocation_002f4"><code>static_array_location/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_005fproperties_002f3"><code>static_array_properties/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005farray_005fto_005fterm_002f3"><code>static_array_to_term/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-static_005fcode-_0028statistics_002f2-option_0029"><code>static_code (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-statistics_002f0"><code>statistics/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-statistics_002f2"><code>statistics/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fposition_002f2"><code>stream_position/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fposition_005fdata_002f3"><code>stream_position_data/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fproperty_002f2"><code>stream_property/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-stream_005fselect_002f3"><code>stream_select/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-strict_005fiso-_0028yap_005fflag_002f2-option_0029"><code>strict_iso (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-style_005fcheck_002f1"><code>style_check/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sublist_002f2"><code>sublist/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-subsumes_002f2"><code>subsumes/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-subsumes_005fchk_002f2"><code>subsumes_chk/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-subsumes_005fterm_002f2"><code>subsumes_term/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sub_005fatom_002f5"><code>sub_atom/5</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Predicates-on-Atoms">6.5 Predicates on Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-succ_002f3"><code>succ/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arithmetic">6.8 Arithmetic</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-suffix_002f2"><code>suffix/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumargs_002f4"><code>sumargs/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumlist_002f2"><code>sumlist/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumlist_002f4"><code>sumlist/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sumnodes_002f4"><code>sumnodes/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sum_005flist_002f2"><code>sum_list/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-sum_005flist_002f3"><code>sum_list/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-syntax_005ferrors-_0028yap_005fflag_002f2-option_0029"><code>syntax_errors (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-syntax_005ferrors_002f1-_0028read_005fterm_002f2-option_0029"><code>syntax_errors/1 (read_term/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_002f0"><code>system/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_002f1"><code>system/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_002f2"><code>system/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_005foptions-_0028yap_005fflag_002f2-option_0029"><code>system_options (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-system_005fpredicate_002f2"><code>system_predicate/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Looking-at-the-Database">6.10.2 Looking at the Data Base</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-T">T</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-tab_002f1"><code>tab/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Characters">6.9.4 Handling Input/Output of Characters</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tab_002f2"><code>tab/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-table_002f1"><code>table/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-table_005fstatistics_002f1"><code>table_statistics/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tabling_005fmode-_0028yap_005fflag_002f2-option_0029"><code>tabling_mode (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tabling_005fmode_002f2"><code>tabling_mode/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tabling_005fstatistics_002f0"><code>tabling_statistics/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tell_002f1"><code>tell/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-telling_002f1"><code>telling/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fattvars_002f2"><code>term_attvars/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#New-Style-Attribute-Declarations">11.1 hProlog and SWI-Prolog style Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fexpansion_002f2"><code>term_expansion/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Grammars">6.14 Grammar Rules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fhash_002f2"><code>term_hash/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fhash_002f4"><code>term_hash/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fposition_002f1-_0028read_005fterm_002f2-option_0029"><code>term_position/1 (read_term/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fto_005fatom_002f2"><code>term_to_atom/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fto_005fatom_002f2-3"><code>term_to_atom/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-term_005fvariables_002f2"><code>term_variables/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-threads_002f0"><code>threads/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fat_005fexit_002f1"><code>thread_at_exit/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fcreate_002f1"><code>thread_create/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fcreate_002f2"><code>thread_create/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fcreate_002f3"><code>thread_create/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fdetach_002f1"><code>thread_detach/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fexit_002f1"><code>thread_exit/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fget_005fmessage_002f1"><code>thread_get_message/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fget_005fmessage_002f2"><code>thread_get_message/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fjoin_002f2"><code>thread_join/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005flocal_002f1-_0028directive_0029"><code>thread_local/1 (directive)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Threads-and-Dynamic-Predicates">16.3.3 Threads and Dynamic Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fpeek_005fmessage_002f1"><code>thread_peek_message/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fpeek_005fmessage_002f2"><code>thread_peek_message/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fproperty_002f2"><code>thread_property/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fself_002f1"><code>thread_self/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsend_005fmessage_002f1"><code>thread_send_message/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsend_005fmessage_002f2"><code>thread_send_message/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Message-Queues">16.3.1 Message Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsetconcurrency_002f2"><code>thread_setconcurrency/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsignal_002f2"><code>thread_signal/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Signalling-Threads">16.3.2 Signalling Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fsleep_002f1"><code>thread_sleep/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fstatistics_002f3"><code>thread_statistics/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Monitoring-Threads">16.2 Monitoring Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-thread_005fyield_002f0"><code>thread_yield/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Creating-and-Destroying-Prolog-Threads">16.1 Creating and Destroying Prolog Threads</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-throw_002f1"><code>throw/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-time_002f1"><code>time/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-time_005ffile_002f2"><code>time_file/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Streams-and-Files">6.9.1 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-time_005fout_002f3"><code>time_out/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Timeout">7.26 Calls With Timeout</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tmpnam_002f1"><code>tmpnam/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tmp_005ffile_002f2"><code>tmp_file/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-told_002f0"><code>told/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-File-Handling">6.9.2 Handling Streams and Files</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-toplevel_005fhook-_0028yap_005fflag_002f2-option_0029"><code>toplevel_hook (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-toplevel_005fprint_005foptions-_0028yap_005fflag_002f2-option_0029"><code>toplevel_print_options (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-top_005fsort_002f2"><code>top_sort/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-top_005fsort_002f3"><code>top_sort/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-to_005fchars_005fmodes-_0028yap_005fflag_002f2-option_0029"><code>to_chars_modes (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trace_002f0"><code>trace/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Deb-Preds">21.1 Debugging Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trail-_0028statistics_002f2-option_0029"><code>trail (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-transitive_005fclosure_002f2"><code>transitive_closure/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-transpose_002f3"><code>transpose/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tree_005fsize_002f2"><code>tree_size/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tree_005fto_005flist_002f2"><code>tree_to_list/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fcheck_005fentry_002f3"><code>trie_check_entry/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fclose_002f1"><code>trie_close/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fclose_005fall_002f0"><code>trie_close_all/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fget_005fentry_002f2"><code>trie_get_entry/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fload_002f2"><code>trie_load/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fmax_005fstats_002f4"><code>trie_max_stats/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fmode_002f1"><code>trie_mode/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fopen_002f1"><code>trie_open/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fprint_002f1"><code>trie_print/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fput_005fentry_002f3"><code>trie_put_entry/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fremove_005fentry_002f1"><code>trie_remove_entry/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fremove_005fsubtree_002f1"><code>trie_remove_subtree/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fsave_002f2"><code>trie_save/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fstats_002f4"><code>trie_stats/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-trie_005fusage_002f4"><code>trie_usage/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-true_002f0"><code>true/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Control">6.1 Control Predicates</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyget_002f1"><code>ttyget/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyget0_002f1"><code>ttyget0/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttynl_002f0"><code>ttynl/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyput_002f1"><code>ttyput/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttyskip_002f1"><code>ttyskip/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ttytab_002f1"><code>ttytab/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#C_002dProlog-to-Terminal">6.9.6 Compatible C-Prolog predicates for Terminal I/O</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-typein_005fmodule-_0028yap_005fflag_002f2-option_0029"><code>typein_module (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-U">U</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-ugraph_005fto_005fdgraph_002f2"><code>ugraph_to_dgraph/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fadd_005fedges_002f3"><code>undgraph_add_edges/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fadd_005fvertices_002f3"><code>undgraph_add_vertices/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fcomplement_002f2"><code>undgraph_complement/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fdel_005fedges_002f3"><code>undgraph_del_edges/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fdel_005fvertices_002f3"><code>undgraph_del_vertices/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fedge_002f2"><code>undgraph_edge/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fedges_002f2"><code>undgraph_edges/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fneighbors_002f3"><code>undgraph_neighbors/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fneighbours_002f3"><code>undgraph_neighbours/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fnew_002f1"><code>undgraph_new/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undgraph_005fvertices_002f2"><code>undgraph_vertices/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unhide_002f1"><code>unhide/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Setting-the-Compiler">4.2 Changing the Compiler&rsquo;s Behavior</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unifiable_002f3"><code>unifiable/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unify_005fwith_005foccurs_005fcheck_002f2"><code>unify_with_occurs_check/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unix-_0028yap_005fflag_002f2-option_0029"><code>unix (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unix_002f1"><code>unix/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#OS">6.15 Access to Operating System Functionality</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unknown-_0028yap_005fflag_002f2-option_0029"><code>unknown (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unknown_002f2"><code>unknown/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unknown_005fpredicate_005fhandler_002f3"><code>unknown_predicate_handler/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Undefined-Procedures">6.2 Handling Undefined Procedures</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unload_005fforeign_005flibrary_002f1"><code>unload_foreign_library/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unload_005fforeign_005flibrary_002f2"><code>unload_foreign_library/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-update_005farray_002f3"><code>update_array/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Arrays">6.20 Arrays</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-update_005fmutable_002f2"><code>update_mutable/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-update_005fsemantics-_0028yap_005fflag_002f2-option_0029"><code>update_semantics (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-user_005ferror-_0028yap_005fflag_002f2-option_0029"><code>user_error (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-user_005fflags--_0028yap_005fflag_002f2-option_0029"><code>user_flags (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-user_005finput-_0028yap_005fflag_002f2-option_0029"><code>user_input (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-user_005foutput-_0028yap_005fflag_002f2-option_0029"><code>user_output (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fforeign_005flibrary_002f1"><code>use_foreign_library/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fforeign_005flibrary_002f2"><code>use_foreign_library/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fmodule_002f1"><code>use_module/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fmodule_002f2"><code>use_module/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-use_005fmodule_002f3"><code>use_module/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Using-Modules">5.3 Using Modules</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-V">V</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-var_002f1"><code>var/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Testing-Terms">6.4 Predicates on terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-variables_002f1-_0028read_005fterm_002f2-option_0029"><code>variables/1 (read_term/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-variables_005fwithin_005fterm_002f3"><code>variables_within_term/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-variable_005fin_005fterm_002f2"><code>variable_in_term/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-variable_005fnames_002f1-_0028read_005fterm_002f2-option_0029"><code>variable_names/1 (read_term/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-variant_002f2"><code>variant/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-verbose-_0028yap_005fflag_002f2-option_0029"><code>verbose (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-verbose_005fload-_0028yap_005fflag_002f2-option_0029"><code>verbose_load (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-verify_005fattributes_002f3"><code>verify_attributes/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Attributed-Unification">11.2.3 Attributed Unification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-version-_0028yap_005fflag_002f2-option_0029"><code>version (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-version_002f0"><code>version/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-version_002f1"><code>version/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-version_005fdata-_0028yap_005fflag_002f2-option_0029"><code>version_data (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-vertices_002f2"><code>vertices/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-vertices_005fedges_005fto_005fugraph_002f3"><code>vertices_edges_to_ugraph/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-W">W</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-wait_002f2"><code>wait/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-walltime-_0028statistics_002f2-option_0029"><code>walltime (statistics/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-when_002f2"><code>when/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Co_002droutining">10.2 Co-routining</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-windoes-_0028yap_005fflag_002f2-option_0029"><code>windoes (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005fmutex_002f2"><code>with_mutex/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Thread-Synchronisation">16.4 Thread Synchronisation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_002f2"><code>with_output_to/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_005fchars_002f2"><code>with_output_to_chars/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_005fchars_002f3"><code>with_output_to_chars/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-with_005foutput_005fto_005fchars_002f4"><code>with_output_to_chars/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-working_005fdirectory_002f2"><code>working_directory/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-working_005fdirectory_002f2-3"><code>working_directory/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_002f1"><code>write/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_002f2"><code>write/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-writeln_002f1"><code>writeln/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-writeq_002f1"><code>writeq/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-writeq_002f2"><code>writeq/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fcanonical_002f1"><code>write_canonical/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fcanonical_002f2"><code>write_canonical/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fdepth_002f2"><code>write_depth/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fdepth_002f3"><code>write_depth/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-Control">6.9.7 Controlling Input/Output</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fstrings-_0028yap_005fflag_002f2-option_0029"><code>write_strings (yap_flag/2 option)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fterm_002f2"><code>write_term/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-of-Terms">6.9.3 Handling Input/Output of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fterm_002f3"><code>write_term/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#I_002fO-for-Streams">6.9.5 Input/Output Predicates applied to Streams</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fto_005fchars_002f2"><code>write_to_chars/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-write_005fto_005fchars_002f3"><code>write_to_chars/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Predicate-Index-1_fn_letter-Y">Y</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAPBINDIR"><code>YAPBINDIR</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Running-YAP-Interactively">2.1 Running YAP Interactively</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAPLIBDIR"><code>YAPLIBDIR</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Running-YAP-Interactively">2.1 Running YAP Interactively</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAPSHAREDIR"><code>YAPSHAREDIR</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Running-YAP-Interactively">2.1 Running YAP Interactively</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fAddressFromSlot-_0028C_002dInterface-function_0029"><code>YAP_AddressFromSlot (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fAGCHook--_0028C_002dInterface-function_0029"><code>YAP_AGCHook (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fAllocSpaceFromYAP-_0028C_002dInterface-function_0029"><code>YAP_AllocSpaceFromYAP (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Memory-Allocation">23.4 Memory Allocation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fArgOfTerm-_0028C_002dInterface-function_0029"><code>YAP_ArgOfTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fArgsOfTerm-_0028C_002dInterface-function_0029"><code>YAP_ArgsOfTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fArgsToSlots-_0028C_002dInterface-function_0029"><code>YAP_ArgsToSlots (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fArityOfFunctor-_0028C_002dInterface-function_0029"><code>YAP_ArityOfFunctor (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fAtomGetHold--_0028C_002dInterface-function_0029"><code>YAP_AtomGetHold (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fAtomName-_0028C_002dInterface-function_0029"><code>YAP_AtomName (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fAtomNameLength-_0028C_002dInterface-function_0029"><code>YAP_AtomNameLength (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fAtomOfTerm-_0028C_002dInterface-function_0029"><code>YAP_AtomOfTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fAtomReleaseHold--_0028C_002dInterface-function_0029"><code>YAP_AtomReleaseHold (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fAtomToPred-_0028C_002dInterface-function_0029"><code>YAP_AtomToPred (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fBigNumOfTerm-_0028C_002dInterface-function_0029"><code>YAP_BigNumOfTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fBufferToAtomList-_0028C_002dInterface-function_0029"><code>YAP_BufferToAtomList (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fBufferToDiffList-_0028C_002dInterface-function_0029"><code>YAP_BufferToDiffList (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fBufferToString-_0028C_002dInterface-function_0029"><code>YAP_BufferToString (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fCallProlog-_0028C_002dInterface-function_0029"><code>YAP_CallProlog (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fClearExceptions-_0028C_002dInterface-function_0029"><code>YAP_ClearExceptions (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fCloseAllOpenStreams-_0028C_002dInterface-function_0029"><code>YAP_CloseAllOpenStreams (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Controlling-Streams">23.5 Controlling YAP Streams from <code>C</code></a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fCompileClause_002f1"><code>YAP_CompileClause/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fContinueGoal_002f0"><code>YAP_ContinueGoal/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fCopyTerm_002f1"><code>YAP_CopyTerm/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fCurrentSlot-_0028C_002dInterface-function_0029"><code>YAP_CurrentSlot (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fcutfail-_0028C_002dInterface-function_0029"><code>YAP_cutfail (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Writing-C">23.10 Writing predicates in C</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fcutsucceed-_0028C_002dInterface-function_0029"><code>YAP_cutsucceed (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Writing-C">23.10 Writing predicates in C</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fEndConsult_002f0"><code>YAP_EndConsult/0</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fEnterGoal-_0028C_002dInterface-function_0029"><code>YAP_EnterGoal (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fErase-_0028C_002dInterface-function_0029"><code>YAP_Erase (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Utility-Functions">23.6 Utility Functions in <code>C</code></a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fError_002f1"><code>YAP_Error/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fExactlyEqual-_0028C_002dInterface-function_0029"><code>YAP_ExactlyEqual (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Utility-Functions">23.6 Utility Functions in <code>C</code></a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fExit_002f1"><code>YAP_Exit/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fFastInit_002f1"><code>YAP_FastInit/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-yap_005fflag_002f2"><code>yap_flag/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Misc">6.22 Miscellaneous</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fFloatOfTerm-_0028C_002dInterface-function_0029"><code>YAP_FloatOfTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fFlushAllStreams-_0028C_002dInterface-function_0029"><code>YAP_FlushAllStreams (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Controlling-Streams">23.5 Controlling YAP Streams from <code>C</code></a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fFreeSpaceFromYAP-_0028C_002dInterface-function_0029"><code>YAP_FreeSpaceFromYAP (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Memory-Allocation">23.4 Memory Allocation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fFullLookupAtom-_0028C_002dInterface-function_0029"><code>YAP_FullLookupAtom (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fFunctorOfTerm-_0028C_002dInterface-function_0029"><code>YAP_FunctorOfTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fFunctorToPred-_0028C_002dInterface-function_0029"><code>YAP_FunctorToPred (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fGetValue_002f1"><code>YAP_GetValue/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fHaltRegisterHook-_0028C_002dInterface-function_0029"><code>YAP_HaltRegisterHook (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Miscellaneous-C_002dFunctions">23.9 Miscellaneous C Functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fHeadOfTerm-_0028C_002dInterface-function_0029"><code>YAP_HeadOfTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fInit_002f1"><code>YAP_Init/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fInitConsult_002f2"><code>YAP_InitConsult/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fInitSlot-_0028C_002dInterface-function_0029"><code>YAP_InitSlot (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIntOfTerm-_0028C_002dInterface-function_0029"><code>YAP_IntOfTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsApplTerm-_0028C_002dInterface-function_0029"><code>YAP_IsApplTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsAtomTerm-_0028C_002dInterface-function_0029"><code>YAP_IsAtomTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsBigNumTerm-_0028C_002dInterface-function_0029"><code>YAP_IsBigNumTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsDBRefTerm-_0028C_002dInterface-function_0029"><code>YAP_IsDBRefTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsFloatTerm-_0028C_002dInterface-function_0029"><code>YAP_IsFloatTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsIntTerm-_0028C_002dInterface-function_0029"><code>YAP_IsIntTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsIsWideAtom-_0028C_002dInterface-function_0029"><code>YAP_IsIsWideAtom (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsNonVarTerm-_0028C_002dInterface-function_0029"><code>YAP_IsNonVarTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsPairTerm-_0028C_002dInterface-function_0029"><code>YAP_IsPairTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsVarTerm-_0028C_002dInterface-function_0029"><code>YAP_IsVarTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fIsWideAtom-_0028C_002dInterface-function_0029"><code>YAP_IsWideAtom (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fLeaveGoal-_0028C_002dInterface-function_0029"><code>YAP_LeaveGoal (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fLookupAtom-_0028C_002dInterface-function_0029"><code>YAP_LookupAtom (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fLookupWideAtom-_0028C_002dInterface-function_0029"><code>YAP_LookupWideAtom (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fMkApplTerm-_0028C_002dInterface-function_0029"><code>YAP_MkApplTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fMkAtomTerm-_0028C_002dInterface-function_0029"><code>YAP_MkAtomTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fMkBigNumTerm-_0028C_002dInterface-function_0029"><code>YAP_MkBigNumTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fMkFloatTerm-_0028C_002dInterface-function_0029"><code>YAP_MkFloatTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fMkFunctor-_0028C_002dInterface-function_0029"><code>YAP_MkFunctor (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fMkIntTerm-_0028C_002dInterface-function_0029"><code>YAP_MkIntTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fMkNewApplTerm-_0028C_002dInterface-function_0029"><code>YAP_MkNewApplTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fMkNewPairTerm-_0028C_002dInterface-function_0029"><code>YAP_MkNewPairTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fMkPairTerm-_0028C_002dInterface-function_0029"><code>YAP_MkPairTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fNameOfFunctor-_0028C_002dInterface-function_0029"><code>YAP_NameOfFunctor (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fNBufferToAtomList-_0028C_002dInterface-function_0029"><code>YAP_NBufferToAtomList (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fNBufferToDiffList-_0028C_002dInterface-function_0029"><code>YAP_NBufferToDiffList (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fNBufferToString-_0028C_002dInterface-function_0029"><code>YAP_NBufferToString (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fNewSlots-_0028C_002dInterface-function_0029"><code>YAP_NewSlots (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fNWideBufferToAtomList-_0028C_002dInterface-function_0029"><code>YAP_NWideBufferToAtomList (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fNWideBufferToDiffList-_0028C_002dInterface-function_0029"><code>YAP_NWideBufferToDiffList (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fNWideBufferToString-_0028C_002dInterface-function_0029"><code>YAP_NWideBufferToString (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fOpenStream-_0028C_002dInterface-function_0029"><code>YAP_OpenStream (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Controlling-Streams">23.5 Controlling YAP Streams from <code>C</code></a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fPRESERVED_005fDATA-_0028C_002dInterface-function_0029"><code>YAP_PRESERVED_DATA (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Writing-C">23.10 Writing predicates in C</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fPRESERVE_005fDATA-_0028C_002dInterface-function_0029"><code>YAP_PRESERVE_DATA (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Writing-C">23.10 Writing predicates in C</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fPutInSlot-_0028C_002dInterface-function_0029"><code>YAP_PutInSlot (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fPutValue_002f2"><code>YAP_PutValue/2</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fRead_002f1"><code>YAP_Read/1</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fReadBuffer-_0028C_002dInterface-function_0029"><code>YAP_ReadBuffer (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fRecord-_0028C_002dInterface-function_0029"><code>YAP_Record (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Utility-Functions">23.6 Utility Functions in <code>C</code></a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fRecorded-_0028C_002dInterface-function_0029"><code>YAP_Recorded (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Utility-Functions">23.6 Utility Functions in <code>C</code></a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fRecoverSlots-_0028C_002dInterface-function_0029"><code>YAP_RecoverSlots (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fReset-_0028C_002dInterface-function_0029"><code>YAP_Reset (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fRestartGoal-_0028C_002dInterface-function_0029"><code>YAP_RestartGoal (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fRestartGoal-_0028C_002dInterface-function_0029-1"><code>YAP_RestartGoal (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fRetryGoal-_0028C_002dInterface-function_0029"><code>YAP_RetryGoal (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fRunGoal-_0028C_002dInterface-function_0029"><code>YAP_RunGoal (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fSetYAPFlag-_0028C_002dInterface-function_0029"><code>YAP_SetYAPFlag (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Miscellaneous-C_002dFunctions">23.9 Miscellaneous C Functions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fShutdownGoal-_0028C_002dInterface-function_0029"><code>YAP_ShutdownGoal (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fSlotsToArgs-_0028C_002dInterface-function_0029"><code>YAP_SlotsToArgs (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Calling-YAP-From-C">23.7 From <code>C</code> back to Prolog</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fStreamToFileNo-_0028C_002dInterface-function_0029"><code>YAP_StreamToFileNo (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Controlling-Streams">23.5 Controlling YAP Streams from <code>C</code></a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fStringToBuffer-_0028C_002dInterface-function_0029"><code>YAP_StringToBuffer (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fTailOfTerm-_0028C_002dInterface-function_0029"><code>YAP_TailOfTerm (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fUnify-_0028C_002dInterface-function_0029"><code>YAP_Unify (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Unifying-Terms">23.2 Unification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fUserBackCPredicate-_0028C_002dInterface-function_002c-deprecated_0029"><code>YAP_UserBackCPredicate (C-Interface function, deprecated)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Writing-C">23.10 Writing predicates in C</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fUserBackCutCPredicate-_0028C_002dInterface-function_0029"><code>YAP_UserBackCutCPredicate (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Writing-C">23.10 Writing predicates in C</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fUserCPredicate-_0028C_002dInterface-function_0029"><code>YAP_UserCPredicate (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Writing-C">23.10 Writing predicates in C</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fWideAtomName-_0028C_002dInterface-function_0029"><code>YAP_WideAtomName (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Terms">23.1 Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fWideBufferToAtomList-_0028C_002dInterface-function_0029"><code>YAP_WideBufferToAtomList (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fWideBufferToDiffList-_0028C_002dInterface-function_0029"><code>YAP_WideBufferToDiffList (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fWideBufferToString-_0028C_002dInterface-function_0029"><code>YAP_WideBufferToString (C-Interface function)</code></a></td><td>&nbsp;</td><td valign="top"><a href="#Manipulating-Strings">23.3 Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fWrite_002f3"><code>YAP_Write/3</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-YAP_005fWriteBuffer_002f4"><code>YAP_WriteBuffer/4</code></a></td><td>&nbsp;</td><td valign="top"><a href="#YAPLibrary">24 Using YAP as a Library</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
</table>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#Predicate-Index-1_fn_symbol-1"><b>!</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-2"><b>,</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-3"><b>-</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-4"><b>;</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-5"><b>&lt;</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-6"><b>=</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-7"><b>&gt;</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-8"><b>@</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-9"><b>[</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_symbol-10"><b>\</b></a>
&nbsp;
<br>
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-J"><b>J</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-K"><b>K</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-M"><b>M</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-Q"><b>Q</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-V"><b>V</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-W"><b>W</b></a>
&nbsp;
<a class="summary-letter" href="#Predicate-Index-1_fn_letter-Y"><b>Y</b></a>
&nbsp;
</td></tr></table>
<hr>
<a name="Concept-Index"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Predicate-Index" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Predicate-Index" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[ &gt; ]</td>
<td valign="middle" align="left">[ &gt;&gt; ]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<a name="Concept-Index-1"></a>
<h1 class="unnumbered">Concept Index</h1>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#Concept-Index-1_cp_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-M"><b>M</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-Q"><b>Q</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-V"><b>V</b></a>
&nbsp;
</td></tr></table>
<table class="index-cp" border="0">
<tr><td></td><th align="left">Index Entry</th><td>&nbsp;</td><th align="left"> Section</th></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-A">A</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-aggregate">aggregate</a></td><td>&nbsp;</td><td valign="top"><a href="#Aggregate">7.1 Aggregate</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-anonymous-variable">anonymous variable</a></td><td>&nbsp;</td><td valign="top"><a href="#Variables">3.2.4 Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-apply">apply</a></td><td>&nbsp;</td><td valign="top"><a href="#Apply">7.2 Apply Macros</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-association-list">association list</a></td><td>&nbsp;</td><td valign="top"><a href="#Association-Lists">7.3 Association Lists</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-atom">atom</a></td><td>&nbsp;</td><td valign="top"><a href="#Atoms">3.2.3 Atoms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attribute-declaration">attribute declaration</a></td><td>&nbsp;</td><td valign="top"><a href="#Attribute-Declarations">11.2.1 Attribute Declarations</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-attributed-variables">attributed variables</a></td><td>&nbsp;</td><td valign="top"><a href="#Attributed-Variables">11 Attributed Variables</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-AVL-trees">AVL trees</a></td><td>&nbsp;</td><td valign="top"><a href="#AVL-Trees">7.4 AVL Trees</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-B">B</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-BOM">BOM</a></td><td>&nbsp;</td><td valign="top"><a href="#BOM">3.3.2 BOM: Byte Order Mark</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-booting">booting</a></td><td>&nbsp;</td><td valign="top"><a href="#Run">2 Running YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Byte-Order-Mark">Byte Order Mark</a></td><td>&nbsp;</td><td valign="top"><a href="#BOM">3.3.2 BOM: Byte Order Mark</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-C">C</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-cleanup">cleanup</a></td><td>&nbsp;</td><td valign="top"><a href="#Cleanup">7.25 Call Cleanup</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-CLPQ">CLPQ</a></td><td>&nbsp;</td><td valign="top"><a href="#CLPR">12 Constraint Logic Programming over Reals</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-CLPR">CLPR</a></td><td>&nbsp;</td><td valign="top"><a href="#CLPR">12 Constraint Logic Programming over Reals</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-comment">comment</a></td><td>&nbsp;</td><td valign="top"><a href="#Layout">3.2.6 Layout</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Counting-Calls">Counting Calls</a></td><td>&nbsp;</td><td valign="top"><a href="#Call-Counting">6.19 Counting Calls</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-D">D</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-declaration_002c-attribute">declaration, attribute</a></td><td>&nbsp;</td><td valign="top"><a href="#Attribute-Declarations">11.2.1 Attribute Declarations</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-E">E</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-Efficient-Directed-Graphs">Efficient Directed Graphs</a></td><td>&nbsp;</td><td valign="top"><a href="#DGraphs">7.29 Directed Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-encodings">encodings</a></td><td>&nbsp;</td><td valign="top"><a href="#Encoding">3.3 Wide Character Support</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-end-of-term">end of term</a></td><td>&nbsp;</td><td valign="top"><a href="#Formal-Syntax">3.1 Syntax of Terms</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-environment-variables">environment variables</a></td><td>&nbsp;</td><td valign="top"><a href="#Running-YAP-Interactively">2.1 Running YAP Interactively</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-F">F</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-floating_002dpoint-number">floating-point number</a></td><td>&nbsp;</td><td valign="top"><a href="#Floats">3.2.1.2 Floating-point Numbers</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-G">G</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-global-variables">global variables</a></td><td>&nbsp;</td><td valign="top"><a href="#Global-Variables">6.17 Global Variables</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-H">H</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-heap">heap</a></td><td>&nbsp;</td><td valign="top"><a href="#Heaps">7.5 Heaps</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-I">I</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-installation">installation</a></td><td>&nbsp;</td><td valign="top"><a href="#Install">1 Installing YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-integer">integer</a></td><td>&nbsp;</td><td valign="top"><a href="#Integers">3.2.1.1 Integers</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-internationalization">internationalization</a></td><td>&nbsp;</td><td valign="top"><a href="#Encoding">3.3 Wide Character Support</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-L">L</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-lam">lam</a></td><td>&nbsp;</td><td valign="top"><a href="#LAM">7.32 LAM</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Lambda-Expressions">Lambda Expressions</a></td><td>&nbsp;</td><td valign="top"><a href="#Lambda">7.31 Lambda Expressions</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Line-Utilities-Library">Line Utilities Library</a></td><td>&nbsp;</td><td valign="top"><a href="#LineUtilities">7.7 Line Manipulation Utilities</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-list-manipulation">list manipulation</a></td><td>&nbsp;</td><td valign="top"><a href="#Lists">7.6 List Manipulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Logtalk">Logtalk</a></td><td>&nbsp;</td><td valign="top"><a href="#Logtalk">14 Logtalk</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-M">M</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-machine-optimizations">machine optimizations</a></td><td>&nbsp;</td><td valign="top"><a href="#Machine-Options">1.2 Tuning YAP for a Particular Machine and Compiler</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-macros">macros</a></td><td>&nbsp;</td><td valign="top"><a href="#MapList">7.8 Maplist</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Matlab-Interface">Matlab Interface</a></td><td>&nbsp;</td><td valign="top"><a href="#MATLAB">7.10 MATLAB Package Interface</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Matrix-Library">Matrix Library</a></td><td>&nbsp;</td><td valign="top"><a href="#matrix">7.9 Matrix Library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-mutable-variables">mutable variables</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-MYDDAS">MYDDAS</a></td><td>&nbsp;</td><td valign="top"><a href="#MYDDAS">15 MYDDAS</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-N">N</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-number">number</a></td><td>&nbsp;</td><td valign="top"><a href="#Numbers">3.2.1 Numbers</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-O">O</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-Operating-System-Utilities">Operating System Utilities</a></td><td>&nbsp;</td><td valign="top"><a href="#System">7.22 Calling The Operating System from YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-or_002dparallelism">or-parallelism</a></td><td>&nbsp;</td><td valign="top"><a href="#Parallelism">17 Parallelism</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-ordered-set">ordered set</a></td><td>&nbsp;</td><td valign="top"><a href="#Ordered-Sets">7.12 Ordered Sets</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-P">P</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-parallelism">parallelism</a></td><td>&nbsp;</td><td valign="top"><a href="#Parallelism">17 Parallelism</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-profiling">profiling</a></td><td>&nbsp;</td><td valign="top"><a href="#Profiling">6.18 Profiling Prolog Programs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-pseudo-random">pseudo random</a></td><td>&nbsp;</td><td valign="top"><a href="#Pseudo-Random">7.13 Pseudo Random Number Integer Generator</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-punctuation-token">punctuation token</a></td><td>&nbsp;</td><td valign="top"><a href="#Punctuation-Tokens">3.2.5 Punctuation Tokens</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-Q">Q</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-queue">queue</a></td><td>&nbsp;</td><td valign="top"><a href="#Queues">7.14 Queues</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-queue-1">queue</a></td><td>&nbsp;</td><td valign="top"><a href="#Random">7.15 Random Number Generator</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-R">R</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-Red_002dBlack-Trees">Red-Black Trees</a></td><td>&nbsp;</td><td valign="top"><a href="#Red_002dBlack-Trees">7.17 Red-Black Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-regular-expressions">regular expressions</a></td><td>&nbsp;</td><td valign="top"><a href="#RegExp">7.18 Regular Expressions</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-S">S</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-splay-trees">splay trees</a></td><td>&nbsp;</td><td valign="top"><a href="#Splay-Trees">7.20 Splay Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-string">string</a></td><td>&nbsp;</td><td valign="top"><a href="#Strings">3.2.2 Character Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-string-I_002fO">string I/O</a></td><td>&nbsp;</td><td valign="top"><a href="#String-I_002fO">7.21 Reading From and Writing To Strings</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-SWI_002dCompatible-foreign-file-loading">SWI-Compatible foreign file loading</a></td><td>&nbsp;</td><td valign="top"><a href="#shlib">7.19 SWI-Prolog&rsquo;s shlib library</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-SWI_002dProlog">SWI-Prolog</a></td><td>&nbsp;</td><td valign="top"><a href="#SWI_002dProlog">8 SWI-Prolog Emulation</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-syntax">syntax</a></td><td>&nbsp;</td><td valign="top"><a href="#Configuration-Options">1.1 Tuning the Functionality of YAP</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-syntax-1">syntax</a></td><td>&nbsp;</td><td valign="top"><a href="#Formal-Syntax">3.1 Syntax of Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-T">T</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-tabling">tabling</a></td><td>&nbsp;</td><td valign="top"><a href="#Tabling">18 Tabling</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-timeout">timeout</a></td><td>&nbsp;</td><td valign="top"><a href="#Timeout">7.26 Calls With Timeout</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-token">token</a></td><td>&nbsp;</td><td valign="top"><a href="#Tokens">3.2 Prolog Tokens</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-tries">tries</a></td><td>&nbsp;</td><td valign="top"><a href="#Tries">7.24 Trie DataStructure</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-U">U</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-UCS">UCS</a></td><td>&nbsp;</td><td valign="top"><a href="#Encoding">3.3 Wide Character Support</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-undirected-graphs">undirected graphs</a></td><td>&nbsp;</td><td valign="top"><a href="#UnDGraphs">7.30 Undirected Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-Unicode">Unicode</a></td><td>&nbsp;</td><td valign="top"><a href="#Encoding">3.3 Wide Character Support</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-unweighted-graphs">unweighted graphs</a></td><td>&nbsp;</td><td valign="top"><a href="#UGraphs">7.28 Unweighted Graphs</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-updatable-tree">updatable tree</a></td><td>&nbsp;</td><td valign="top"><a href="#Trees">7.27 Updatable Binary Trees</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-update-semantics">update semantics</a></td><td>&nbsp;</td><td valign="top"><a href="#Major-Differences-with-SICStus">25.2.1 Major Differences between YAP and SICStus Prolog.</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-updating-terms">updating terms</a></td><td>&nbsp;</td><td valign="top"><a href="#Term-Modification">6.16 Term Modification</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-UTF_002d8">UTF-8</a></td><td>&nbsp;</td><td valign="top"><a href="#Encoding">3.3 Wide Character Support</a></td></tr>
<tr><td></td><td valign="top"><a href="#index-utilities-on-terms">utilities on terms</a></td><td>&nbsp;</td><td valign="top"><a href="#Terms">7.23 Utilities On Terms</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
<tr><th><a name="Concept-Index-1_cp_letter-V">V</a></th><td></td><td></td></tr>
<tr><td></td><td valign="top"><a href="#index-variable">variable</a></td><td>&nbsp;</td><td valign="top"><a href="#Variables">3.2.4 Variables</a></td></tr>
<tr><td colspan="4"> <hr></td></tr>
</table>
<table><tr><th valign="top">Jump to: &nbsp; </th><td><a class="summary-letter" href="#Concept-Index-1_cp_letter-A"><b>A</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-B"><b>B</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-C"><b>C</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-D"><b>D</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-E"><b>E</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-F"><b>F</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-G"><b>G</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-H"><b>H</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-I"><b>I</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-L"><b>L</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-M"><b>M</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-N"><b>N</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-O"><b>O</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-P"><b>P</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-Q"><b>Q</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-R"><b>R</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-S"><b>S</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-T"><b>T</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-U"><b>U</b></a>
&nbsp;
<a class="summary-letter" href="#Concept-Index-1_cp_letter-V"><b>V</b></a>
&nbsp;
</td></tr></table>
<hr size="6">
<a name="SEC_About"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="#Compatibility" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h1>About This Document</h1>
<p>
This document was generated on <i>October 18, 2010</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 5.0</i></a>.
</p>
<p>
The buttons in the navigation panels have the following meaning:
</p>
<table border="1">
<tr>
<th> Button </th>
<th> Name </th>
<th> Go to </th>
<th> From 1.2.3 go to</th>
</tr>
<tr>
<td align="center"> [ &lt;&lt; ] </td>
<td align="center">FastBack</td>
<td>Beginning of this chapter or previous chapter</td>
<td>1</td>
</tr>
<tr>
<td align="center"> [ &lt; ] </td>
<td align="center">Back</td>
<td>Previous section in reading order</td>
<td>1.2.2</td>
</tr>
<tr>
<td align="center"> [ Up ] </td>
<td align="center">Up</td>
<td>Up section</td>
<td>1.2</td>
</tr>
<tr>
<td align="center"> [ &gt; ] </td>
<td align="center">Forward</td>
<td>Next section in reading order</td>
<td>1.2.4</td>
</tr>
<tr>
<td align="center"> [ &gt;&gt; ] </td>
<td align="center">FastForward</td>
<td>Next chapter</td>
<td>2</td>
</tr>
<tr>
<td align="center"> [Top] </td>
<td align="center">Top</td>
<td>Cover (top) of document</td>
<td> &nbsp; </td>
</tr>
<tr>
<td align="center"> [Contents] </td>
<td align="center">Contents</td>
<td>Table of contents</td>
<td> &nbsp; </td>
</tr>
<tr>
<td align="center"> [Index] </td>
<td align="center">Index</td>
<td>Index</td>
<td> &nbsp; </td>
</tr>
<tr>
<td align="center"> [ ? ] </td>
<td align="center">About</td>
<td>About (help)</td>
<td> &nbsp; </td>
</tr>
</table>
<p>
where the <strong> Example </strong> assumes that the current position is at <strong> Subsubsection One-Two-Three </strong> of a document of the following structure:
</p>
<ul>
<li> 1. Section One
<ul>
<li>1.1 Subsection One-One
<ul>
<li>...</li>
</ul>
</li>
<li>1.2 Subsection One-Two
<ul>
<li>1.2.1 Subsubsection One-Two-One</li>
<li>1.2.2 Subsubsection One-Two-Two</li>
<li>1.2.3 Subsubsection One-Two-Three &nbsp; &nbsp;
<strong>&lt;== Current Position </strong></li>
<li>1.2.4 Subsubsection One-Two-Four</li>
</ul>
</li>
<li>1.3 Subsection One-Three
<ul>
<li>...</li>
</ul>
</li>
<li>1.4 Subsection One-Four</li>
</ul>
</li>
</ul>
<hr>
<p>
<font size="-1">
This document was generated on <i>October 18, 2010</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 5.0</i></a>.
</font>
<br>
</p>
</body>
</html>