SWI-Prolog For MS-Windows
SWI-Prolog For MS-Windows
Abstract
This document gets you started using SWI-Prolog on MS-Windows. It also describes
the components and issues that are specific to MS-Windows. It is by no means a
manual or Prolog tutorial. The reference manual is available online or can be
downloaded in HTML and PDF format from the http://www.swi-prolog.org/SWI-
Prolog website , which also provides links to books, online tutorials and other
Prolog-related material.
Table of Contents
1 Using SWI-Prolog
1.1 Starting Prolog and loading a program
1.2 Executing a query
1.3 Menu commands
1.4 Editing Prolog programs
1.5 Some useful commands
2 Using SWI-Prolog with C/C++
2.1 Using MSVC
2.2 Using swipl-ld.exe
3 The installation
3.1 Supported Windows versions
3.2 Choosing the file extension
3.3 Installed programs
3.4 Installed Registry keys and menus
3.5 Execution level
3.6 Creating a desktop menu item
4 The SWI-Prolog community and foundation
4.1 Website and mailing lists
4.2 About license conditions
4.3 Supporting SWI-Prolog
1 Using SWI-Prolog
1.1 Starting Prolog and loading a program
The SWI-Prolog executable swipl-win.exe can be started from the StartMenu or by opening a file holding
Prolog program text from the Windows explorer..pl1 The installation folder (by default ) contains a
subfolder with the file . This file can be opened in Prolog from the StartMenu, by opening in the Windows
explorer or by using the following command in the Prolog application. Be sure to get the quotes right and
terminate the command with a full stop (). C:\Program Files\swipldemolikes.pllikes.pl.
?- [swi('demo/likes')].
file:///C:/Program Files/swipl/doc/windows.html 1/8
22/04/2021 SWI-Prolog for MS-Windows
If Prolog is started from the start menu it is passed the option , which causes it to start in the local equivalent
of . This folder is created if it does not exist. --win_appMyDocuments\Prolog
After loading a program, one can ask Prolog queries about the program. The query below asks Prolog what
food `sam' likes. The system responds with if it can prove the goal for a certain . The user can type the semi-
colon (;) or spacebar. If you want another solution. Use the key if you do not want to see the more
answers. Prolog completes the output a full stop (.) if the user uses the key or Prolog knowns there
are no more answers. If Prolog cannot find (more) answers, it writes false. Finally, Prolog can answer using
an error message to indicate the query or program contains an error. X = <value>X
?- likes(sam, X).
X = dahl ;
X = tandoori ;
...
X = chips.
?-
Note that the answer written by Prolog is a valid Prolog program that, when executed, produces the same set
of answers as the original program.
File/Navigator ...
Opens an explorer-like view on Prolog files and the predicates they contain.
Settings/Font ...
Allows for changing the font of the console. On some installations the default font gives redraw and
cursor dislocation problems. In this case you may wish to select an alternative. Some built-in
commands assume non-proportional fonts.
Run/Interrupt
Try to interrupt the running Prolog process. This is the same as using Control-C. Sometimes interrupts
are not honoured or take very long to process. Closing the window twice provides a way to force
Prolog to stop.
Run/New thread
Creates a new interactor window running in a separate thread of execution. This may be used to
inspect the database or program while the main task continues.
Help
The help menu provides various starting points to related documents. Items flagged with (on www)
open your default internet browser on a page of the SWI-Prolog website.
The default editor is the built-in editor called PceEmacs. This editor provides colourisation support based on
real-time parsing and cross-reference analysis of the program.
Other options for editing include GNU-Emacs, SWI-Prolog-Editor and the Eclipse-based PDT environment.
See http://www.swi-prolog.org/IDE.html for an up-to-date overview.
This section provides a very brief overview of important or commonly used SWI-Prolog predicates to control
the environment.
consult(:File)
Load a source file. On Windows, folders may be specified with the DOS/Windows , which must be
escaped, or by using the POSIX standard . Especially when used in source code, is to be preferred as it
is portable. A Prolog list ([ ... ]) can be used to abbreviate the consult command. The file extension ( as
well as the selected alternative) can be omitted. Here are some examples: \//.pl
pwd
Print working directory (folder).
ls
List files in current directory.
edit
If Prolog is started by opening a file in the explorer, edit this file. Also available from the menu..pl
edit(+Spec)
Edit file, predicate, module, etc., with the given name. If multiple items are named it prompts for the
desired alternative.Spec
make
Reload all files that have been changed since they were last loaded. Normally used after editing one or
more files.
gtrace
Start the graphical debugger. There are three ways to use this. Entered as a single goal at the top level,
the next query will be traced. Alternatively it can be used in conjunction with the goal to be debugged:
and finally you can include it in your program to start tracing at a particular point or under a particular
condition: ?- gtrace, run.
...,
(var(X) -> gtrace ; true),
...,
trace
Same as gtrace, but text-based on the console.
apropos(+Keyword)
Search for all predicates that contain in their name or short description. If a GUI environment is
available the results are hyperlinks. Otherwise use help/1 to get details on selected hits.Keyword
help(+Spec)
Give help on , which is normally the name of a predicate or C interface function. Spec
First of all, add the folder of the installation to the search path for headers and the folder to the search path
for libraries. Both DLLs (extensions) or embedded executables should link to and, if appropriate, to the
multithreaded DLL version of the MSVC runtime library. includeliblibswipl.dll.a
To create extensions, create a Win32 DLL. To embed Prolog, care should be taken that Prolog can find the
Prolog installation. For development, the simplest way to ensure this is by adding the installation folder to the
environment and calling PL_initialise() as illustrated below. PL_initialise() uses the path of the loaded
module to find the Prolog installation folder.bin%PATH%libswipl.dll2
if ( !PL_initialise(1, av) )
{ <error>
}
}
To create an executable that does not rely on Prolog one must create a saved state of the required Prolog code
and attach this to the executable. Creating saved states is described with qsave_program/2 in the reference
manual. This can be attached to a state using the DOS command below to create from the executable
produced by MSVC and the generated saved state. final.exe
3 The installation
3.1 Supported Windows versions
SWI-Prolog requiring Windows XP or later (XP, Vista, Windows-7). The download site of SWI-Prolog
contains older binaries that run on older versions of Windows. We provide both 32-bit and 64-bit installers.
The table below lists the installed components. Some components are marked (32-bits) or (64-bits). Most of
this is because the 64-bit version is built using more recent tools and from more recent versions of required
libraries using different naming conventions. This will probably be synchronised in the future.
Programs
bin\swipl-win.exe Default Windows application for interactive use.
bin\swipl.exe Console-based version for scripting purposes.
Utilities
bin\swipl-ld.exe Linker front-end to make single-file mixed Prolog/C/C++ executables.
bin\swipl-rc.exe Manipulate Prolog resource files.
Important directories
bin Executables and DLL files
library Prolog library
boot Sources for system predicates
HKEY_LOCAL_MACHINE\Software\SWI\Prolog
fileExtension Extension used for Prolog files
group Start menu group
home Installation directory
HKEY_CURRENT_USER\Software\SWI\Plwin\Console
Note: thread-windows store the same info in sub-keys
Height Height of window in character units
Width Width of window in character units
X Left edge of window in pixel units
Y Top edge of window in pixel units
SaveLines Number of lines available for scrollback
The installer asks for the execution level (Vista and later) to be able to write shortcuts and registry keys.
admin
If you want a desktop entry for SWI-Prolog, right-drag swipl-win.exe to the desktop and select `Create
shortcut'. Then edit the properties and add to the command line to make the application start in . --
win_appMyDocuments\Prolog
The SWI-Prolog license allows it to be used in a wide variety of environments, including closed-source
commercial applications. In practice, redistribution and embedding is allowed, as long as modifications to the
SWI-Prolog source are published following the Free Software rules.
The SWI-Prolog kernel and foreign libraries are licensed under the Lesser General Public License (LGPL).
The Prolog files are licensed under the normal General Public License GPL with an additional statement that
allows for embedding in proprietary software:
As a special exception, if you link this library with other files compiled with a Free Software
compiler to produce an executable, this library does not by itself cause the resulting executable
to be covered by the GNU General Public License. This exception does not, however, invalidate
any other reasons why the executable file might be covered by the GNU General Public License.
This exception is a proven construct used for libgcc, the GNU C-compiler runtime library.
Sponsoring development has several benefits: (1) it solves your bottlenecks, (2) others help debugging
it, and (3) it strengthens SWI-Prolog's position, which gives you better guarantees that the system
remains actively developed and makes it easier to find resources and programmers.
Index
?
apropos/1
consult/1
edit/0
edit/1
1.4
gtrace/0
file:///C:/Program Files/swipl/doc/windows.html 7/8
22/04/2021 SWI-Prolog for MS-Windows
help/1
1.5
ls/0
make/0
1.3 1.4
pwd/0
1.5
qsave_program/2
2.1
trace/0