ArticleslgStudy

computer science

SWI-Prolog

SWI-Prolog is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand SWI-Prolog rather than just read about it. In short: SWI-Prolog is a free implementation of the programming language Prolog, commonly used for teaching and semantic web applications. It has a rich set of features, libraries for constraint logic programming, multithreading, unit testing, GUI, interfacing to Java, ODBC and others, literate programming, a web server, SGML, RDF, RDFS, developer tools (including an IDE with a GUI debugger and GUI profiler), and extensive d…

Key takeaways

  • SWI-Prolog belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect SWI-Prolog to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of SWI-Prolog from memory before moving on to harder problems.

Reference excerpt

SWI-Prolog is a free implementation of the programming language Prolog, commonly used for teaching and semantic web applications. It has a rich set of features, libraries for constraint logic programming, multithreading, unit testing, GUI, interfacing to Java, ODBC and others, literate programming, a web server, SGML, RDF, RDFS, developer tools (including an IDE with a GUI debugger and GUI profiler), and extensive documentation. SWI-Prolog runs on Unix, Windows, Macintosh and Linux platforms. SWI-Prolog has been under continuous development since 1987. Its main author is Jan Wielemaker. The name SWI is derived from Sociaal-Wetenschappelijke Informatica ("Social Science Informatics"), the former name of the group at the University of Amsterdam, where Wielemaker was employed when he initiated the development of SWI-Prolog.

Execution model SWI-Prolog is not based on the Warren Abstract Machine execution model of Prolog. Instead, it is based on an extended version of the ZIP virtual machine, a minimal virtual machine for Prolog implementing a simple language consisting of only seven instructions. SWI-Prolog-specific extensions aim at improving performance in several ways: ad hoc instructions are introduced to support unification, predicate invocation, some frequently used built-in predicates, arithmetic, control flow, and negation as failure. Prolog can easily be compiled into this language, and the abstract machine code is easily decompiled back into Prolog. This feature is often exploited to interleave compiled and interpreted code execution.

Constraint logic programming Constraint logic programming functionality came rather late in the lifetime of SWI-Prolog, because it lacked the basic support. This changed early in 2004, when attributed variables were added to the language. The Leuven CHR library was then the first CLP library to be ported to SWI-Prolog. We mention SWI-Prolog's INCLP(R) library (De Koninck et al. 2006), which provides non-linear constraints over the reals and was implemented on top of CHR. Later came a port of Christian Holzbaur's CLP(QR) library and a finite-domain CLP(FD) solver. Finally, a boolean CLP(B) solver was added.

Extensions for SWI-Prolog SWI-Prolog installs with a web framework based on definite clause grammars. SWI-Prolog queries may be distributed over several servers and web pages through the Pengines system.

XPCE XPCE is a platform-independent object-oriented GUI toolkit for SWI-Prolog, Lisp and other interactive and dynamically typed languages. Although XPCE was designed to be language-independent, it has gained popularity mostly with Prolog. The development XPCE graphic toolkit started in 1987, together with SWI-Prolog. It supports buttons, menus, sliders, tabs and other basic GUI widgets. XPCE is available for all platforms supported by SWI-Prolog. PceEmacs is a SWI-Prolog builtin editor. PceEmacs is an Emacs clone implemented in Prolog (and XPCE). It supports proper indentation, syntax highlighting, full syntax checking by calling the SWI-Prolog parser, warning for singleton variables and finding predicate definitions based on the source information from the Prolog database.

Interfaces JPL is a bidirectional interface between Java and Prolog. It requires both SWI-Prolog and Java SDK. It is installed as a part of SWI-Prolog.

See also

Prolog Comparison of Prolog implementations Prolog syntax and semantics

References

External links Official website

Worked examples

Example 1 — a first encounter with SWI-Prolog

Start with the simplest possible case. Write down what SWI-Prolog claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to SWI-Prolog before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about SWI-Prolog ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of SWI-Prolog

In research
SWI-Prolog appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses SWI-Prolog in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
SWI-Prolog is common in secondary-school and first-year university syllabi. It links to neighbouring topics Constraint programming, Cross-platform free software, Free and open source compilers, so understanding it makes those chapters shorter.
In everyday life
Look for SWI-Prolog outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “SWI-Prolog” →

How to study SWI-Prolog in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what SWI-Prolog means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain SWI-Prolog out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is SWI-Prolog in simple terms?

SWI-Prolog is a free implementation of the programming language Prolog, commonly used for teaching and semantic web applications. It has a rich set of features, libraries for constraint logic programming, multithreading, unit testing, GUI, interfacing to Java, ODBC and others, literate programming…

Why does SWI-Prolog matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study SWI-Prolog?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on SWI-Prolog.

Tags

  • Constraint programming
  • Cross-platform free software
  • Free and open source compilers
  • Free software programmed in C
  • Free software programmed in Prolog
  • Integrated development environments
  • Prolog programming language family
  • Software using the BSD license
  • Software using the GNU Lesser General Public License

Keep exploring