The following abstracts are meant to describe the functionality of each package, not to serve as documentation. Whatever documentation exists is included in comments within each package. Refer to lib-bas-dlp-acc to find out how to locate the source files if you wish to read the code comments. All the files abstracted in the following pages are found in the library directory.
library(aggregate)
aggregate/3
, an operation
similar to bagof/3
, which lets you calculate sums. For example,
given a table pupil(Name, Class, Age)
, to calculate the average
age of the pupils in each class, one would write
| ?- aggregate( sum(Age)/sum(1), Name^pupil(Class, Name, Age), Expr), call(Average_Age is Expr).
library(antiunify)
The code here is based on a routine called generalise/5
written by
Fernando Pereira. The name was changed because there are other ways
of generalizing things, but there is only one dual of unification.
anti_unify(
+Term1,
+Term2,
-Term)
anti_unify(
+Term1,
+Term2,
-Subst1,
-Subst2,
-Term)
Subst1(Term) = Term1 Subst2(Term) = Term2
Substitutions are represented as lists of Var=Term pairs, where
Var is a Prolog variable, and Term is the term to substitute for Var.
When you call anti_unify/5
, Subst1, Subst2, and Term should be variables.
library(arity)
arity2quintus
.
library(aritystring)
library(aropen)
ar(1)
) without having to
extract the member. You cannot compile or consult such a file,
but you can read from it. This may be useful as an example of
defining Prolog streams from C.
Not available under Windows.
library(arrays)
library(logarr)
or library(trees)
.
library(assoc)
library(avl)
library(bags)
library(benchmark)
library(between)
library(big_text)
big_text.txt
in
the library area for more details.
library(bitsets)
library(ordsets)
.
library(break)
break/0
in QPC.
library(call)
library(caseconv)
library(ctypes)
. Here you'll find
predicates to test whether text is in all lowercase, all
uppercase, or mixed-case, and to convert from one case to
another.
library(charsio)
library(charsio)
:
chars_to_stream
.
with_input_from_chars/[2,3]
do this.
with_output_to_chars/[2,3]
predicates do this.
library(clump)
library(count)
compile/1
, use count/1
. The program will do
what it always used to, except that it may run twice as slowly. The
output of library(count)
is a file that contains a record of predicate
calls, and is suitable for processing by awk(1)
or similar
utilities.
library(critical)
library(crypt)
open/3
:
crypt_open(
+FileName[,
+Password, +Mode, -Stream)]
If you do not supply a Password, crypt_open/3
will prompt
you for it. Note that the password will be echoed. If
there is demand, this can be changed. The Stream will
be clear text as far as Prolog is concerned, yet
encrypted as far as the file system is concerned.
encrypt.c
is a stand-alone program (which is designed to
have its object code linked to three names: encrypt
,
decrypt
, and recrypt
), and can be used to read and write
files using this encryption method.
This encryption method was designed, and the code was
published, in Edinburgh, so it is available outside the USA.
library(decons)
prolog_clause(
Clause,
Head,
Body)
.
library(demo)
demo
file_search_path
.
library(det)
library(environ)
environ(
?Varname,
?Value)
is a genuine relation. Note
that if you include this file in a saved state, the values of
environment variables are those current when the saved state was run,
not when it was saved. There is also an argv/1
in this file, which is superseded by unix(argv(_))
.
library(environment)
library(expansion)
term_expansion/2
and provides more powerful hooks
that enable multiple, "simultaneously active" and recursive program
transformations to be achieved in an effcient manner.
library(fft)
library(vectors)
to call a Fortran subroutine.
library(filename)
filename.txt
.
library(flatten)
library(foreach)
forall(Generator, Test) foreach(Generator, Test)
forall/2
is the standard double-negation "there is no proof of
Generator for which Test is not provable", coded as
\+ (
Generator, \+
Test)
.
foreach/2
works in three phases: first each provable instance of
Generator is found, then each corresponding instance
of Test is collected in a conjunction, and finally
the conjunction is executed.
If, by the time a Test is called, it is always ground
-- apart from explicitly existentially quantified variables --
the two forms of iteration are equivalent, and forall/2
is
cheaper. But if you want Test to bind some variables,
you must use foreach/2
.
library(freevars)
library(fromonto)
| ?- (repeat, read(X), process(X)) from_file 'fred.dat'. | ?- read(X) from_chars "example. ". X = example | ?- write(273.4000) onto_chars X. X = "273.4"
library(gauss)
library(getfile)
get_file(
+FileName,
-ListOfLines)
, which reads an
entire file into memory in one go.
library(graphs)
The P-representation of a graph is a list of (from-to) vertex pairs, where the pairs can be in an arbitrary order. This form is convenient for input and output.
The S-representation of a graph is a list of (vertex-neighbors)
pairs, where the pairs are in standard order (as produced by
keysort/2
) and the neighbors of each vertex are also in standard
order (as produced by sort/2
). This form is convenient for many
calculations.
See also library(mst)
(lib-abs),
which is soon to be merged into library(graphs)
.
library(heaps)
library(knuth_b_1)
library(listparts)
library(lpa)
quintus.mac
, quintus.dec
.
library(logarr)
library(trees)
.
library(long)
rational(
N)
recognizes arbitrary-precision rational numbers:
this includes integers, infinity
, neginfinity
, & undefined
.
whole(
N)
recognizes arbitrary precision integers.
eval(
Expr,
Result)
evaluates an expression using arbitrary
precision rational arithmetic; it does not accept floats at all.
{eq,ge,gt,le,lt,ne}/2
are infix predicates like </2
that compare
rationals (or integers, not expressions).
succ/2
, plus/3
, and times/3
are relational forms of arithmetic,
which work on rational numbers (not floats).
To have rational numbers printed nicely, put the command
:- assert((portray(X) :- portray_number(X)))
in your code. See long.doc
and the comments in long.pl
.
library(mapand)
maplist.pl
.
library(maplist)
library(call)
, and provides
a collection of meta-predicates for applying predicates to elements of lists.
library(maps)
library(menu)
illustrates how to drive the Emacs interface from
Prolog. The sample application involves choosing items from a menu.
See also the menu_example.pl
program in the demo directory.
Not available under Windows.
library(mst)
library(graphs)
.
library(mst)
currently provides two predicates:
first_mst(
+Nodes,
+Cost,
-Root,
-MST)
mst(
+Nodes,
+Cost,
-Root,
-MST)
library(call)
, call(
Cost,
X,
Y,
Dist)
calculates
the distance Dist between nodes X and Y.
Please note:
mst/4
has been carefully written so that it will find all the minimal spanning trees of a graph.mst/4
finds many trees, especially as it is blind to redundant representations of isomorphic trees. If you will be satisfied with any MST at all, usefirst_mst/4
instead.first_mst/4
will try to keep the arcs in the same order as the nodes if at all possible.
library(multil)
library(newqueues)
library(newqueues)
package replaces library(queues)
, and should be
used in new programs.
library(nlist)
nlist(3)
.
Not available under Windows.
library(note)
fred(a, b)
and fred(97, 46)
are regarded as the same key.
library(note)
defines a complete set of storing, fetching, and
deleting commands where the "key" is a ground term all of
which is significant, using the existing recorded database.
Note that this package is no better indexed than the existing
recorded database.
library(order)
compare/3
violates this. This package provides an
additional interface to provide comparison predicates with the usual order.
The package contains predicates to compare numbers, terms, sets and ordered
lists.
library(ordered)
library(ordsets)
(lib-lis-ordsets), library(ordprefix)
below, and library(samsort)
(lib-abs).
library(ordprefix)
library(ordered)
above.
quintus.mac
lpa.pl
to be used on Mac.
quintus.dec
lpa.pl
to be used on DEC.
library(pipe)
library(pipe)
, which
provides a single predicate:
popen(
+Command,
+Mode,
-Stream)
read
user_input -> Command -> Stream
write
Stream -> Command -> user_output
The behavior of popen/3
is defined by the system function popen(3S)
.
There is no special
pclose/1
command: the existing close/1
will call
pclose(3S)
. Commands are executed by sh(1)
under UNIX
and by the default command interpreter under Windows,
e.g. cmd.exe
under Windows XP. Under Windows, the underlying
popen()
C library function, and therefore also popen/3
,
only works in console applications, e.g. in prolog
but not
in qpwin
.
library(plot)
plot(5)
files.
library(pptree)
<tree> --> <node label>/[<son>,...<son>] | <leaf label> -- anything else
Two forms of output are provided: a human-readable form and a Prolog term form for reading back into Prolog.
pp_tree(
+Tree)
pp_term(
+Tree)
There is a new command ps_tree/1
, which prints trees
represented in the form
<tree> --> <node label>(<son>,...,<son>) | <leaf> -- constants
The output of ps_tree/1
is readable by Prolog and people both.
You may find it useful for things other than parse trees.
library(printchars)
portray/1
(using library(addportray)
) so
that lists of character codes are written by print/1
, by the top
level, and by the debugger, between double quotes.
| ?- X = "fred". X = [102,114,101,100] | ?- use_module(library(printchars)), X = "fred". X = "fred"
library(printlength)
library(putfile)
library(qerrno)
library(qsort)
library(samsort)
below.
library(queues)
library(newqueues)
. It is retained for backward compatibility, but
should not be used in new programs.
library(random)
library(ranstk)
library(read)
P(X,Y,Z)
is read as call(P,X,Y,Z)
. Alan Mycroft reorganized the code
to regularize the functor modes. This is easier to understand (there
are no more ?
s), and it also fixes bugs concerning the curious
interaction of cut with the state of parameter instantiation. O'Keefe
then took it over again and made a number of other changes.
There are three intentional differences between this library and the Dec-10 Prolog parser:
call/N
.
portable_read/1
with an uninstantiated argument,
failure means a syntax error. You can rely on it.
, ..
is not accepted in place of |
. This was always a
parser feature, not a tokeniser feature: any amount of
layout and commentary was allowed between the ,
and the
..
. It wouldn't be hard to allow this again.
library(retract)
retract/1
will backtrack
through a predicate, expunging each matching clause until the caller
is satisfied. This is not a bug. That is the way retract/1
is supposed to work. But it is also useful to have a version that
does not backtrack.
library(retract)
defines, among many other commands,
retract_first/1
, which is identical to retract/1
except that it
expunges only the first matching clause, and fails if asked for another
solution.
library(samsort)
samsort(
Raw,
Sorted)
is like sort(
Raw,
Sorted)
except that it does not discard
duplicate elements. samsort(
Order,
Raw,
Sorted)
lets you specify
your own comparison predicate, which the built-in sorting predicates
sort/2
and keysort/2
do not. This file also exports
two predicates for merging already-sorted lists: merge/3
and merge/4
.
See also library(ordered)
and library(qsort)
.
library(setof)
setof/3
.
Note that the built-in predicates bagof/3
and setof/3
are much more efficient than the
predicates in this file. See also library(findall)
.
library(show)
listing/1
displays dynamic predicates.
But there is no built-in command for displaying the terms recorded under
a given key. library(show)
defines two predicates: show(
Key)
displays
all the terms recorded under the given Key, and show/0
displays all
the Keys and terms in the recorded database.
library(showmodule)
show_module(
Module)
prints a
description of the Module, what it exports, and what it imports.
The command
| ?- show_module(_), fail ; true.
will print a description of every loaded module. To backtrack through all current modules and print information about the predicates they define, import, and export, use
| ?- ensure_loaded(library(showmodule)), show_module(Module).
To print information about a particular module m, use
| ?- show_module(m).
library(statistics)
full_statistics/[0,2]
predicates are exactly like the built-in
statistics/[0,2]
predicates except that
library(stchk)
<usual heading> :- push_style. :- set_style(StyleFlag, Value). ... <clauses> :- pop_style.
Some combination of this with the existing style check interface will be safe: no matter what style check changes are made, the original values will be restored.
The initial state (assumed) is that all checks are ON.
library(terms)
library(terms)
lets you pass copies of terms
from Prolog to C, and receive copies of terms from C. For example, the
new built-in predicate copy_term/2
could have been defined this
way:
'copy term'(Term, Copy) :- prolog_to_c(Term, Pointer_to_C_version), c_to_prolog(Pointer_to_C_version, Temp), erase_c_term(Pointer_to_C_version), Copy = Temp.
The C code in terms.c
is just as much a part of this package as the
Prolog code. In particular, the comments in that file describe the
representation used on the C side of the interface and there are
routines and macros (see terms.h
) for accessing terms-in-C.
library(termdepth)
library(termdepth)
provides predicates that find the depth, length and size
of a term, which can even be used on cyclic terms.
library(tokens)
%(
is not accepted as an alternative to {
%)
is not accepted as an alternative to }
,..
is not accepted as an alternative to |
xwd(
Top18Bits,
Bottom18Bits)
(
is read as (
rather than (
. This does the
parser no harm at all, and the Dec-10 tokeniser guarantees never to
return (
except immediately after an atom, yielding (
everywhere
else.
BEWARE: this file does not recognize floating-point numbers.
library(trees)
library(types)
must_be_compound/3
, must_be_proper_list/3
,
must_be_var/3
, and
proper_list/1
are new in this release.
library(update)
library(vectors)
library(vectors)
provides routines
you can use to pass one-dimensional numeric arrays between
Prolog and C, Pascal, or FORTRAN.
See the comments in the code. Briefly,
list_to_vector(
+ListOfNumbers,
+Type,
-Vector)
+address(
Type)
.
FORTRAN will declare the argument as an array of Type.
make_vector(
+Size,
+Type,
-Vector)
+address(
Type)
.
FORTRAN will declare the argument as an array of Type.
vector_to_list(
+Vector,
?List)
kill_vector(
+Vector)
vector_to_list/2
on a dead vector, until the next time
memory is allocated. All that you can really rely on is
that it is safe to create some vectors, call a C routine,
kill all the vectors, and then extract the contents of
the interesting ones before doing anything else.
library(writetokens)
write.pl
, except that
instead of writing characters to the current output stream, it returns
a list of tokens. There are three kinds of tokens: punctuation marks,
constants, and atoms. There is nothing to indicate spacing; the point
of this package is to let the caller do such formatting.
library(xml)