Next: , Previous: , Up: Top   [Contents][Index]


10 The Prolog Library

The Prolog library comprises a number of packages that are thought to be useful in a number of applications. Note that the predicates in the Prolog library are not built-in predicates. One has to explicitly load each package to get access to its predicates.

As opposed to built-in predicates, predicates exported by library modules generally do not check their arguments, although some do to a lesser or greater extent. Input arguments that are lists are usually supposed to be proper lists, i.e., not end with an unbound variable. Input arguments that are trees are usually not supposed to have uninstantiated leaves, and so on.

To load a library package Package, you will normally enter a query:

| ?- use_module(library(Package)).

A library package normally consists of one or more hidden (see ref-mod) modules. There are packages for many different purposes, such as providing an abstract data type, database access, constraint solvers, I/O, interoperability with other software, file and operating system access, object-oriented programming, a unit-test framework, random numbers, and statistics.

Among the first category, several packages provide array-like functionality, because arrays are not part of the Prolog language. If you are about to choose an array representation, the following comparison of their key properties may be helpful. Prolog lists are included in the comparison. In the table, read cost is the cost of looking up an element given a key; update cost is the cost of replacing an element given a key, creating a new array-like term; sparse means that the set of keys does not have to be known up front:

representationread costupdate costsparse
Prolog listO(n)O(n)no
library(assoc)O(n)O(n)yes
library(avl)O(log n)O(log n)yes
library(logarr)O(log n)O(log n)yes
library(mutarray)O(1)O(1)no
library(trees)O(log n)O(log n)no

Please note: library(mutarray) updates run in O(1) time for all indices in the best case, and in O(n) time otherwise.

Following is the list of provided packages, in alphabetic order:

aggregate (see lib-aggregate)

provides an aggregation operator for data-base-style queries.

assoc (see lib-assoc)

uses unbalanced binary trees trees to implement dictionaries, i.e. extendible mappings from terms to terms. Can be used as sparse arrays with linear read and update cost.

atts (see lib-atts)

provides a means of associating with variables arbitrary attributes, i.e. named properties that can be used as storage locations as well as hooks into Prolog’s unification.

avl (see lib-avl)

uses AVL trees to implement dictionaries, i.e. extendible finite mappings from terms to terms. Can be used as sparse arrays with logarithmic read and update cost.

bags (see lib-bags)

defines operations on bags, or multisets

between (see lib-between)

provides some means of generating integers.

chr (see lib-chr)

provides Constraint Handling Rules

clpb (see lib-clpb)   since release 4.0.7,unsupported

provides constraint solving over Booleans

clpfd (see lib-clpfd)

provides constraint solving over Finite (Integer) Domains

clpq (see lib-clpqr)   unsupported
clpr (see lib-clpqr)   unsupported

provides constraint solving over Q (Rationals) or R (Reals)

codesio (see lib-codesio)

defines I/O predicates that read from, or write to, a code list.

csv (see lib-csv)

defines I/O predicates that read from, or write to, comma-separated values (CSV) files and strings.

comclient (see lib-comclient)

An interface to Microsoft COM automaton objects.

fdbg (see lib-fdbg)

provides a debugger for finite domain constraint programs

file_systems (see lib-file_systems)

accesses files and directories.

gauge (see lib-gauge)

A profiling tool for Prolog programs with a graphical interface based on tcltk.

heaps (see lib-heaps)

implements binary heaps, the main application of which are priority queues.

is_directives (see lib-is_directives)

Access information about predicates that have been declared with is/2 directives.

jasper (see lib-jasper)   since release 4.0.3

Access Prolog from Java.

json (see lib-json)   since release 4.5.0

defines I/O predicates that read and write using the JSON serialization format.

jsonrpc_server (see lib-jsonrpc)   since release 4.8.0

provides a way, using the standardized JSON-RPC protocol, for other programming languages to communicate with SICStus.

simple_jsonrpc_server (see lib-simple-jsonrpc)   since release 4.8.0

provides a simplified way to develop servers using the JSON-RPC library.

linda/client (see lib-linda)
linda/server (see lib-linda)

provides an implementation of the Linda concept for process communication.

lists (see lib-lists)

provides basic operations on lists.

lmdb (see lib-lmdb)

provides an interface to LMDB, for storage and retrieval of terms on disk files with user-defined multiple indexing.

logarr (see lib-logarr)

provides a binary tree implementation of dense arrays with logarithmic read and update cost.

mutarray (see lib-mutarray)   since release 4.7

provides an implementation of mutable, dense arrays with constant read cost and update cost for all indices in the best case.

mutdict (see lib-mutdict)   since release 4.7

provides an implementation of mutable, extendible dictionaries, i.e. mutable extendible finite mappings from terms to terms, with constant lookup and update cost for all keys in the best case.

objects (see lib-objects)

provides a package for object-oriented programming, and can be regarded as a high-level alternative to library(structs).

odbc (see lib-odbc)   since release 4.1

provides an interface to an ODBC database driver.

ordsets (see lib-ordsets)

defines operations on sets represented as lists with the elements ordered in Prolog standard order.

pillow (see lib-pillow)   unsupported

The PiLLoW Web Programming Library,

plunit (see lib-plunit)   since release 4.1.3

A Prolog unit-test framework.

process (see lib-process)

provides process creation primitives.

prologbeans (see lib-prologbeans)

Access Prolog from Java and .NET.

queues (see lib-queues)

defines operations on queues (FIFO stores of information).

random (see lib-random)

provides a random number generator.

rem (see lib-rem)

provides Rem’s algorithm for maintaining equivalence classes.

samsort (see lib-samsort)

provides generic stable sorting and merging.

sets (see lib-sets)

defines operations on sets represented as lists with the elements unordered.

sockets (see lib-sockets)

provides an interface to sockets.

statistics (see lib-statistics)   since release 4.3.4

provides commonly used sample and population statistics functions.

structs (see lib-structs)

provides access to C data structures, and can be regarded as a low-level alternative to library(objects).

system (see lib-system)

provides access to operating system services.

tcltk (see lib-tcltk)

An interface to the Tcl/Tk language and toolkit.

terms (see lib-terms)

provides a number of operations on terms.

timeout (see lib-timeout)

Meta-call with limit on execution time.

trees (see lib-trees)

provides a binary tree implementation of dense arrays with logarithmic read and update cost.

types (see lib-types)

Provides type checking.

ugraphs (see lib-ugraphs)

Provides an implementation of directed and undirected graphs with unlabeled edges.

varnumbers (see lib-varnumbers)

An inverse of numbervars/3.

wgraphs (see lib-wgraphs)

provides an implementation of directed and undirected graphs where each edge has an integral weight.

xml (see lib-xml)

provides an XML parser.

zinc (see lib-zinc)   since release 4.0.5

provides an interpreter for FlatZinc programs

For the purpose of migrating code from release 3, the following deprecated library modules are also provided. For documentation, please see the release 3 documentation for the corresponding library module with the trailing ‘3’ removed from its name:

arrays3
assoc3
lists3
queues3
random3
system3


Send feedback on this subject.