SWI-Prolog for MacOS X
|This document briefly explains the MacOS X specific issues for SWI-Prolog. This 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 SWI-Prolog website, which also provides links to books, online tutorials and other Prolog related material.|
SWI-Prolog is by origin an Unix application, and not a native Macintosh application. It has been brought to the Mac using the darwinports project, using (Macintosh) X11 for its graphical capabilities.
Users of the Darwinport 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
swi-prolog-devel providing the development version.
% sudo port -d selfupdate # make sure we have the latest portfiles % sudo port install swi-prolog
The swi-prolog port depends on
Opening and installing the meta installer installs the required ports
from the Darwinport system. The programs are installed in the directory
/opt/local/bin. The main executable is named
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 (Multi-threaded, Version 5.6.0) Copyright (c) 1990-2005 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details. For help, use ?- help(Topic). or ?- apropos(Word). 1 ?-
If X11 is properly configure, the help system of the graphics subsystem XPCE can now be started using the command below.
Prolog source files can be loaded by specifying their filename
. In addition to a plain filename, files may be searched
on a named search-path (1)
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
demo directory in the installation directory, Be sure to
get the quotes right and terminate the command with a full-stop (
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 (;) (2) 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
/.plrc. A commented template is in the directory
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
?- emacs. or can be set as default editor in the
This section provides a very brief overview of important or commonly used SWI-Prolog predicates to control the environment.
.plcan be omitted. Here are some examples:
|?- consult(likes).||Load |
|?- ['/opt/local/lib/swipl-5.6.0/demo/likes']||Load |
.plfile 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 mailinglist and allows to (de)register the mailinglist. 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: