I'm trying to figure out how to use swi prolog. I'm not a computer programmer so please go easy on me and assume I know very little.
Well, the app works without xquartz. I'm downloading xquartz right now just in case.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.
2 Installation
XQuartz should be installed prior to SWI-Prolog installation. The installer can be downloaded from the XQuartz web site.
Clear.2.1 Using MacPorts
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.
Not clear.The swi-prolog port depends on readline, ncurses, ncursesw, gmp libmcrypt, zlib, expat, and jpeg.
Clear.2.2 From the installer
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.
Don't understand.3 Running SWI-Prolog
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
% sudo port -v selfupdate # make sure we have the latest portfiles % sudo port install swi-prolog
what file? what lines?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).
Where do I type %swipl?Now start X11.App and configure it to autostart at login. Open Terminal.app or xterm and type
% swipl
Huh?If X11 is properly configured, the help system of the graphics subsystem XPCE can now be started using the command below.
3.1 Loading a program
Prolog source files can be loaded by specifying their filename between [].
Don't understand/In addition to a plain filename, files may be searched
on a named search-path1 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 (.).
Well, I'll try to understand that part when I get the software to work.3.2 Executing a query
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.
# 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
% swipl Welcome to SWI-Prolog (Multi-threaded, Version 5.6.0) Copyright (c) 1990-2006 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 ?-