SWI-Prolog is by origin an Unix application, and not a native Macintosh application. It has been brought to the Mac using the MacPorts project, using XQuartz (Macintosh X11) for its graphical capabilities.
XQuartz should be installed prior to SWI-Prolog installation. The installer can be downloaded from the XQuartz web site.
Users of the MacPorts system can install the system just like any
port using the command below. In addition to the port named
swi-prolog
providing the stable version, there is a port
called
swi-prolog-devel
providing the development version.
% sudo port -v selfupdate # make sure we have the latest portfiles % sudo port install swi-prolog
The swi-prolog port depends on readline
, ncurses
,
ncursesw
, gmp
libmcrypt
, zlib
,
expat
, and jpeg
.
Opening and installing the meta installer installs the required ports
from the MacPorts system. The programs are installed in the directory
/opt/local/bin
. The main executable is named swipl
.
Not being a Macintosh Application, SWI-Prolog must be started from a
terminal window. This can either be an X11 xterm or
Terminal.app from Utilities. For comfortable usage it is
necessary to setup some environment variables. The procedure depends on
your shell of choice. On Tiger the default is bash. Add the
following lines to the file ~/.bashrc
(or create this file
if it does not yet exist).
# This allows using Prolog graphics if you use Terminal.app if [ -z "$DISPLAY" ]; then export DISPLAY=:0; fi # This sets up the path PATH=$PATH:/opt/local/bin
Now start X11.App and configure it to autostart at login. Open Terminal.app or xterm and type
% swipl Welcome to SWI-Prolog (threaded, 64 bits, version 7.3.33) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit http://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). ?-
If X11 is properly configured, the help system of the graphics subsystem XPCE can now be started using the command below.
?- manpce.
Prolog source files can be loaded by specifying their filename
between
[]
. In addition to a plain filename, files may be searched
on a named search-path1See file_search_path/2
in the manual for details. using the notation SearchPath(File)
.
Two defined paths are
library
for the Prolog library and swi
for the
Prolog installation directory. Below we load the file likes.pl
from the
demo
directory in the installation directory, Be sure to
get the quotes right and terminate the command with a full-stop (
).
.
?- [swi('demo/likes')].
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 X = <value>
if it can prove
the goal for a certain
X. The user can type the semi-colon (;)2On
most installations, single-character commands are executed without
waiting for the RETURN key.
if (s)he wants another solution, or RETURN
if (s)he is satisfied, after which Prolog will say Yes. If Prolog
answers No, it indicates it cannot find any (more) answers to the
query. Finally, Prolog can answer using an error message to indicate the
query or program contains an error.
?- likes(sam, X). X = dahl ; X = tandoori ; ... X = chips ; No ?-
There are three options for editing. One is to run an editor of
choice in a separate window and use the below described make/0
command to reload modified files. In addition to this option Prolog can
be used to locate predicates, modules and loaded files by specifying the
editor of choice for use with the edit/1
command described below. This is achieved by editing the personalisation
file /.swiplrc
. A commented template is in the directory dotfiles
of the SWI-Prolog installation directory.
Finally, you may wish to use the built-in editor called PceEmacs.
This editor provides colourisation support based on real-time parsing
and cross-reference analysis of the program. It is started using the
command ?- emacs.
or can be set as default editor in the
personalisation file.
This section provides a very brief overview of important or commonly used SWI-Prolog predicates to control the environment.
.pl
can be
omitted. Here are some examples:
?- consult(likes). | Load likes.pl
from the current folder (see pwd/0). |
?- ['/opt/local/lib/swipl-5.6.0/demo/likes'] | Load likes.pl
using absolute path. |
.pl
file in the explorer,
edit this file. Also available from the menu.?- trace, run.
and finally you can include it in
your program to start tracing at a particular point or under a
particular condition:
..., (var(X) -> trace ; true), ...,
To use SWI-Prolog with C or C++ code you must install Apples Xcode environment, providing gcc. If all paths are properly installed, programs can be linked using the plld command described in the manual.
The SWI-Prolog web-site is located at http://www.swi-prolog.org/. Part of the web is powered by TWiki, a wiki web that can be edited by any registered user and used to exchange ideas, problems and solutions. The web also provides access to the archive of the mailing list and allows to (de)register the mailing list. Finally, it incorporates Bugzilla, the Mozilla project bugtracking system, for reporting bugs and tracking issues.
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.
There are several ways to support SWI-Prolog: