Table of Contents

1 Introduction
1.1 Positioning SWI-Prolog
1.2 Status and releases
1.3 Should I be using SWI-Prolog?
1.4 Support the SWI-Prolog project
1.5 Implementation history
1.6 Acknowledgements
2 Overview
2.1 Getting started quickly
2.1.1 Starting SWI-Prolog
2.1.1.1 Starting SWI-Prolog on Unix
2.1.1.2 Starting SWI-Prolog on Windows
2.1.2 Executing a query
2.2 The user's initialisation file
2.3 Initialisation files and goals
2.4 Command line options
2.4.1 Informational command line options
2.4.2 Command line options for running Prolog
2.4.3 Controlling the stack sizes
2.4.4 Running goals from the command line
2.4.5 Compilation options
2.4.6 Maintenance options
2.5 GNU Emacs Interface
2.6 Online Help
2.7 Command line history
2.8 Reuse of top-level bindings
2.9 Overview of the Debugger
2.10 Compilation
2.10.1 During program development
2.10.2 For running the result
2.10.2.1 Using PrologScript
2.10.2.2 Creating a shell script
2.10.2.3 Creating a saved state
2.10.2.4 Compilation using the -c command line option
2.11 Environment Control (Prolog flags)
2.12 An overview of hook predicates
2.13 Automatic loading of libraries
2.14 Garbage Collection
2.15 Syntax Notes
2.15.1 ISO Syntax Support
2.15.1.1 Processor Character Set
2.15.1.2 Character Escape Syntax
2.15.1.3 Syntax for non-decimal numbers
2.15.1.4 Using digit groups in large integers
2.15.1.5 Unicode Prolog source
2.15.1.6 Singleton variable checking
2.16 Rational trees (cyclic terms)
2.17 Just-in-time clause indexing
2.17.1 Future directions
2.17.2 Indexing and portability
2.18 Wide character support
2.18.1 Wide character encodings on streams
2.18.1.1 BOM: Byte Order Mark
2.19 System limits
2.19.1 Limits on memory areas
2.19.1.1 The heap
2.19.2 Other Limits
2.19.3 Reserved Names
2.20 SWI-Prolog and 64-bit machines
2.20.1 Supported platforms
2.20.2 Comparing 32- and 64-bits Prolog
2.20.3 Choosing between 32- and 64-bit Prolog
3 Initialising and Managing a Prolog Project
3.1 The project source files
3.1.1 File Names and Locations
3.1.1.1 File Name Extensions
3.1.1.2 Project Directories
3.1.1.3 Sub-projects using search paths
3.1.2 Project Special Files
3.1.3 International source files
3.2 Using modules
3.3 The test-edit-reload cycle
3.3.1 Locating things to edit
3.3.2 Editing and incremental compilation
3.4 Using the PceEmacs built-in editor
3.4.1 Activating PceEmacs
3.4.2 Bluffing through PceEmacs
3.4.2.1 Edit modes
3.4.2.2 Frequently used editor commands
3.4.3 Prolog Mode
3.4.3.1 Finding your way around
3.5 The Graphical Debugger
3.5.1 Invoking the window-based debugger
3.6 The Prolog Navigator
3.7 Cross-referencer
3.8 Accessing the IDE from your program
3.9 Summary of the IDE
4 Built-in Predicates
4.1 Notation of Predicate Descriptions
4.2 Character representation
4.3 Loading Prolog source files
4.3.1 Conditional compilation and program transformation
4.3.1.1 Program transformation with source layout info
4.3.1.2 Conditional compilation
4.3.2 Loading files, active code and threads
4.3.2.1 Compilation of mutually dependent code
4.3.2.2 Compilation with multiple threads
4.3.2.3 Reloading running code
4.3.3 Quick load files
4.4 Editor Interface
4.4.1 Customizing the editor interface
4.5 List the program, predicates or clauses
4.6 Verify Type of a Term
4.7 Comparison and Unification of Terms
4.7.1 Standard Order of Terms
4.7.2 Special unification and comparison predicates
4.8 Control Predicates
4.9 Meta-Call Predicates
4.10 ISO compliant Exception handling
4.10.1 Debugging and exceptions
4.10.2 The exception term
4.10.3 Printing messages
4.10.3.1 Printing from libraries
4.11 Handling signals
4.11.1 Notes on signal handling
4.12 DCG Grammar rules
4.13 Database
4.13.1 Update view
4.13.2 Indexing databases
4.14 Declaring predicate properties
4.15 Examining the program
4.16 Input and output
4.16.1 Predefined stream aliases
4.16.2 ISO Input and Output Streams
4.16.3 Edinburgh-style I/O
4.16.4 Switching between Edinburgh and ISO I/O
4.16.5 Write onto atoms, code-lists, etc.
4.17 Status of streams
4.18 Primitive character I/O
4.19 Term reading and writing
4.20 Analysing and Constructing Terms
4.20.1 Non-logical operations on terms
4.21 Analysing and Constructing Atoms
4.22 Localization (locale) support
4.23 Character properties
4.23.1 Case conversion
4.23.2 White space normalization
4.23.3 Language-specific comparison
4.24 Representing text in strings
4.25 Operators
4.26 Character Conversion
4.27 Arithmetic
4.27.1 Special purpose integer arithmetic
4.27.2 General purpose arithmetic
4.27.2.1 Arithmetic types
4.27.2.2 Rational number examples
4.27.2.3 Arithmetic Functions
4.28 Misc arithmetic support predicates
4.29 Built-in list operations
4.30 Finding all Solutions to a Goal
4.31 Forall
4.32 Formatted Write
4.32.1 Writef
4.32.2 Format
4.32.3 Programming Format
4.33 Terminal Control
4.34 Operating System Interaction
4.34.1 Windows-specific Operating System Interaction
4.34.2 Dealing with time and date
4.34.2.1 Time and date data structures
4.34.2.2 Time and date predicates
4.34.3 Controlling the swipl-win.exe console window
4.35 File System Interaction
4.36 User Top-level Manipulation
4.37 Creating a Protocol of the User Interaction
4.38 Debugging and Tracing Programs
4.39 Obtaining Runtime Statistics
4.40 Execution profiling
4.40.1 Profiling predicates
4.40.2 Visualizing profiling data
4.40.3 Information gathering
4.40.3.1 Profiling in the Windows Implementation
4.41 Memory Management
4.42 Windows DDE interface
4.42.1 DDE client interface
4.42.2 DDE server mode
4.43 Miscellaneous
5 Modules
5.1 Why Use Modules?
5.2 Defining a Module
5.3 Importing Predicates into a Module
5.4 Defining a meta-predicate
5.5 Overruling Module Boundaries
5.5.1 Explicit manipulation of the calling context
5.6 Interacting with modules from the top level
5.7 Composing modules from other modules
5.8 Operators and modules
5.9 Dynamic importing using import modules
5.10 Reserved Modules and using the `user' module
5.11 An alternative import/export interface
5.12 Dynamic Modules
5.13 Transparent predicates: definition and context module
5.14 Module properties
5.15 Compatibility of the Module System
6 Special Variables and Coroutining
6.1 Attributed variables
6.1.1 Attribute manipulation predicates
6.1.2 Attributed variable hooks
6.1.3 Operations on terms with attributed variables
6.1.4 Special purpose predicates for attributes
6.2 Coroutining
6.3 Global variables
6.3.1 Compatibility of SWI-Prolog Global Variables
7 CHR: Constraint Handling Rules
7.1 Introduction
7.2 Syntax and Semantics
7.2.1 Syntax of CHR rules
7.2.2 Semantics
7.2 Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>PocodsUYG/&"rw>C꫸~h5Y:">Syntds>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>Pocods>PoG/&"rw>C꫸~h5Y:">4.24 Representing text in strings
4.25 Operators
Defining a meta-predicatePL_thread_attach_engine() a 5px #888; display: none; background: #fff; color: #000; margin-todysirale. Aptlicatiois should make no other assumptions about its reprettach_engine()">PL_thread_attach_engine() a 5px a 5px a 5or: #000; margin-tod00006440000000f="gvar.h="toc-h4"> Pocods>class="toc-h2">4.39Obtaining Runtime Statistics
pan cl for other purposes.
4.3.2.1
4.3.2.1
4.3.2.1
4.3.2.1
4.3.2.1
4.3.2.1<">4.3.2.1
4.3.2.1
4.3.2.1<">4.3.2.1
4.3.2.1
4.3.2.1
4.3.2.1
a 5T.1
4.3.2.14.3.3.14.3.3.14.3.3.14.3.3.14.3.3.14.3.3.14.3.3.14.3.3.14.3.3.14.3.3.14.3.3.14.3.3.14.3.3.13.3.14.3.3.14.3.3.14.3.3.14.3.3.14.3.3.13.3.14.3.3.1 a 5px a 5px a 5px a 5px ass=" oc-h2"> Semantics Semantics Previous =f="useresource.html">
Request the DDE server to execute the given command string. Succeeds if the command could be executed and fails with an error message otherwise.
dde_poke(+Handle (:-).
.

Some of these predicates match directly to corresponding list operations. It is advised to use tht versions from this library to make clear you are operating on ordered sets. An exception is member/2. See ord_memberchk/2.

The ordsets library is based on the stanilists. the stanilists. the stanilists. the stanilists. the stanilists. the stanilng thread. If engine is memclass="pubdets library is based on the stanilists the stanilists. Whe stanilists. the stanilists. the dd>

.

Sometallation-, single-character commands are; overflow: hidden; } dt.pub>+Handlone of <, ed sets. An exception is member/2. See <,./usr/lib/swi-prolog/doc/Manual/predicate_options.html00006>(:Goal)

portray(true)Goal rat|enilu00006>((((((((((00006>(:G>y"? Implies portray(true)Goal rat|enilu00006>((((((((((00006>( portray(true)readin00006>/usr/l.pred-tag { float: right; padding-top: 0.2em; sec-title">Built-in list ops" href="initfile.html">readig>((((((((((00006>(:G>y"? Implies portray(true)Goal rat|enilu00006>((((((((((00006>( portray(true) ortray(true)Goal rat|enilu00006>((( ((((((00006>( portray(true)SWI-Prolog is basedpds}uessu8չa>
Heary" hreettach_engin-right:1u is basedpds}uessu800006>
top
Value is unified with true if Frame is the top Prolog goal from a recursive call back from the foreign language; false otherwise.
hidden
Value

Ty"> Value is unified with true if Framear> is unified with true if trueValue Value

Ty"> Value is unified with true if Framedr> is unified with true if trueValue Value

Ty"> Value is unified with true if Framedr> is unified with true if trueValue ammunity, especially  g<@Ĝ kcD+z_*ency ond terms musbug if trueValue

Ty"> Value is unified with 4rue if Framear> is u((00006/var> i bold; margin-left: 2em; } class="pred" href="termrw.html#ppss:unify">unify with the first argument of the goal, which also expects its first argument to be ground. ord_selectchk(X, S, T)

[ISO]read(-Term)
Read the next Prolog term from the current input stream and unify it with Term. On a syntax error arls Goal rat|enilu00006><'/var>. On a syntax error ord_selectchk(|, S, T)section 5.9). Note that ord_memberchk/2.

The ordsets library is based on the stanilists. thename, this name is returned in ord_mgative,s libraryt.pubdef, dt.multidef { color: #f has been written.

[ISO] SWI-Prolog, mgative,s libraryt.pubdef, dt.<code>true</code> if <var>Frame</var> is the top Prolog goal from a recursive call back from the fative,s libraryt.pubdef, dt.multidef { color: ="idx:read1:1004"></Xtnt to be ground. <code>ed" dt.mO]</span><a id="/dd/strict.dtd"> <html> <head> <title>SWI-Prolog, yt.pmultidef { co it must be possi.<cocD+z_"pead_atta"h_engink/2">ord_memberchk/2</a>. <p>The ordsets library is based on the stanilists. thename, this name is returned in <ust be . thename, ta_atta"h_engink/2">ord_mgative,s libraryt.pubdef, dt.multidef { color: #f has been writte>.</dd> <dt class="pubdef"><song>PL_geared2</i> do not interpret the same option dcode></td><td>A+z_"pead_atta"h_engink/2">ord_memberchk/2</a>. <p>Thst term read. See <a id="idx:readterm2:452"></a><a class="pred" href="termrw.html#read_term/2">read_term/2</a> for details. </td><cide formatted output.��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������