PDA

View Full Version : Can't understand how to get this app to work




kylefoley76
Jul 18, 2013, 12:35 AM
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.


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.

Well, the app works without xquartz. I'm downloading xquartz right now just in case.


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.

Clear.


The swi-prolog port depends on readline, ncurses, ncursesw, gmp libmcrypt, zlib, expat, and jpeg.

Not 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.

Clear.


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

Don't understand.


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).

what file? what lines?


Now start X11.App and configure it to autostart at login. Open Terminal.app or xterm and type
% swipl

Where do I type %swipl?


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 [].

Huh?


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 (.).

Don't understand/


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 ?-

Well, I'll try to understand that part when I get the software to work.



ArtOfWarfare
Jul 18, 2013, 05:32 AM
I'll try to answer as many of your questions as I can, but these strike me more as Unix administration questions than programming questions.

The swi-prolog port depends on readline, ncurses, ncursesw, gmp libmcrypt, zlib, expat, and jpeg.
I recognize some of these as unix commands. There should be executable files with these names somewhere on your computer with the names. Note that they'll be in directories that Apple has hidden from the Finder by default.

I'm pretty sure you needn't worry about it, though, as MacPorts should automatically handle downloading and installing any files that you need but don't have.

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

Open terminal and type in (after the prompt)
sudo port -v selfupdate
Then press enter. It should update MacPort just for incase you don't have the newest version. It'll give you a prompt again when it's done at which point you should type
sudo port install swi-prolog
Then press enter.

One other thing - if you have a password set on the computer, it'll ask you for that after each time you type a command involving "sudo". It won't show you stars or anything when you type it. It'll just ask for your password and you should type it and then hit enter and it'll proceed with executing that command.

The stuff after the # and before the % is a comment, which does nothing and so is why I didn't have you type that. And the %s themselves represent your prompt (or at least that's my guess.)

~/.bashrc

~/ refers to your home folder - the one that shares the name with your account name.

The . at the start of the file name means it'll be hidden from Finder, if it exists, unless you have modified some hidden preference files to reveal hidden files in Finder.

I'd suggest editing the file in a text editor like sublime. Text edit will also work. Word will not - it's a word processor, not a text editor.

Where do I type %swipl?
It's not clear from what you typed in your post (I'm not looking at the source you're quoting from) - but I'm guessing they want you to have the line

swipl inside a file named .bashrc and placed inside of your home folder. If the file already existed, add this line to it. If the file doesn't already exist and you had to make a new one, it'll have just this line in it.

Let's worry about the rest when you get to it...