当前位置: 首页 > 工具软件 > SWI-Prolog > 使用案例 >

Installing and running SWI Prolog(如何安装运行swi-prolog)

养俊驰
2023-12-01

prolog中一个比较常用的编译器swi-prolog,可以在ubuntu中方便安装

sudo apt-get install swi-prolog.  然后在terminal,   里面输入swipl即可,运行方式和gprolog相似。

其实英文网站并不少很难看懂,只有我们勇于尝试。

Installing and running SWI Prolog

SWI is a free interpreter for the logic programming language Prolog discussed in the lectures. In order to carry out the Prolog exercises, you will need to have SWI installed on your machine. This page outlines how to go about this.

Downloading and installing

Windows

A Windows installer can be found here for users of Windows NT/2000/XP/Vista (and presumably Windows 7), and here for users of Windows 95/98/ME.

Download, and run the installer when prompted.

Choose a "Typical" install.

You may get an error about insufficient privileges. If you are not logged into your machine as an administrator, log out and log in as an admin user. If you are already an administrator, ignore the message and carry on.

A Start Menu group for SWI Prolog will be added.

Mac OS X

An OS X installer can be found here for users of Leopard or later on Intel Macs, here for users of Leopard on Power PC Macs and here for users of Tiger on Power PC Macs.

Download and run the installer when prompted.

SWI Prolog is a UNIX application, and thus will need to be run from the terminal prompt. Instructions are below.

Linux

Most distributions of Linux include SWI Prolog. Search for "Prolog" in your system's package manager, and install all packages containing "swi" or whose descriptions mention "SWI Prolog". For example, on a Debian or Ubuntu system, search Synaptic or "Add/Remove software", or, at the shell prompt, type "apt-get install swi-prolog".

Running SWI

The standard file extension for Prolog is ".pl" on all platforms. You can create Prolog files using your system's basic text editor (e.g. Notepad on Windows, TextEdit on OS X and gedit on Linux).

Windows

Find "SWI Prolog" in the Start Menu, and run "Prolog".

Double-clicking on ".pl" files in Windows Explorer should start Prolog, and load the file you clicked.

Mac OS X and Linux

Open a terminal window (e.g. gnome-terminal or Applications/Utilities/Terminal). Navigate (using "cd") to the directory in which you plan to store your Cognitive Systems Prolog exercises. For example, if you create a folder in your home directory called "work", change to it in the terminal by typing

cd work

If you're being a bit more organised and using subfolders, for example {your home}/work/c4b/exercises, then you would type

cd work/c4b/exercises

(If this doesn't work, try just typing "cd", pressing return and then try again.)

On most Linux distributions, you will be able to start Prolog by typing "pl" or "swipl" at the prompt. On OS X, type "/opt/local/bin/swipl" at the prompt and press return.

Consulting a Prolog file

If you have written some Prolog and want to try it out, the interpreter needs to load the ".pl" file containing your code. This is known as "consulting" the file. On Windows this happens when you double-click it, and we recommend that you use this method on Microsoft platforms. On OS X and Linux, you can consult any file in the current directory by entering

[filename].

and pressing return, at the Prolog prompt. (The full stop at the end IS significant.)

You can then enter any Prolog queries against the predicates defined in the file you have consulted.

Quitting Prolog

Often omitted from guides to Prolog interpreters is the fact that to exit Prolog, you must type

halt.

and press return.

转载自:http://www.cossac.org/groups/oxford/teaching/cogsys/prolog/

 类似资料: