Table of Contents

Basic operation

Prolog is about running a query against a program. The query goes into the bottom-left editor and the program into the left editor. The program can be empty, executing queries against the built-in predicates of Prolog. For example:

?- format("Hello world!~n").

A query can be executed by hitting RETURN if the query is complete and the caret is behind the '.' that terminates the query or by using the Run! button. At this moment, the following happens:

  1. The interface creates a runner in the top-right window that controls the execution of the query.
  2. The runner collects the text from the top-left editor (if any) and the query and sends this to the server, which creates a Pengine (Prolog Engine).
  3. The Pengine compiles the program into a temporary private module.
  4. The Pengine assesses whether executing the query can compromise the query. If this fails, an error is displated. See the help topic Caveats ... for details.
  5. If the query is considered safe, it executes the query and communicates with the runner about the results using JSON messages. The runner interaction is described in the help topic Runner ...

Note that you do not have to save your program to execute it. If your are not satisfied with the answer to a query, you can simply edit the program and use the Run! again. The new query is executed in a completely new environment. In particular, data that you asserted in a previous query is not available in the next.

Embedding examples in the program text

If you include example goals inside comments as shown below, they will be used to populate the example menu and make the first goal show in the Goal input field.

/** <examples>

?- loves(X, mia).
?- jealous(X, Y).

*/

Save or share your program

If you use File/Save, the server will save your program in a file with a unique random name and add this name to the URL displayed in the browser's address bar. You can later come back to this source by going to this URL. You can also sent the URL to a friend and let him or her have a look at your program. Anyone can save the program, but the last one wins. In the future, we will add versioning.

Using File/Collaborate ..., you create a TogetherJS session that provides shared editing, chat and voice communication.

Preload SWISH with data

You can make SWISH start with a loaded program using the URL http://swish.swi-prolog.org/ and providing the parameters below. The URL accepts both `GET` and `POST` requests.

code
Either the concrete code or a URL from which the code will be downloaded.
background
As code, but this part of the code will not be visible in the editor.
examples
As the above described examples comment block.
q
The initial query to load into the query window. Note that the following characters need to be escaped: '#', '&' and the space.

The URL below opens SWISH on a file from GitHub with a default query.

http://swish.swi-prolog.org/?code=https://github.com/SWI-Prolog/swipl-devel/raw/master/demo/likes.pl&q=likes(sam,Food).