Manual: Topical List of Prolog Built-ins


Quintus Prolog Manual


(PREV) (NEXT)

L-2: Topical List of Prolog Built-ins

Following is a complete list of Quintus Prolog built-in predicates, arranged by topic. A predicate may be included in more than one list.

L-2-1: Arithmetic

L-2-2: Character I/O

L-2-3: Control

L-2-4: Database

L-2-5: Debugging

L-2-6: Executables and QOF-Saving

L-2-7: Execution State

L-2-8: File Name Manipulation

L-2-9: File and Stream Handling

L-2-10: Foreign Interface

L-2-11: Grammar Rules

L-2-12: Help

L-2-13: Hook Predicates

L-2-14: List Processing

L-2-15: Loading Programs

L-2-16: Memory

L-2-17: Messages

L-2-18: Modules

L-2-19: Program State

L-2-20: Term Comparison

L-2-21: Term Handling

L-2-22: Term I/O

L-2-23: Type Tests

L-3: Built-in Predicates

The following reference pages, alphabetically arranged, describe the Quintus Prolog built-in predicates.

For a functional grouping of these predicates including brief descriptions, see section L-2.

In many cases the heading of a reference page will contain not only the name and arity of the predicate, but also the name of a major category to which the predicate belongs. These categories are defined in section L-1-3.

Further information about categories of predicates and arguments, mode annotations, and the conventions observed in the reference pages is found in Chapter L-1.

L-3-1: !/0

Synopsis:
!
Cut.
Description:
When first encountered as a goal, cut succeeds immediately. If backtracking should later return to the cut, the parent goal will fail (the parent goal is the one which matched the head of the clause containing the cut).
See Also:
Chapter B-5-1

L-3-2: ;/2 - disjunction

Synopsis:
+*P ; +*Q
Disjunction: Succeeds if P succeeds or Q succeeds.
Arguments:
P
<callable> MOD
Q
<callable> MOD
Description:
See Also:
Chapter B-5-6 and Chapter G-2-3

L-3-3: ,/2

Synopsis:
+*P , +*Q
Conjunction: Succeeds if P succeeds and then Q succeeds.
Arguments:
P
<callable> MOD
Q
<callable> MOD
Description:
This is not normally regarded as a built-in predicate, since it is part of the syntax of the language. However, it is like a built-in predicate in that you can say call((P , Q)) to execute P and then Q.
See Also:
Chapter G-2-3

L-3-4: ;/2 - if-then-else

Synopsis:
+-P -> +*Q ; +*R
If P then Q else R, using first solution of P only.
Arguments:
P
<callable> MOD
Q
<callable> MOD
R
<callable> MOD
Description:
Backtracking:
If P succeeds and Q then fails, backtracking into P does not occur. P may not contain a cut. '->'/2 acts like a cut except that its range is restricted to within the disjunction: it cuts away R and any choice points within P. '->' may be thought of as a "local cut".
See Also:
Chapter B-5-6 and Chapter G-2-3

L-3-5: ->/2

Synopsis:
+-P -> +*Q
"Local cut"
If P then Q else fail, using first solution of P only.
Arguments:
P
<callable> MOD
Q
<callable> MOD
Description:
Exceptions:

L-3-6: =/2

Synopsis:
+-Term1 = +-Term2
unifies Term1 and Term2.
Arguments:
Term1
<term>
Term2
<term>
Description:

L-3-7: =../2

Synopsis:
+-Term =.. +-List
Unifies List with a list whose head is the atom corresponding to the principal functor of Term and whose tail is a list of the arguments of Term.
Arguments:
Term
<term> any term
List
<list> and not[]
Description:
Exceptions:
See Also:
functor/3, arg/3
Chapter G-9-2

L-3-8: </2, =:=/2, =</2, =\=/2, >/2, >=/2

Synopsis:
+Expr1 < +Expr2
Evaluates Expr1 and Expr2 as arithmetic expressions. The goal succeeds if the result of evaluating Expr1 is strictly less than the result of evaluating Expr2.
+Expr1 =:= +Expr2
Succeeds if the results of evaluating Expr1 and Expr2 are equal.
+Expr1 =< +Expr2
Succeeds if the result of evaluating Expr1 is less than or equal to the result of evaluating Expr2.
+Expr1 =\= +Expr2
Succeeds if the results of evaluating Expr1 and Expr2 are not equal.
+Expr1 > +Expr2
Succeeds if the result of evaluating Expr1 is strictly greater than the result of evaluating Expr2.
+Expr1 >= +Expr2
Succeeds if the result of evaluating Expr1 is greater than or equal to the result of evaluating Expr2.
Arguments:
Expr1
<expr> Arithmetic expression
Expr2
<expr> Arithmetic expression
Description:
All of these predicates evaluate Expr1 and Expr2 as arithmetic expressions and compare the results.
The possible values for Expr are spelled out in detail in section G-8-3.
Exceptions:
Examples:
| ?- 23 + 2.2 < 23 - 2.2. yes | ?- X = 31, Y = 25, X + Y < X - Y no | ?- 1.0 + 1.0 =:= 2. yes | ?- "a" =:= 97. yes | ?- 42 =< 42. yes | ?- "b" =< "a". no | ?- 7 =\= 14/2. no | ?- 7 =\= 15/2. yes | ?- "g" > "g". no | ?- 4*2 > 15/2. yes | ?- 42 >= 42. yes | ?- "b" >= "a". yes
Comments:
Note that the symbol '=<' is used here rather than '<=' which is used in some other languages. One way to remember this is that the inequality symbols in Prolog are the ones which cannot be thought of as looking like arrows. The '<' or '>' always points at the '='.
See Also:
Chapter G-8

L-3-9: \+ /1

Synopsis:
\+ +P
Fails if the goal P has a solution, and succeeds otherwise.
Arguments:
P
<callable> MOD
Description:
This is not real negation ("P is false"), which is not possible in Prolog, but negation-by-failure meaning "P is not provable". P may not contain a cut. The goal \+ P behaves exactly like

                  ( P -> fail ; true)

          
Exceptions:
Tip:
Remember that with prefix operators such as this one, it is necessary to be careful about spaces if the argument starts with a '('. For example:

                  | ?- \+ (P, Q).

          
is the '\+'/1 operator applied to the conjunction of P and Q, but

                  | ?- \+(P, Q).

          
would require a predicate '\+'/2 for its solution. The prefix operator can, however, be written as a functor of one argument; thus
                  | ?- \+((P,Q)).

          
is also correct.
See Also:
library(not) -- defines a safer form of negation as failure.

L-3-10: ==/2, \==/2

Synopsis:
+Term1 == +Term2
Succeeds if the terms currently instantiating Term1 and Term2 are literally identical (in particular, variables in equivalent positions in the two terms must be identical).
+Term1 \== +Term2
Succeeds if the terms currently instantiating Term1 and Term2 are not literally identical.
Arguments:
Term1
<term>
Term2
<term>
Description:
Query (A) fails because Term1 and Term2 are distinct uninstantiated variables. However, query (B) succeeds because the first goal unifies the two variables:
| ?- Term1 == Term2. (A) no
| ?- Term1 = Term2, Term1 == Term2. (B) yes
Query (C) succeeds because Term1 and Term2 are distinct uninstantiated variables. However, query (D) fails because the first goal unifies the two variables.
| ?- Term1 \== Term2. (C) yes
| ?- Term1 = Term2, Term1 \== Term2. (D) no
See also:
compare/3, @</2, @=</2, @>/2, @>=/2 Chapter G-9

L-3-11: @</2, @=</2, @>/2, @>=/2

Synopsis:
+Term1 @< +Term2
Succeeds if term Term1 is before term Term2 in the standard order.
+Term1 @=< +Term2
Succeeds if term Term1 is not after term Term2 in the standard order.
+Term1 @> +Term2
Succeeds if term Term1 is after term Term2 in the standard order.
+Term1 @>= +Term2
Succeeds if term Term1 is not before term Term2 in the standard order.
Arguments:
Term1
<term>
Term2
<term>
Description:
These predicates use a standard total order when comparing terms. The standard total order is:

variables @< database references @< numbers @< atoms
@< compound terms

          
For further details see section G-9-7-1.
Examples:
| ?- foo(1) @< foo(2). yes | ?- chicken @< egg. yes | ?- a @< "a". yes
| ?- liberty @=< pride. yes |?- 1 @=< 1.0. yes
| ?- fie(1,1) @> fie(1). yes
| ?- 1 @>= 1.0. no | ?- 1.0 @>= 1. yes
See Also:
compare/3, ==/2, \==/2 Chapter G-9

L-3-12: -->/2

Synopsis:
+Head-->+Body
A possible form for Head is Body. Used primarily in grammar rules.
Arguments:
Head
Prolog term, or list of terms
Body
Prolog term, or list of terms
The formal description of grammar heads and grammar bodies is spelled out in section G-1-7-2.
Description:
Exceptions:
Examples:
See examples in section G-16-3 and section G-16-4.
See Also:
expand_term/2, 'C'/3, term_expansion/2, phrase/[2,3] Chapter G-16

L-3-13: ^/2

Synopsis:
+X ^ +*P
Equivalent to "there exists an X such that P is true", thus X is normally an unbound variable. The use of the explicit existential quantifier outside setof/3 and bagof/3 is superfluous.
Arguments:
X
<term>
P
<callable> MOD
Description:
Exceptions:
As for call/1:
Examples:
See Also:
setof/3, bagof/3

L-3-14: abolish/[1,2]

Synopsis:
abolish(+PredSpecTree)
abolish(+Name, +Arity)
Removes procedures from the Prolog database.
Arguments:
PredSpecTree
<pred_spec_tree> A procedure specification in the form Name/Arity, or a list of such procedure specifications. MOD
Name
<atom> A string representing the name of a predicate. MOD
Arity
<arity> An integer giving the arity of the predicate.
Description:
Exceptions:
See Also:
dynamic/1, erase/1, retract/1, retractall/1.
Chapter G-14-2

L-3-15: abort/0

Synopsis:
abort
Abandons the current execution and returns to the beginning of the current break level.
Description:
Tip:
Does not close any files which you may have opened. When using see/1 and tell/1, (rather than open/3, set_input/1, and set_output/1), close files yourself to avoid strange behavior after your program is aborted and restarted.
See Also:
halt/[0,1], break/0, QP_toplevel(), QP_initialize(), runtime_entry/1
Chapter G-11-1

L-3-16: absolute_file_name/[2,3]

Synopsis:
absolute_file_name(+RelFileSpec, -AbsFileName)
absolute_file_name(+RelFileSpec, +Options, -AbsFileName)
absolute_file_name(+RelFileSpec, +Options, *AbsFileName)
Unifies AbsFileName with the the absolute file name that corresponds to the relative file specification RelFileSpec.
Arguments:
RelFileSpec
<file_spec> A valid file specification.
AbsFileName
<atom> The first absolute file name derived from RelFileSpec that satisfies the access modes given by Options.
Options
<list> A list of zero or more of the following:
ignore_underscores(Bool). Bool =
true
When constructing an absolute file name that matches the given access modes, two names are tried: First the absolute file name derived directly from RelFileSpec, and then the file name obtained by first deleting all underscores from RelFileSpec.
false
(default) Suppresses any deletion of underscores.
extensions(Ext)
Has no effect if RelFileSpec contains a file extension. Ext is an atom or a list of atoms, each atom representing an extension that should be tried when constructing the absolute file name. The extensions are tried in the order they appear in the list. Default value is Ext = [''], i.e. only the given RelFileSpec is tried, no extension is added. To specify extensions('') or extensions([]) is equal not to give any extensions option at all.
file_type(Type)
Has no effect if RelFileSpec contains a file extension. Picks an adequate extension for the operating system currently running, which means that programs using this option instead of extensions(Ext) will be more portable between operating systems. Type must be one of the following atoms:
text
implies extensions(['']).
RelFileSpec is a file without any extension. (Default)
prolog
implies extensions(['pl','']).
RelFileSpec is a Prolog source file, maybe with a .pl extension.
object
implies extensions(['o',''])
RelFileSpec is a foreign language object file, maybe with a .o extension.
executable
implies extensions(['so',''])
RelFileSpec is a foreign executable (shared object file), maybe with a .so extension.
qof
implies extensions(['qof','']).
RelFileSpec is a Prolog object code file, maybe with a .qof extension.
directory
implies extensions(['']).
RelFileSpec is a directory, not a regular file. Only when this option is present can absolute_file_name/3 access directories without raising an exception.
foreign
implies extensions(['o',''])
Same as object. Included for backward compatibility. Might be removed from future releases.
ignore_version(Bool)
This switch has no effect on systems where files don't have version numbers. Bool =
true
When looking for a file that obeys the specified access modes, the version numbers will be ignored. The returned absolute file name will not contain any version number. To find a file name which includes a proper version number, use absolute_file_name/3 with the returned file as input, and the option ignore_version(false). See description of access option.
false
(default) Version numbers are significant.
access(Mode)
Mode must be one of the following:
read
AbsFileName must be readable.
write
If AbsFileName exists, it must be writable. If it doesn't exist, it must be possible to create.
append
If AbsFileName exists, it must be writable. If it doesn't exist, it must be possible to create.
exist
The file represented by AbsFileName must exist.
none
(default) The file system is not accessed. The first absolute file name that is derived from RelFileSpec is returned. Note that if this option is specified, no existence exceptions can be raised.
list of access modes
A list of one or more of the above options. If AbsFile exists, it must obey every specified option in the list. This makes it possible to combine a read and write, or write and exist check, into one call to absolute_file_name/3.
NOTE: The following only applies to file systems with version numbered files. If the user explicitly has specified a version number, only that version is considered. If no version number is supplied, the version number of AbsFileName is determined by:
read
newest readable version.
write
the file exists, the newest version plus one. If the file doesn't exist, a system dependent "youngest" version number.
append
If the file exists, the newest version. If the file doesn't exist, a system dependent "youngest" version number.
exist
newest version.
none
A system dependent "youngest" version number. Note that this can be switched of with the ignore_version option.
list of modes
newest version.
file_errors(Val). Val =
error
(default) Raise an exception if a file derived from RelFileSpec has the wrong permissions, that is, can't be accessed at all, or doesn't satisfy the the access modes specified with the access option.
fail
Fail if a file derived from RelFileSpec has the wrong permissions. Normally an exception is raised, which might not always be a desirable behavior, since files that do obey the access options might be found later on in the search. When this option is given, the search space is guaranteed to be exhausted. Note that the effect of this option is the same as having the global flag nofileerrors set.
solutions(Val). Val =
first
(default) As soon as a file derived from RelFileSpec is found, commit to that file. Makes absolute_file_name/3 deterministic.
all
Return each file derived from RelFileSpec that is found. The files are returned through backtracking. This option is probably most useful in combination with the option file_errors(fail).
Description:
Description of each phase:
Exceptions:
Comments:
Examples:
To check whether the file 'my_text' exists in the current user directory, with one of the extensions 'text' or 'txt', and is both writable and readable:
absolute_file_name('~/my_text', [extensions(['text','txt']), access([read,write])], File).
To check if the Prolog file 'same_functor' exists in some library, and also check if it exists under the name 'samefunctor':

absolute_file_name(library(same_functor),
                   [file_type(prolog), access(exist),
                    ignore_underscores(true)],
                   File).

          
See Also:
file_search_path/2, library_directory/2 nofileerrors/0, fileerrors/0
library(files) library(directory)

L-3-17: add_advice/3

Synopsis:
add_advice(+Goal,+Port,+Action)
Associate an action with entry to a port of a procedure.
Arguments:
Goal
<callable> a term to be unified against a calling goal. MOD
Port
one of {call, exit, done, redo, fail}; an atom indicating the port at which to check advice.
Action
<callable> a goal to be called when advice is checked at the given port. MOD
Description:
Tips:
Using advice can streamline debugging of deep recursions and other situations where a given call is made correctly many times but eventually goes amiss. Use of the Prolog debugger's spypoints is inconvenient because of the many calls before the error. If, for instance, it is known that a certain bad datum is present in the particular call producing the error, it is possible to use advice to set a spypoint only when that datum is seen:
:- add_advice(recurse(X,Y), call, (bad_data(X), spy recurse/2)).
When advice checking is enabled, this piece of advice will take effect only if the first argument passed to recurse/2 is bad. When that is so, a spypoint will be placed on recurse/2 and execution will continue at the call port of recurse/2. Since advice is checked before debugger interaction at the port, the debugger will immediately stop. There is no need to interact with the debugger for all the calls that have valid data.
Advice can also provide a simple and flexible profiling tool by associating a counter with various ports of each "interesting" predicate. The advice associated with each port and predicate might map the name, arity, module and port to a counter value held in a dynamic table. When advice checking is on and an advised predicate port is reached, the advice action simply increments the counter. The counter table can then be inspected to determine the number of times each predicate-port combination was reached.
Advice can also be used to associate "pre-conditions" and "post-conditions" to predicates. "pre-conditions" can be associated with the "call" port of a predicate and "post-conditions" can be
associated with the "done" or "exit" port of a predicate. Checking for "pre" and "post" conditions will be done only when checking advice is turned on.
See Also:
remove_advice/3, current_advice/3, check_advice/[0,1], nocheck_advice/[0,1]
Chapter E-4

L-3-18: add_spypoint/1

Synopsis:
add_spypoint(+SpySpec)
sets a spypoint on the specified predicate or call.
Arguments:
SpySpec
<compound> a specification of an individual spypoint. Two forms of spyspec are allowed:
predicate(Pred)
A spypoint on any call to Pred. Pred must be a skeletal predicate specification, and may be module qualified.
call(Caller,Clausenum,Callee,Callnum)
A spypoint on the Callnum call to Callee in the body of the Clausenum clause of Caller. Callee and Caller must be skeletal predicate specifications. Callnum and Clausenum must be integers, and begin counting from 1. Note that Callnum specifies a lexical position, that is, the number of the occurrence of Callee counting from the beginning of the body of the clause, and ignoring any punctuation.
Description:
Exceptions:
See Also:
current_spypoint/1, remove_spypoint/1, spy/1, nospy/1, debugging/0,
Chapter E-1.

L-3-19: append/3

Synopsis:
append(+*List1, +*List2, +*List3)
True when all three arguments are lists, and the members of List3 are the members of List1 followed by the members of List2.
Arguments:
List1
<term> a list
List2
<term> a list
List3
<term> a list consisting of List1 followed by List2
Description:
Backtracking:
Suppose L is bound to a proper list (see section K-2-2). That is, it has the form [T1,...,Tn] for some n. In that instance, the following things apply:
  1. append(L, X, Y) has at most one solution, whatever X and Y are, and cannot backtrack at all.
  2. append(X, Y, L) has at most n+1 solutions, whatever X and Y are, and though it can backtrack over these it cannot run away without finding a solution.
  3. append(X, L, Y), however, can backtrack indefinitely if X and Y are variables.
Examples:
The following examples are perfectly ordinary uses of append/3:
See Also:
length/2 Chapter K-2 library(lists)

L-3-20: arg/3 meta-logical

Synopsis:
arg(+ArgNum, +Term, -Arg)
unifies Arg with the ArgNumth argument of term Term.
Arguments:
ArgNum
<integer> positive integer
Term
<nonvar> compound term
Arg
<term>
Description:
The arguments are numbered from 1 upwards.
Example:
| ?- arg(2, foo(a,b,c), X). X = b
See Also:
functor/3, =../2
Chapter G-9-2; Chapter K-3-3

L-3-21: assert/[1,2]

Synopsis:
These predicates add a dynamic clause, Clause, to the Prolog data base. They optionally return a database reference in Ref:
assert(+Clause)
assert(+Clause, -Ref)
Undefined whether Clause will precede or follow the clauses already in the data base.
asserta(+Clause)
asserta(+Clause, -Ref)
Clause will precede all existing clauses in the data base.
assertz(+Clause)
assertz(+Clause, -Ref)
Clause will follow all existing clauses in the data base.
Arguments:
Clause
<callable> A valid dynamic Prolog clause. MOD
Ref
<db_reference> a database reference which uniquely identifies the newly asserted Clause.
Description:
Exceptions:
See Also:
abolish/[1,2], dynamic/1, erase/1, multifile_assertz/1 retract/1, retractall/1, clause/[2,3].
section G-14-2

L-3-22: assign/2

Synopsis:
assign(+LHS, +Expr)
Evaluates Expr as an arithmetic expression, and stores the value in the memory location and format given by LHS.
Arguments:
LHS
<compound> One of the following terms

integer_8_at(L_Exp)        integer_16_at(L_Exp)
unsigned_8_at(L_Exp)     unsigned_16_at(L_Exp)
integer_at(L_Exp)        address_at(L_Exp)
single_at(L_Exp)         double_at(L_Exp)
L_Exp     <expr>   a valid arithmetic expression

               
Expr
<expr> A valid arithmetic expression
Description:
Exceptions:
Examples:
IN THE C CODE:

static int counter;
int * init_counter()
{
        counter = 0;
        return &counter;
}


          
IN THE PROLOG CODE:

foreign(init_counter, c, init_counter([-address])).

get_counter(Counter, Count) :-
        Count is integer_at(Counter).

incr_counter(Counter) :-
        assign(integer_at(Counter),
        integer_at(Counter)+1).

| ?- init_counter(C), incr_counter(C),
        get_counter(C, Count1),
     incr_counter(C), incr_counter(C),
        get_counter(C, Count2).

C = 1418304,
Count1 = 1,
Count2 = 3

| ?-


          
See Also:
section G-8-3 library(structs)

L-3-23: at_end_of_file/[0,1]

Synopsis:
at_end_of_file
at_end_of_file(+Stream)
Tests whether end of file has been reached for the current input stream or for the input stream Stream.
Arguments:
Stream
<stream_object> a valid Prolog input stream
Description:
at_end_of_file/[0,1] checks if end of file has been reached for the specified input stream. An input stream reaches end of file when all characters except the file border code (-1 by default) of the stream have been read. It remains at end of file after the file border code has been read.
Exceptions:
Stream errors (see section G-7-6-2), plus:
Comments:
See Also:
at_end_of_line/[0,1].

L-3-24: at_end_of_line/[0,1]

Synopsis:
at_end_of_line
at_end_of_line(+Stream)
Test whether end of line (record) has been reached for the current input stream or for the input stream Stream.
Arguments:
Stream
<stream_object> a valid Prolog input stream
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
Comments:
See Also:
at_end_of_file/[0,1], skip_line/[0,1], get0/[1,2], set_input/1

L-3-25: atom/1 meta-logical

Synopsis:
atom(+Term)
Term term is currently instantiated to an atom.
Arguments:
Term
<term>
Examples:
| ?- atom(pastor). yes | ?- atom(Term). no | ?- atom(1). no | ?- atom('Time'). yes
See Also:
atomic/1, number/1, var/1, compound/1, callable/1, nonvar/1 simple/1
section G-1-1-3

L-3-26: atom_chars/2

Synopsis:
atom_chars(+Atom, -Chars)
atom_chars(-Atom, +Chars)
Chars is the list of ASCII character codes comprising the printed representation of Atom.
Arguments:
Chars
<list of char> the list of ASCII character codes comprising the printed representation of Atom.
Atom
<atom> will be instantiated to an atom containing exactly those characters, even if the characters look like the printed representation of a number.
Description:
Comment:
If you deal with chars values often, you may find it useful to load library(printchars). Once this is done, a list of character codes will be written by print/1 as double-quoted text.
Exceptions:
See Also:
print/1, library(printchars)

L-3-27: atomic/1

Synopsis:
atomic(+Term)
Succeeds if Term is currently instantiated to either an atom number or a db_reference.
Arguments:
Term
<term>
Example:
| ?- atomic(9). yes | ?- atomic(a). yes | ?- atomic("a"). no | ?- assert(foo(1), Ref), atomic(Ref). Ref = '$ref'(1195912,1)
See Also:
atom/1, number/1, var/1, compound/1, callable/1, nonvar/1 simple/1

L-3-28: bagof/3

Synopsis:
bagof(+Template, +*Generator, *Set)
Like setof/3 except that the list (or alternative lists) returned will not be ordered, and may contain duplicates. This relaxation saves time and space in execution.
Arguments:
Template
<term>
Generator
<callable> a goal to be proved as if by call/1. MOD
Set
<list of term> non-empty set
Examples:
See findall/3 for examples that illustrate the differences among findall/3, setof/3, and bagof/3.
Exceptions:
As for call/1:
See Also:
findall/3, setof/3, ^/2
Chapter G-15

L-3-29: break/0

Synopsis:
break
causes the current execution to be interrupted; enters next break level.
Description:
See Also:
abort/0, halt/[0,1], QP_toplevel()

L-3-30: 'C'/3

Synopsis:
'C'(+-List1, +-Terminal, +-List2)
In a grammar rule: Terminal connectsList1 and List2. It is defined by the clause 'C'([T|S], T, S).
Arguments:
List1
<term>
List2
<term>
Terminal
<term>
Description:
Analyzes List1 into head and tail, and creates the tail, List2.
'C'/3 is not normally of direct use to the user. If its arguments are not of the expected form, it simply fails.
Examples:
| ?- 'C'([the, slithy, toves, did, grob], Head, Tail). Head = the, Tail = [slithy,toves,did,grob] ; no
See examples in section G-16-4.
See Also:
Chapter G-16

L-3-31: call/1

Synopsis:
call(+*P)
Proves(executes) P.
Arguments:
P
<callable> MOD
Description:
Exceptions:

L-3-32: callable/1

Synopsis:
callable(+Term)
Term is currently instantiated to a term that call/1 would take as an argument and not give a type error (an atom or a compound term).
Arguments:
Term
<term>
Examples:
| ?- callable(a). yes | ?- callable(a(1,2,3)). yes | ?- callable([1,2,3]). yes | ?- callable(1.1). no
See Also:
atom/1, atomic/1, number/1, var/1, compound/1, nonvar/1, simple/1

L-3-33: character_count/2

Synopsis:
character_count(+Stream, -Count)
Obtains the total number of characters either input from or output to the open stream Stream and unifies it with Count.
Arguments:
Stream
<stream_object> a valid open Prolog stream
Count
<integer> the resulting character count of the stream
Description:
A freshly opened stream has a character count of 0. When a character is input from or output to a non-tty Prolog stream, the character count of the Prolog stream is increased by one. Character count for a tty stream reflects the total character input from or output to the tty since the tty is opened to any stream. See section G-7-7-1, for details on the use of this predicate on a stream which is directed to the user's terminal.
A nl/[0,1] operation also increases the character count of a stream by one unless the line border code (end_of_line option in open/4) is less than 0.
Exceptions:
Stream errors (see section G-7-6-2).
See Also:
line_count/2, line_position/2, stream_position/[2,3]. Chapter G-7

L-3-34: check_advice/[0,1]

Synopsis:
check_advice
check_advice(+PredSpecs)
Enable advice checking.
Arguments:
PredSpecs
<gen_pred_spec_tree> A list of predicate specifications. MOD
Description:
Tips:
check_advice/0 behaves as though implemented by
check_advice :- current_advice(Goal, Port, Action), functor(Goal, Name, Arity), check_advice(Name/Arity), fail. check_advice.
See Also:
add_advice/3, remove_advice/3, current_advice/3, nocheck_advice/[0,1]
Chapter E-4

L-3-35: clause/[2,3]

Synopsis:
clause(+*Head, *Body)
clause(-Head, -Body, +Ref)
clause(+*Head, *Body, *Ref)
Searches the data base for a clause whose head matches Head and whose body matches Body.
Arguments:
Head
<callable> a term whose functor names a dynamic procedure. MOD
Body
<callable> compound term or true
Ref
<db_reference> a database reference
Description:
Backtracking:
Can be used to backtrack through all the clauses matching a given Head and Body. It fails when there are no (or no further) matching clauses in the database.
Exceptions:
Comments:
See Also:
instance/2, assert/[1,2], dynamic/1, retract/1
Chapter G-14-2

L-3-36: close/1

Synopsis:
close(+Stream)
closes the stream corresponding to Stream.
Arguments:
Stream
<stream_object> stream or file specification
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
Examples:
See Also:
see/1, tell/1, open/[3,4], write_canonical/[1,2]

L-3-37: compare/3

Synopsis:
compare(-Order, +Term1, +Term2)
succeeds if the result of comparing terms Term1 and Term2 is Order
Arguments:
Order
one of {=, <, >} '=' if Term1 is identical to Term2, '<' if Term1 is before Term2 in the standard order, '>' if Term1 is after Term2 in the standard order.
Term1
<term>
Term2
<term>
Description:
See Also:
@</2, @=</2, @>/2, @>=/2, QP_compare() Chapter G-9

L-3-38: compile/1

Synopsis:
compile(+Files)
Compiles the specified Prolog source file(s) into memory.
Arguments:
Files
<file_spec or list of file_spec> a file specification or a list of file specifications; a ".pl" extensions may be omitted in file specifications. MOD
Description:
Exceptions:
Same as for load_files/[1,2]
See Also:
multifile/1, dynamic/1, no_style_check/1, style_check/1, nofileerrors/0, fileerrors/0, source_file/1, term_expansion/2, prolog_load_context/2, load_files/[1,2], ensure_loaded/1, use_module/[1,2,3], volatile/1, initialization/1.

L-3-39: compound/1

Synopsis:
compound(+Term)
Term is currently instantiated to a compound term.
Arguments:
Term
<term>
Examples:
| ?- compound(9). no | ?- compound(a(1,2,3)). yes | ?- compound("a"). yes | ?- compound([1,2]). yes
See Also:
atom/1, atomic/1, number/1, var/1, callable/1, nonvar/1, simple/1

L-3-40: consult/1

Synopsis:
consult(+Files)
Same as compile/1
Arguments:
Files
<file_spec or list of file_spec> . MOD
See Also:
compile/1, load_files/[1,2].

L-3-41: copy_term/2 meta-logical

Synopsis:
copy_term(+Term, -Copy)
Makes a copy of +Term in which all variables have been replaced by new variables which occur nowhere outside the newly created term.
Arguments:
Term
<term>
Copy
<term>
Description:
Example:
See Also:
atomic/1, float/1, integer/1, nonvar/1, number/1, var/1, simple/1, compound/1, callable/1, ground/1, simple/1, db_reference/1.

L-3-42: current_advice/3

Synopsis:
current_advice(*Goal, *Port, *Action)
Provides a means for checking what advice is present.
Arguments:
Goal
<callable> any term. MOD
Port
one of {call, exit, done, redo, fail}; any term.
Action
<callable> any term. MOD
Description:
Tips:
To backtrack through all the advice that exists for a predicate mypred/2, you can use the goal
| ?- current_advice(mypred(_,_), Port, Action).
If you are only interested in the advice for mypred/2 on the call port, use
| ?- current_advice(mypred(_,_), call, Action).
To determine what predicates you told to call format/2, use
| ?- current_advice(Goal, Port, format(_,_)).
See Also:
add_advice/3, remove_advice/3, check_advice/[0,1], nocheck_advice/[0,1]

L-3-43: current_atom/1 meta-logical

Synopsis:
current_atom(+Atom)
current_atom(*Atom)
Atom is a currently existing atom.
Arguments:
Atom
<atom>
Backtracking:
If Atom is uninstantiated, current_atom/1 can be used to enumerate all known atoms. The order in which atoms are bound to Atom on backtracking corresponds to the times of their creation.
Comments:
See Also:
atom/1

L-3-44: current_input/1

Synopsis:
current_input(-Stream)
unifies Stream with the current input stream.
Arguments:
Stream
<stream_object>
See Also:
open/[3,4], see/1, seeing/1
Chapter G-7-6-5

L-3-45: current_key/2

Synopsis:
current_key(*KeyName, *KeyTerm)
Succeeds when KeyName is the name of KeyTerm, and KeyTerm is a recorded key.
Arguments:
KeyName
<atomic> either of:
  • KeyTerm, if KeyTerm is an atom or an integer; or
  • the principal functor of KeyTerm, if KeyTerm is a compound term.
KeyTerm
<nonvar> is an integer, atom, or compound term which is the key for a currently recorded term.
Description:
If KeyName is not an atom, an integer, or an unbound variable, current_key/2 fails. If KeyTerm is not a current key, current_key/2 simply fails.
See Also:
recorda/3, recorded/3, recordz/3,

L-3-46: current_module/[1,2]

Synopsis:
current_module(+ModuleName)
current_module(*ModuleName)
Queries whether a module is "current" or backtracks through all of the current modules.
current_module(+ModuleName, -AbsFile)
current_module(-ModuleName, +AbsFile)
current_module(*ModuleName, *AbsFile)
Associates modules with their module-files.
Arguments:
ModuleName
<atom>
AbsFile
<atom> absolute file name
Description:
Backtracking:
current_module/1 backtracks through all of the current modules. The following command will print out all current modules:

          | ?- current_module(Module), writeq(Module), nl, fail.

          
current_module/2 backtracks through all of the current modules and their associated files.
Exceptions:
See Also:
module/1, module/2

L-3-47: current_output/1

Synopsis:
current_output(-Stream)
Unifies Stream with the current output stream.
Arguments:
Stream
<stream_object>
See Also:
open/[3,4], tell/1, telling/1

L-3-48: current_op/3

Synopsis:
current_op(+Precedence, +Type, +Name)
current_op(*Precedence, *Type, *Name)
Succeeds when the atom Name is currently an operator of type Type and precedence Precedence.
Arguments:
Precedence
<integer> if instantiated, must be an integer in the range 1 to 1200.
Type
one of {xfx, xfy, yfx, fx,xf, yf} if instantiated.
Name
<atom> atom or a list of atoms if instantiated.
Description:
Exceptions:
See Also:
op/3
section G-1-4.

L-3-49: current_predicate/2

Synopsis:
current_predicate(-Name, +Term)
current_predicate(*Name, *Term)
Unifies Name with the name of a user-defined predicate, and Term with the most general term corresponding to that predicate.
Arguments:
Name
<atom>
Term
<callable> MOD
Description:
Backtracking:
Tip:
To find out whether a predicate is built-in, use predicate_property/2.

                  Is there a callable predicate named
                  'gc'?

                  | ?- current_predicate(gc, Term).
                  no
                  | ?- predicate_property(gc, Prop)

                  Prop = built_in

          
See Also:
predicate_property/2

L-3-50: current_spypoint/1

Synopsis:
current_spypoint(*Spyspec)
Determines if there is currently a spypoint on a particular predicate or call, or enumerates all current spypoints.
Arguments:
Spyspec
<compound> can be any Prolog term. Prolog will try to unify it to terms of the form:
predicate(Pred)
A spypoint on any call to Pred. Pred will be a skeletal predicate specification, and may be module qualified.
call(Caller,Clausenum,Callee,Callnum)
A spypoint on the Callnum call to Callee in the body of the Clausenum clause of Caller. Callee and Callnum will be skeletal predicate specifications section E-1-3-2. Callnum and Clausenum will be integers, and begin counting from 1. Note that Callnum specifies a lexical position, that is, the number of the occurrence of Callee counting from the beginning of the body of the clause, and ignoring any punctuation.
Description:
This predicate is not supported in runtime systems. When building a runtime system, qld treats a call to current_spypoint/1 as it would a call to any other undefined predicate, printing a warning. If it is called during the execution of a runtime system, an existence exception is raised.
Backtracking:
Can generate all current spypoints on backtracking.
See Also:
add_spypoint/1, remove_spypoint/1, spy/1, nospy/1, debugging/0
Chapter E-1.

L-3-51: current_stream/3

Synopsis:
current_stream(-AbsFile, -Mode, +Stream)
current_stream(*AbsFile, *Mode, *Stream)
Stream is a stream which is currently open on file AbsFile in mode Mode.
Arguments:
AbsFile
<atom> absolute file name.
Mode
one of {read, write, append}
Stream
<stream_object> a term which will be unifed with an open stream.
Description:
Backtracking:
Can be used to backtrack through all open streams.
See Also:
open/[3,4], see/1, tell/1
section G-7-6-7

L-3-52: db_reference/1

Synopsis:
db_reference(+Term)
Term is a db_reference.
Arguments:
Term
<term>
See Also:
recorda/3, assert/2, atom/1, atomic/1, number/1, var/1, compound/1, callable/1, nonvar/1, simple/1

L-3-53: debug/0

Synopsis:
debug
Turns on the debugger in debug mode.
Description:
See Also:
spy/1,add_spypoint/1,trace/0, nodebug/0

L-3-54: debugging/0

Synopsis:
debugging
Prints out current debugging state
Description:
debugging/0 displays information on the terminal about the current debugging state. It shows
This predicate is not supported in runtime systems. When building a runtime system, qld treats a call to debugging/0 as it would a call to any other undefined predicate, printing a warning. If it is called during the execution of a runtime system, an existence exception is raised.

L-3-55: discontiguous/1 declaration

Synopsis:
:- discontiguous +PredSpec
Declares the clauses of the predicates defined by PredSpecs to be discontiguous in the source file (suppresses compile-time warnings).
Arguments:
PredSpec
<gen_pred_spec_tree> a skeletal predicate specification
Exceptions:
See Also:
Section section G-14-1.

L-3-56: display/1

Synopsis:
display(+Term)
Displays Term on the standard output stream .
Arguments:
Term
<term>
Description:
Tips:
Example:
| ?- display(a+b). +(a,b) yes
read(X), display(X), nl. |: a + b * c. +(a,*(b,c)) X = a+b*c | ?-
See Also:
write/[1,2], write_term/[2,3]

L-3-57: dynamic/1 declaration

Synopsis:
:-dynamic +PredSpecs
Declares the predicates in PredSpecs to be dynamic.
Arguments:
PredSpecs
<pred_spec_forest> A single predicate specification of the form Name/Arity, or a sequence of predicate specifications separated by commas. Name must be an atom and Arity an integer in the range 0..255. MOD
Description:
Exceptions:
Comments:
To declare a grammar rule gram/n dynamic, the arity of PredSpec must be n+2.
See Also:
Chapter G-14-1.

L-3-58: ensure_loaded/1

Synopsis:
ensure_loaded(+Files)
Load the specified Prolog source and/or QOF file(s) into memory, if not already loaded and up to date.
Arguments:
Files
<file_spec or list of file_spec> a file specification or a list of file specifications; a ".pl" or ".qof" extension may be omitted in a file specification. MOD
Description:
Exceptions:
See Also:
compile/1, load_files/[1,2].

L-3-59: erase/1

Synopsis:
erase(+Ref)
Erases from the data base the dynamic clause or recorded term referenced by Ref.
Arguments:
Ref
<db_reference>
Description:
Exceptions:
See Also:
abolish/[1,2], assert/2, dynamic/1, retract/1, retractall/1.

L-3-60: expand_term/2 hookable

Synopsis:
expand_term(+Term1, -Term2)
Transforms grammar rules into Prolog clauses before they are compiled. Normally called by the compiler, but can be called directly. The transform can be customized by defining the hook term_expansion/2.
Arguments:
Term1
<term>
Term2
<term>
Description:
Exceptions:
Prints messages for exceptions raised by term_expansion/2.
Examples:
See examples in section G-16-4.
See Also:
term_expansion/2, phrase/[2,3], 'C'/3, -->/2 Chapter G-16

L-3-61: extern/1 declaration

Synopsis:
:-extern(+ExternSpec)
Declares a Prolog predicate to be callable from functions written in other languages.
Arguments:
ExternSpec
<extern_spec> a term of the form Name(Argspec, Argspec, ...) MOD
Name
the name of the Prolog predicate
Argspec
an argument specification for each argument of the predicate. Each should be one of the following where T is a foreign type name.

 +integer    +float    +single   +double
 -integer    -float    -single   -double

 +atom       +term     +string
 -atom       -term     -string

 +string     +address(T)
 -string     -address(T)

                      
Description:
Exceptions:
Examples:
It can be quite useful to make the system built-in call/1 available to foreign functions. Combined with term manipulation in C, doing so provides an evaluator for arbitrary Prolog queries. This can be done by loading a Prolog file containing the declaration
:- extern(call(+term)).
Prolog's call/1 is then available to C via a function like
call_prolog(term) QP_term_ref term; { QP_pred_ref call; call = QP_predicate("call",1,"user"); QP_query(call, term); }
For the sake of brevity, this example does not check return values for failure or errors. Doing so is generally recommended. Of course, as is the case in Prolog, it is faster to call a Prolog predicate directly.

L-3-62: fail/0

Synopsis:
fail
Always fails.

L-3-63: false/0

Synopsis:
false
Same as fail/0.

L-3-64: file_search_path/2 extendable

Synopsis:
file_search_path(*PathAlias, *DirSpec)
Defines a symbolic name for a directory or a path. Used by predicates taking file_spec as input argument.
Arguments:
PathAlias
<atom> A string which represents the path given by DirSpec.
DirSpec
<file_spec> Either a string giving the path to a file or directory, or PathAlias(DirSpec), where PathAlias is defined by another file_search_path/2 rule.
Description:
Examples:
| ?- assert(file_search_path(home, '/usr/joe_bob')). yes | ?- assert(file_search_path(review, home('movie/review'))). yes | ?- compile(review(blob)). % compiling /usr/joe_bob/movie/review/blob.pl
See Also:
absolute_file_name/[2,3], assert/[1,2], dynamic/1, library_directory/1, listing/1, load_files/[1,2],
Chapter G-6.

L-3-65: fileerrors/0

Synopsis:
fileerrors
Cancels the effect of nofileerrors/0.
Description:
See Also:
nofileerrors/0, prolog_flag/[2,3]

L-3-66: findall/3

Synopsis:
findall(+Template, +*Generator, -List)
Collects in List all the instances of Template for which the goal Generator succeeds. A special case of bagof/3, where all free variables in the generator are taken to be existentially quantified.
Arguments:
Template
<term>
Generator
<callable> a goal to be proved as if by call/1. MOD
List
<list of terms>
Description:
Examples:
To illustrate the differences among findall/3, setof/3, and bagof/3:

          | ?- [user].
          | foo(1,2).
          | foo(1,2).
          | foo(2,3).
          |
          % user compiled in module user, 0.100 sec 352 bytes

          yes
          | ?- bagof(X, foo(X,Y), L).

          X = _3342,
          Y = 2,
          L = [1,1] ;

          X = _3342,
          Y = 3,
          L = [2] ;

          no

          
| ?- bagof(X, Y^foo(X,Y), L). X = _3342, Y = _3361, L = [1,1,2] ; no
| ?- findall(X, foo(X,Y), L). X = _3342, Y = _3384, L = [1,1,2] ; no
| ?- setof(X, foo(X,Y), L). X = _3342, Y = 2, L = [1] ; X = _3342, Y = 3, L = [2] ; no | ?-
Exceptions:
As for call/1:
See Also:
setof/3, bagof/3, ^/2
Chapter G-15

L-3-67: float/1 meta-logical

Synopsis:
float(+Term)
Term is currently instantiated to a float.
Arguments:
Term
<term>
Example:
| ?- float(Term1). no | ?- float(5.2). yes
See Also:
atom/1, atomic/1, number/1, var/1, compound/1, callable/1, nonvar/1, simple/1

L-3-68: flush_output/1

Synopsis:
flush_output(+Stream)
Forces the buffered output of the stream Stream to be sent to the associated device.
Arguments:
Stream
<stream_object> a valid Prolog stream
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
Comments:
If the host operating system, such as UNIX, buffers an output file stream, the output may be written to the disk some time after flush_output/1 succeeds.
See Also:
nl/[0,1], QP_flush(), QU_flush_output(), ttyflush/0

L-3-69: foreign/[2,3] hook

Synopsis:
foreign(*Routine, *ForeignSpec)
foreign(*Routine, *Language, *ForeignSpec)
Describes the interface between Prolog and the foreign Routine. The user has to define a foreign/3 or the fact for every foreign function that is to be called from Prolog. Used by load_foreign_files/2 and load_foreign_executable/2.
Arguments:
Routine
<atom> An atom that names a foreign code Routine
Language
<atom> An atom that names the Language in which Routine is written. It must be one of 'c', 'pascal' or 'fortran'.
ForeignSpec
<foreign_spec> A term of the form PredName(Argspec, Argspec, ...) where:
PredName
the name of the Prolog predicate
Argspec
an argument specification (for each argument of the predicate) One of the following:

 +integer    +float    +single   +double
 -integer    -float    -single   -double
[-integer]  [-float]  [-single] [-double]

  +atom      +term     +string
  -atom      -term     -string
 [-atom]    [-term]   [-string]

 +string(N)    +address(T)
 -string(N)    -address(T)
[-string(N)]  [-address(T)]

                       
where N is a positive integer and T is a foreign type name.
Description:
Exceptions:
Errors in the specification of foreign/3 will only be detected at load_foreign_files/2 time. Otherwise defining a foreign/3 fact is just like defining any other Prolog fact.
Tips:
A good practice in loading several foreign files is to insert the call to load_foreign_files/2 into the file which defines foreign/3 as an embedded command. For example,

                  foreign(f11, c, f11(+integer)).
                  foreign(f12, c, f12(+atom, -atom)).
                  foreign_file('f1.o', [f11, f12]).
                  :- load_foreign_files('f1.o', []),
                     abolish([foreign/3,foreign_file/2]).

          
Examples:
Solve() is a C function that takes three integer coeffecients of a quadratic equation and returns the two solutions. We assume that the solutions are not imaginary numbers.
IN THE PROLOG CODE:

          foreign(solve, c, solve(+integer, +integer, +integer,
                                  -double, -double)).
          foreign_file('a.o', [solve]).
          :- load_foreign_files(['a.o'], ['-lm']),
             abolish([foreign/3, foreign_file/2]).

          
IN THE C CODE:
void solve(a, b, c, f1, f2) long int a, b, c; double *f1; double *f2; { *f1 = (-b + sqrt(b*b - 4*a*c)) / 2 * a; *f2 = (-b - sqrt(b*b - 4*a*c)) / 2 * a; }
See Also:
load_foreign_files/2, foreign_file/2, extern/1 Chapter I-3

L-3-70: foreign_file/2 hook

Synopsis:
foreign_file(+ObjectFile, +ForeignFunctions)
Describes the foreign functions in ObjectFile to interface to. The user has to define a foreign_file/2 fact for every object file that is to be loaded into Prolog.
Arguments:
ObjectFile
<file_spec> The foreign object (.o) file
ForeignFunctions
<list of atoms> A list of foreign function symbols that will be obtained from ObjectFile.
Description:
Exceptions:
Errors in the specification of foreign_file/2 will only be detected when load_foreign_files/2 is called. Otherwise defining a foreign_file/2 fact is just like defining any other Prolog fact.
Examples:
See example under foreign/[2,3].
Tips:
See Tip under foreign/[2,3]
See Also:
load_foreign_files/2, foreign/[2,3]

L-3-71: format/[2,3]

Synopsis:
format(+Control, +Arguments)
format(+Stream, +Control, +Arguments)
Interprets the Arguments according to the Control string and prints the result on the current or specified output stream.
Arguments:
Stream
<stream_object>
Control
<list of char> or <atom> either an atom or a string which can contain control sequences of the form '~<n><c>'
<c>
a format control option
<n>
is its optional argument. <n> must be a non-negative integer.
Any characters that are not part of a control sequence are written to the current output stream.
Arguments
<term> list of arguments which will be interpreted and possibly printed by format control options. If there is only one argument then this argument need not be enclosed in a list.
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
Examples:
1. The following is an extended example of the use of format/[2,3] and the character escaping facility.

| ?- prolog_flag(character_escapes, _, on).

yes
| ?- compile(user).
toc(Rel) :-
    format('Table of Contents ~t ~a~72|~*n', [i,3]),
    format('~tTable of Contents~t~72|~*n', 2),
    format("1. Documentation supplement for ~s~1f \c
      ~`.t ~d~72|~*n", ["Quintus Prolog Release ",Rel,2,2]),
    format("~t~*+~w Definition of the term \"loaded\" \c
      ~`.t ~d~72|~n", [3,1-1,2]),
    format("~t~*+~w Finding all solutions ~`.t ~d~72|~n", [3,1-2,3]),
    format("~t~*+~w Searching for a file in a library \c
      ~`.t ~d~72|~n", [3,1-3,4]),
    format("~t~*+~w New Built-in Predicates ~`.t ~d~72|~n", [3,1-4,5]),
    format("~t~*+~w write_canonical (?Term) ~`.t ~d~72|~n", [7,1-4-1,5]),
    format("~*+.~n~*+.~n~*+.~n", [20,20,20]),
    format("~t~*+~w File Specifications ~`.t ~d~72|~n", [3,1-7,17]),
    format("~t~*+~w multifile(+PredSpec) ~`.t ~d~72|~n", [7,1-7-1,18]).
[user compiled (20.783 sec 4888 bytes)]

yes
| ?- toc(1.5).
                           Table of Contents

1. Documentation supplement for Quintus Prolog Release 1.5 ........... 2

   1-1 Definition of the term "loaded" ............................... 2
   1-2 Finding all solutions ......................................... 3
   1-3 Searching for a file in a library ............................. 4
   1-4 New Built-in Predicates ....................................... 5
       1-4-1 write_canonical (?Term) ................................. 5
                    .
                    .
                    .
   1-7 File Specifications .......................................... 17
       1-7-1 multifile(+PredSpec) ................................... 18

yes

2. Misc. examples:
| ?- X=12, format('X =:= ~2d', X). % These three | ?- X=12, format("X=:= ~2d", X). % have the | ?- X=12, format('X =:= ~*d', [2,X]). % same results | ?- format('~s', ["string"]). % These two have | ?- format('string', []). % the same results | ?- X=12, Y= 123, format('X = ~d, Y = ~d', [X,Y]).
See Also:
write_canonical/[1,2], print/[1,2], write/[1,2] Chapter G-7

L-3-72: functor/3 meta-logical

Synopsis:
functor(+Term, -Name, -Arity)
functor(-Term, +Name, +Arity)
Succeeds if the principal functor of term Term has name Name and arity Arity.
Arguments:
Term
<term>
Name
<atom>
Arity
<arity>
Description:
There are two ways of using this predicate:
  1. If Term is initially instantiated, then
    • if Term is a compound term, Name and Arity are unified with the name and arity of its principal functor.
    • if Term is an atom or number, Name is unified with Term, and Arity is unified with 0.
  2. If Term is initially uninstantiated, Name and Arity must both be instantiated, and
    • if Arity is an integer in the range 1..255, then Name must be an atom, and Term becomes instantiated to the most general term having the specified Name and Arity; that is, a term with distinct variables for all of its arguments.
    • if Arity is 0, then Name must be an atom or a number, and it is unified with Term.
Examples:
| ?- functor(foo(a,b), N, A). N = foo, A = 2 | ?- functor(X, foo, 2). X = foo(_1,_2)
Note: "_1" and "_2" are anonymous variables. The term foo(_1,_2) is the "most general" term that has name foo and arity 2.

                  | ?- functor(X, 2, 0).

                  X = 2

          
Exceptions:
See Also:
arg/3, name/2, =../2
Chapter G-9-2

L-3-73: garbage_collect/0

Synopsis:
garbage_collect
Explicitly invokes the garbage collector.
Description:
Example:
In the code fragment:
cycle(X) :- big_goal(X, X1), cycle(X1).

          
if cycle/1 is to run for a long time, and if big_goal /2 generates a lot of garbage, then rewrite the code like this:

cycle(X) :- big_goal(X, X1), !, garbage_collect, cycle(X1).

          
Tip:
Use of the "!, garbage_collect" idiom is only desirable when you notice that your code does frequent garbage collections. It will allow the garbage collector to collect garbage more effectively, and the cycle will run without demanding increasing amounts of memory.
See Also:
gc/0, prolog_flag(gc_margin,_,_,_), nogc/0, statistics/2

L-3-74: garbage_collect_atoms/0

Synopsis:
garbage_collect_atoms
Invokes the atom garbage collector.
Description:
Tips:
A program can use the atoms keyword to statistics/2 to determine if a call to garbage_collect_atoms would be appropriate.
See Also:
garbage_collect/0, statistics/2

L-3-75: gc/0

Synopsis:
gc
Enables the garbage collector.
Description:

L-3-76: 'QU_messages':generate_message/3 extendable

Synopsis:
generate_message(+MessageTerm, -S0, -S)
For a given MessageTerm, generates a list composed of Control-Arg pairs and the atom 'nl'. This can be translated into a nested list of Control-Arg pairs which can be used as input to print_message_lines/3.
Arguments:
MessageTerm
<term> May be any term.
S0
<list of pair> the resulting list of Control-Arg pairs.
S
<list of pair> the remaining list.
Description:
Examples:
The following example shows how the output of generate_message/3 is translated and passed to print_message_lines/3.
gen_message_and_print_lines(Msg, Stream, Prefix) :- generate_message(Msg, L, []), lines(L, Lines, []), print_message_lines(Stream, Prefix, Lines) lines([]) --> []. lines([H|T]) --> line(H), [nl], lines(T). line([]) --> []. line([Control-Args|T]) --> [Control-Args], line(T).
Errors:
When print_message/2 calls 'QU_messages':generate_message/3 it handles any exceptions that arise by printing out an error message. It then writes out the original message.
See Also:
print_message/2, message_hook/3, format/[2,3], print_message_lines/3, user:generate_message_hook/3, QU_messages':query_abbreviation/2
Chapter G-20

L-3-77: user:generate_message_hook/3 hook

Synopsis:
:- multifile generate_message_hook/3.
generate_message_hook(+MessageTerm, -S0, -S)
A way for the user to override the call to 'QU_messages':generate_message/3 in print_message/2.
Arguments:
MessageTerm
<term> May be any term.
S0
<list of pair> the resulting list of Control-Arg pairs.
S
<list of pair> the remaining list.
Description:
Examples:
Tips:
If you define clauses for this hook predicate, it should be declared multifile in each file containing clauses for it. Without this multifile declaration, it will be impossible to use this code with other (possibly library) code that has clauses for this hook.
See also::
'QU_messages':generate_message/3, print_message/2, message_hook/3, format/[2,3], print_message_lines/3

L-3-78: get/[1,2]

Synopsis:
get(-Char)
get(+Stream, -Char)
unifies Char with the ASCII code of the next non-layout character from Stream or the current input stream.
Arguments:
Char
<char> integer; legal ASCII code
Stream
<stream_object> valid Prolog input stream
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
Comment:
If the stream is tty, trying to read beyond the end of the stream results in resetting the input stream and trying to read the next character. By using the eof_action option of open/[3,4], it is possible to specify that it should not be an error to run off the end of a stream.
See Also:
get0/[1,2], ttyget/1, prompt/[2,3], open/[3,4]

L-3-79: get0/[1,2]

Synopsis:
get0(-Char)
get0(+Stream, -Char)
Same as get/[1,2] except that Char includes layout characters.
Arguments:
Char
<char>
Stream
<stream_object>
See Also:
get/[1,2], ttyget0/1, prompt/[2,3]

L-3-80: get_profile_results/4

Synopsis:
get_profile_results(+By, +Num,-Results,-Total)
Returns the results of the last profiled execution.
Arguments:
By
<atom> must be one of the atoms:

                          by_time  by_choice_points
                          by_calls by_redos

                  
Num
<integer> specifies the maximum length of the Results list
Results
<list of term> the results list
Total
<integer>
Description:
Example:
| ?- get_profile_results(by_time,3,List,Total). List = [proc(user:setof/3,227,0,0,1980, [calledby(61,152,user:satisfy/1,6,1), calledby(20,27,user:satisfy/1,7,1), calledby(18,48,user:seto/3,1,1)]), proc(user:satisfy/1,35738,36782,14112,260, [calledby(69,13857,user:satisfy/1,1,2), calledby(15,12137,user:satisfy/1,2,1)]), proc(user:write/1,2814,0,0,240, [calledby(33,481,user:reply/1,3,1), calledby(25,608,user:replies/1,3,1), calledby(16,562,user:out/1,2,1), calledby(8,203,user:reply/1,2,5), calledby(8,34,user:replies/1,2,3)])], Total = 6040 [profile]
See Also:
profile/[0,1], show_profile_results/[0,1,2]

L-3-81: ground/1

Synopsis:
ground(+Term)
Term is currently instantiated to a term that is completely bound (has no uninstantiated variables in it).
Arguments:
Term
<term>
Examples:
See Also:
atom/1, atomic/1, number/1, var/1, compound/1, callable/1, nonvar/1, simple/1

L-3-82: halt/[0,1]

Synopsis:
halt
halt(+ExitCode)
Causes an exit from Prolog.
Arguments:
ExitCode
<integer> an exit status code
Description:
See Also:
abort/0, break/0
Chapter G-11-1

L-3-83: hash_term/2

Synopsis:
hash_term(+Term, -HashValue)
Provides an efficient way to calculate an integer hash value for the ground term Term.
Arguments:
Term
<term>
HashValue
<term> is an integer or variable
Description:
Tips:
hash_term/2 is provided primarily as a tool for the construction of sophisticated Prolog clause access schemes. Its intended use is to generate hash values for ground terms that will be used with first argument clause indexing, yielding compact and efficient multi-argument or deep argument indexing.
hash_term/2 is most easily used when a known pattern of access to a predicate is desired and both arguments of the call and arguments of the predicate are known to be ground. In the following simple but typical example, hash_term/2 calls are used together with Prolog's database manipulation predicates (assert/1 and clause/2) to calculate and add an additional argument to the clauses actually stored in the Prolog database:
add_pred_info(Name, Arity, Module, Info) :- hash_term([Name,Arity,Module], Hash), assert(info(Hash,Name,Arity,Module,Info)). get_pred_info(Name, Arity, Module, Info) :- hash_term([Name,Arity,Module], Hash), clause(info(Hash,Name,Arity,Module,Info), _).
This example assumes that the name, arity and module to be stored in the Prolog database are ground when add_pred_info/4 is called, and that they are also ground when get_pred_info/4 is called. The predicate that is actually asserted, info/5, has an additional argument calculated by hash_term/2; info/5 would not normally be called directly. A predicate using hash_term/2 to delete the stored information would also be straightforward.
If the first argument passed to hash_term/2 is not ground, hash_term/2 returns a variable. Thus, if add_pred_info/4 is called with the name, arity or module not ground, the info/5 information will be asserted with a variable as its first argument, so it will not be indexed. If get_pred_info/4 is called with the name, arity or module not ground, info/5 will simply be searched sequentially. Prolog's normal semantics will be retained, although access will be considerably less efficient.
It is possible to use hash_term/2 in more complex indexing schemes as well by checking instantiation when adding, accessing, and deleting clauses; however, it is up to the user to ensure appropriate instantiation patterns in calls. The tradeoff between run-time argument checking and reduced indexing effectiveness depends on the degree of discrimination otherwise afforded by normal first argument indexing. The efficiency gained by fast multi-argument indexing can often more than make up for such additional run-time costs.
It is also possible to use such indexing techniques on compiled predicates using term expansion. Note that calculated hash values are not dependent on transitory information like atom numbers or internal pointers. Hash values are consistent across saving and restoring or multiple invocations of an application.
Calculation of hash values is very fast, and indices constructed using the techniques sketched above are also very compact, as the only additional cost is for storing the additional (hash value) argument. When a solution to a complex indexing problem can be constructed using hash_term/2 it will probably be preferable to solutions using other techniques.

L-3-84: help/[0,1] hookable

Synopsis:
help
Gives basic information, such as how to start using the help system and how to exit from Prolog.
help(+Topic)
Displays help available on Topic.
Arguments:
Topic
<term> an atom
Description:
See Also:
user_help/0, manual/[0,1]

L-3-85: initialization/1 declaration

Synopsis:
:-initialization(Goal)
Declares that Goal is to be run when the file in which the declaration appears is loaded into a running system, or when a stand-alone program or runtime system that contains the file is started up.
Arguments:
Goal
<callable> A valid goal. MOD
Description:
Exceptions:
Examples:
To understand the examples fully, read the reference page on volatile/1 first.
See Also:
volatile/1, load_files/1, compile/1
See Chapter G-5

L-3-86: instance/2

Synopsis:
instance(+Ref, -Term)
Unifies Term with the most general instance of the dynamic clause or recorded term indicated by the database reference Ref.
Arguments:
Ref
<db_reference>
Term
<term>
Description:
Ref must be instantiated to a database reference to an existing clause or recorded term. instance/2 is not sensitive to the source module and can be used to access any clause, regardless of its module.
Exceptions:
Comments:
instance/2 ignores the module of a clause. Because of this, accessing a clause with via instance/2 is different from accessing it via clause/3 with a given Ref.
If the reference is to a unit-clause C, then Term is unified with 'C :- true'.
Examples:
| ?- assert(foo:bar,R). R = '$ref'(771292,1) | ?- instance('$ref'(771292,1),T). T = (bar:-true) | ?- clause(H,B,'$ref'(771292,1)). no | ?- clause(foo:H,B,'$ref'(771292,1)). H = bar, B = true | ?-
See Also:
clause/3, asserta/2, assertz/2
Chapter G-14

L-3-87: integer/1

Synopsis:
integer(+Term)
Term is an integer.
Arguments:
Term
<term>
Examples:
| ?- integer(5). yes | ?- integer(5.0). no
See Also:
atom/1, atomic/1, number/1, var/1, compound/1, callable/1, nonvar/1, simple/1

L-3-88: is/2

Synopsis:
-Term is +Expression
Evaluates Expression as an arithmetic expression (see Chapter G-8-3), and unifies the resulting number with Term.
Arguments:
Expression
<expr> an expression made up of:
functors representing arithmetic operations
numbers
variables bound to numbers or arithmetic expressions
Term
<number> a number
Description:
The possible values for Expression are spelled out in detail in section G-8-3.
Character codes like "a" are arithmetic expressions.
Exceptions:
Examples:
| ?- X is 2 * 3 + 4. X = 10 | ?- Y = 32.1, X is Y * Y. Y = 3.21E+01, X = 1.03041E+03 | ?- Arity is 3 * 8, X is 4 + Arity + (3 * Arity * Arity). Arity = 24, X = 1756

                  | ?- X is 6/0.
                  ! Domain error in argument 2 of is/2
                  ! non-zero number expected, but 6/0 found
                  ! goal:  _3211 is 6/0

          

                  | ?- X is 16' 7fffffff + 3.
                  ! Syntax error
                  ! between lines 64 and 65
                  ! X is 0
                  ! <<here>>
                  ! 7 fffffff+3

                  | ?- X is "a".

                  X = 97

                  | ?- X is 4 * 5, Y is X * 4.

                  X = 20,
                  Y = 80

          
See example under assign/2 to see use of is/2 to peek at random memory addresses.
Comments:
If a variable in an arithmetic expression is bound to another arithmetic expression (as opposed to a number) at runtime then the cost of evaluating that expression is much greater. It is approximately equal to the cost of call/1 of an arithmetic goal.
See Also:
assign/2, </2, =:=/2, =</2, =\=/2, >/2, >=/2 Chapter G-8

L-3-89: keysort/2

Synopsis:
keysort(+List1, -List2)
Sorts the elements of the list List1 into ascending standard order (see section G-9-7-1 with respect to the key of the pair structure.
Arguments:
List1
<list of pair>
List2
<list of pair>
Description:
The list List1 must consist of terms of the form Key-Value. Multiple occurrences of any term are not removed.
(The time taken to do this is at worst order (N log N) where N is the length of the list.)
Note that the elements of List1 are sorted only according to the value of Key, not according to the value of Value.
keysort is stable in the sense that the relative position of elements with the same key maintained.
Examples:
| ?- keysort([3-a,1-b,2-c,1-a,1-b], X). X = [1-b,1-a,1-b,2-c,3-a]

                  |?- keysort([2-1, 1-2], [1-2, 2-1]).

                  yes

          
Exceptions:
See Also:
library(samsort)

L-3-90: leash/1

Synopsis:
leash(+Mode)
Starts leashing on the ports given by Mode.
Arguments:
Mode
<all | list> either the atom 'all', or a list of the ports to be leashed. Valid port names are: 'call', 'exit', 'redo', 'fail', 'done', 'head' and 'exception.'
Description:
Examples:
| ?- leash([]).
turns off all leashing; now when you creep you will get an exhaustive trace but no opportunity to interact with the debugger. You can get back to the debugger to interact with it by pressing ^c "t". The command

                  | ?- leash([call,redo]).

          
leashes on the Call and Redo ports. When creeping, the debugger will now stop at every Call and Redo port to allow you to interact.
Exceptions:
instantiation_error
Mode is not ground
domain_error
Mode is not a valid leash specification
See Also:
Chapter E-1

L-3-91: length/2

Synopsis:
length(-List, +Integer)
length(*List, *Integer)
Integer is the length of List. If List is instantiated to a proper list, the predicate is determinate, also when Integer is var.
Arguments:
List
<list> a list
Integer
<integer> non-negative integer
Description:
Backtracking:
If both List and Integer are variables, the system will backtrack, generating lists of increasing length whose elements are anonymous variables.
Exceptions:
Examples:
| ?- length([1,2], 2). yes | ?- length([1,2], 0). no | ?- length([1,2], X). X = 2 ; no

L-3-92: library_directory/1 extendable

Synopsis:
library_directory(*DirSpec)
Defines a library directory. Used by predicates taking file_spec as input argument.
Arguments:
DirSpec
<file_spec> Either an atom giving the path to a file, or PathAlias(DirSpec), where PathAlias is defined by a file_search_path rule (see the reference page for file_search_path/2).
Description:
Examples:
| ?- assert(library_directory('/usr/joe_bob/prolog/libs')). yes | ?- ensure_loaded(library(flying)). % loading file /usr/joe_bob/prolog/libs/flying.qof ...
See Also:
absolute_file_name/[2,3], assert/[1,2], dynamic/1, file_search_path/2, listing/1, load_files/[1,2]
Chapter G-6.

L-3-93: line_count/2

Synopsis:
line_count(+Stream, -N)
Unifies N with the total number of lines either read or written on the open stream Stream.
Arguments:
Stream
<stream_object>
N
<integer>
Description:
A freshly opened stream has a line count of 1. See section G-7-7-1, for details on the use of this predicate on a stream which is directed to the user's terminal.
Exception:
Stream errors (see section G-7-6-2)
See Also:
character_count/2, line_position/2, stream_position/3 Chapter G-7

L-3-94: line_position/2

Synopsis:
line_position(+Stream, -N)
Unifies N with the total number of characters either read or written on the current line of Stream.
Arguments:
Stream
<stream_object> specifies an open stream
N
<integer> current line position
Description:
A fresh line has a line position of 0. See section G-7-7-1, for details on the use of this predicate on a stream which is directed to the user's terminal.
Exception:
Stream errors (see section G-7-6-2)
See Also:
character_count/2, line_count/2, stream_position/3 Chapter G-7

L-3-95: listing/[0,1]

Synopsis:
listing
listing(+PredSpecs)
Prints the clauses of all the dynamic procedures currently in the Prolog data base, or of PredSpecs, to the current output stream, using portray_clause/1.
Arguments:
PredSpecs
<gen_pred_spec_tree_var> ; Name/Arity predicate specification
list of predicate specifications or atoms
Description:
Examples:
Comments:
Under the Emacs interface, there is a facility for finding the source code definition for a specified compiled or dynamic procedure and reading it into an edit buffer. This is likely to be more helpful than listing/1 in most cases. See section D-2-2 for more information.

L-3-96: load_files/[1,2]

Synopsis:
load_files(+Files)
load_files(+Files, +Options)
[+File|+Files]
[]
Load the specified Prolog source and/or QOF files into memory. Subsumes all other load predicates.
Arguments:
Files
<file_spec> or <list of file_spec> a file specification or a list of file specifications; a ".pl" or ".qof" extension may be omitted in a file specification. MOD
Options
<list> a list of zero or more options of the form:
if(X)
X=true
(default) always load
X=changed
load file if it is not already loaded or if it has been changed since it was last loaded
when(X)
X=run_time
(default) The file does not define any predicates that will be called during compilation of other files.
X=compile_time
the file only defines predicates that wil be called during compilation of other files; it does not define any predicates that will be called when the application is running.
X=both
the file defines some predicates that will be needed during compilation and some that will be needed during execution.
load_type(X)

X=compile
compile Prolog source code
X=qof
load QOF code
X=latest
(default) load QOF or compile source, whichever is newer. The latest option is effective only if Files are sepcified without extensions.
must_be_module(X)

X=true
the files are required to be module-files
X=false
(default) the files need not be module-files
imports(X)

X=all
(default) if the file is a module-file, all exported predicates are imported
X=List
list of predicates to be imported
Note that if the option imports is present, the option must_be_module(true) is enforced.
all_dynamic(X)

X=true
load all predicates as dynamic
X=false
(default) load predicates as static unless they are declared dynamic
Note that the all_dynamic option has no effect when a QOF file is loaded. Thus it is not normally useful to use all_dynamic(true) in conjunction with load_type(latest), since the file will be loaded in dynamic mode only if the source file is more recent than the QOF file.
silent(X)

X=true
loading information is printed as silent messages (see section G-20 for details).
X=false
(default) loading information is printed as informational message.
Description:
Exceptions:
See Also:
compile/1, consult/1, dynamic/1, ensure_loaded/1, fileerrors/0, multifile/1, no_style_check/1, nofileerrors/0, prolog_load_context/2, source_file/[1,2], style_check/1, term_expansion/2, use_module/[1,2,3], initialization/1, volatile/1.
Chapter G-4

L-3-97: load_foreign_executable/1 hookable

Synopsis:
load_foreign_executable(+Executable)
Load the foreign executable (shared object file) Executable into Prolog. Relies on the hook predicates foreign_file/2 and foreign/[2,3].
Arguments:
Executable
<file_spec> The shared object (.so) file to be loaded.
Description:
Exceptions:
Errors in the specification of foreign/3 will all be reported when load_foreign_executable/1 is called.
Examples:
See example under foreign/[2,3]
See Also:
foreign_file/2, foreign/[2,3], load_foreign_files/2
Chapter I-3

L-3-98: load_foreign_files/2 hookable

Synopsis:
load_foreign_files(+ObjectFiles, +Libraries)
Loads foreign object files into Prolog. Relies on the hook predicates foreign_file/2 and foreign/[2,3].
Arguments:
ObjectFiles
<list of file_spec> A list of foreign object (.o) files to be loaded.
Libraries
<list of atom> A list of UNIX libraries that need to be searched while loading ObjectFiles.
Description:
Exceptions:
Errors in the specification of foreign/3 will all be reported when load_foreign_files/2 is called.
Examples:
See example under foreign/[2,3]
See Also:
foreign_file/2, foreign/[2,3], load_foreign_executable/1
Chapter I-3

L-3-99: manual/[0,1]

Synopsis:
manual
Displays a menu of the top layer of the manual hierarchy.
manual(+Term)
Goes directly to the point in the manual represented by Term.
Arguments:
Term
<term> a reference: of form part-chapter-section-subsection. E.g. g-13-3-1
part
a lower case letter representing a major part of the manual:

a   Introduction
b   User's Guide
c   The Quintus User Interface
d   The Emacs Interface
e   The Debugger
f   Glossary
g   The Prolog Language
h   Creating Executables
i   Foreign Language Interface
j   Inter-Process Communication
k   Library
l   Prolog Reference Pages
m   C Reference Pages
n   Command Reference Pages
o   Release Notes and Installation Guide

                    
chapter, section, sub-sections, etc.
integers representing chapters, sections, sub-sections, etc.
a topic
Description:
Examples:
To view the text in G.17-2-1 type:

          ?- manual(g-17-2-1).

          
To look up character escaping, type:
manual('character escaping').
This brings up a menu which contains reference terms enclosed in curly braces. Simply copy the one you want at the prompt.
See Also:
help/1
Chapter G-17

L-3-100: message_hook/3 hook

Synopsis:
message_hook(+MessageTerm, +Severity, +Lines)
Overrides the call to print_message_lines/3 in print_message/2. A way for the user to intercept the Message of type Severity, whose translations is Lines, before it is actually printed.
Arguments:
MessageTerm
<term> any term
Severity
one of {informational, warning, error, help, silent}
Lines
<list of pair> is of the form [Line1, Line2, ...], where each Linen is of the form [Control_1-Args_1,Control_2-Args_2, ...].
Description:
After a message is parsed, but before the message is written, print_message/2 calls
user:message_hook(+MsgTerm,+Severity,+Lines)
If the call to user:message_hook/3 succeeds, print_message succeeds without further processing. Otherwise the built-in message display is used. It is often useful to have a message hook that performs some action and then fails, allowing other message hooks to run, and eventually allowing the message to be printed as usual. See section G-20-3-3 for an example.
Exceptions:
An exception raised by this predicate causes an error message to be printed and then the original message is printed using the default message text and formatting. Since the user defines message_hook/3, they can write code which might raise exceptions.
Examples:
The following is the default, built-in message portrayal predicate:
message_hook(MessageTerm,Severity,Lines):- ( Severity == silent -> true /* Don't translate or print silent messages */ ; severity_prefix(Severity,Prefix,Stream) -> print_message_lines(Stream,Prefix,Lines) ; raise_exception(domain_error( print_message(Severity,MessageTerm),1, one_of([help,error,warning, informational,silent]), Severity)). severity_prefix(silent, '' '', user_error). severity_prefix(help, '' '', user_error). severity_prefix(error, '! ', user_error). severity_prefix(warning, '* ', user_error). severity_prefix(informational,'% ', user_error).
The reasoning behind the assignment of streams is that all unsolicited output should go to user_error.
Tips:
If you define clauses for this hook predicate, it should be declared multifile in each file containing clauses for it. Without this multifile declaration, it will be impossible to use this code with other (possibly library) code that has clauses for this hook.
See Also:
print_message/2, generate_message/3, print_message_lines/3
Chapter G-20

L-3-101: meta_predicate/1 declaration

Synopsis:
:-meta_predicate +MetaSpec
Provides for module name expansion of arguments in calls to the predicate given by MetaSpec. All meta_predicate/1 declarations must be at the beginning of a module.
Arguments:
MetaSpec
<callable> Goal template or list of goal templates, of the form:

                       functor(Arg1, Arg2,...)

               
Each Argn is one of:

                  :              requires module name expansion

                  integer >0      same as ':'

                  +, -, ?,*      ignored


               
Description:
Exceptions:
Caveat:
When a meta_predicate declaration is added, removed or changed, the file containing it, as well as all the modules which import the predicate given by MetaSpec, must be reloaded.
Examples:
See Also:
module/2
Chapter G-13-16

L-3-102: mode/1 declaration

Synopsis:
:-mode(+Mode)
Currently a dummy declaration.
Arguments:
Mode
<term> MOD
Description:

L-3-103: module/1

Synopsis:
module(+ModuleName)
Changes the type-in module (see section G-13-7) to ModuleName. Thus subsequent top-level goals use ModuleName as their source module.
Arguments:
ModuleName
<atom> atom, the name of a module
Description:
Exceptions:
See also:
module/2, current_module/[1,2]

L-3-104: module/2 declaration

Synopsis:
:- module(+ModuleName, +PublicPred).
Declares the file in which the declaration appears to be a module-file named ModuleName, with public predicates PublicPred. Must appear as the first term in the file.
Arguments:
ModuleName
<atom> an atom
PublicPred
<list of simple_pred_spec> List of predicate specifications of the form Name/Arity.
Description:
Exceptions:
At compile time:
See Also:
module/1 Chapter G-13

L-3-105: multifile/1 declaration

Synopsis:
:- multifile +PredSpecs
Allows the clauses for the specified predicates to be in more than one file.
Arguments:
PredSpecs
<pred_spec_forest> A single predicate specification of the form Name/Arity, or a sequence of predicate specifications separated by commas. Name must be an atom and Arity an integer in the range 0..255. MOD
Description:
Exceptions:
See Also:
multifile_assertz/1, source_file/[1,2], compile/1, load_files/[1,2], dynamic/1.

L-3-106: multifile_assertz/1

Synopsis:
multifile_assertz(+Clause)
Adds a compiled clause to the database. The clause will be added at the end of all existing clauses in the database.
Arguments:
Clause
<callable> A valid Prolog clause. MOD
Description:
Exceptions:
See Also:
abolish/[1,2], assertz/1, dynamic/1, multifile/1, Chapter H-1
Chapter H-2

L-3-107: name/2

Synopsis:
name(+Constant, -Chars)
name(-Constant, +Chars)
Chars is the list consisting of the ASCII character codes comprising the printed representation of Constant.
Arguments:
Constant
<atomic>
Chars
<list of char>
Description:
Examples:
Exceptions:
See Also:
Chapter G-9-4

L-3-108: nl/[0,1]

Synopsis:
nl
nl(+Stream)
Terminates the current output record on the current output stream or on Stream.
Arguments:
Stream
<stream_object> (optional) a valid Prolog stream
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
Comments:
See Also:
put/[1,2] flush_output/1.

L-3-109: no_style_check/1

Synopsis:
no_style_check(+Type)
Turns off the specified Type of compile-time style checking.
Arguments:
Type is one of the following atoms:
all
Turn off all style checking.
single_var
Turn off checking for clauses containing a single instance of a named variable, where variables that start with a '_' are not considered named.
discontiguous
Turn off checking for procedures whose clauses are not all adjacent to one another in the file.
multiple
Turn off checking for multiple definitions of the same procedure in different files.
Description:
Exceptions:
See Also:
style_check/1.

L-3-110: nocheck_advice/[0,1]

Synopsis:
nocheck_advice
nocheck_advice(+PredSpecs)
Disable advice checking on all predicates given by PredSpecs.
Arguments:
PredSpecs
<gen_pred_spec_tree> A list of predicate specifications. MOD
Description:
Tips:
nocheck_advice/0 behaves as though implemented by
nocheck_advice :- current_advice(Goal, Port, Action), functor(Goal, Name, Arity), nocheck_advice(Name/Arity), fail. nocheck_advice.
See Also:
add_advice/3, remove_advice/3, current_advice/3, check_advice/[0,1]

L-3-111: nodebug/0

Synopsis:
nodebug
Turns the debugger off. Equivalent to notrace/0.
Description:

L-3-112: nofileerrors/0

Synopsis:
nofileerrors
Disables the 'fileerrors' flag
Description:
Tips:
nofileerrors is a drastic predicate, since it affects the use of all predicates that open files. You might be unintentionally changing the behaviour of calls to open/3 from other parts of the system (written by other people or from libraries). A better way to detect and ignore file errors is to wrap specific calls to open/3 with on_exception/3 and ignore the types of errors you want to ignore.
See Also:
fileerrors/0, prolog_flag/[2,3]

L-3-113: nogc/0

Synopsis:
nogc
Disables the garbage collector.
Description:
As if defined by:

          nogc :- prolog_flag(gc, _, off).

          
See Also:
prolog_flag/[2,3]
Chapter G-12-3

L-3-114: nonvar/1

Synopsis:
nonvar(+Term)
Term is currently instantiated. This is the opposite of var/1.
Arguments:
Term
<term>
Example:
| ?- nonvar([X,Y]). X = _288 Y = _303 | ?- nonvar(X). no
See Also:
atom/1, atomic/1, number/1, var/1, compound/1, callable/1, simple/1

L-3-115: noprofile/0

Synopsis:
noprofile
Turns off the profiler.
Description:
See Also:
profile/[0,1]

L-3-116: nospy/1

Synopsis:
nospy(+PredSpecs)
Removes spypoints on all the predicates represented by PredSpecs.
Arguments:
PredSpecs
<gen_pred_spec_tree> Single predicate specification of form
  • Name
  • Name/Arity
List of predicate specifications
Description:
See Also:
spy/1, nospyall/0, debug/0, add_spypoint/1, remove_spypoint/1

L-3-117: nospyall/0

Synopsis:
nospyall
Removes all spypoints.
Description:
The only way to remove all spypoints at once, since turning off debugging with nodebug/0 does not remove spypoints; they remain in place and are reactivated if the debugger is turned back on using trace/0 or debug/0.
This predicate is not supported in runtime systems. When building a runtime system, qld treats a call to nospyall/0 as it would a call to any other undefined predicate, printing a warning. If it is called during the execution of a runtime system, an existence exception is raised.
See Also:
nospy/1

L-3-118: notrace/0

Synopsis:
notrace
Turns the debugger off. Equivalent to nodebug/0
Description:

L-3-119: number/1

Synopsis:
number(+Term)
Term is currently instantiated to either an integer or a float.
Arguments:
Term
<term>
Examples:
| ?- number(5.2). yes | ?- number(5). yes
See Also:
atom/1, atomic/1, var/1, compound/1, callable/1, nonvar/1, simple/1

L-3-120: number_chars/2

Synopsis:
number_chars(+Number, -Chars)
number_chars(-Number, +Chars)
Chars is the list consisting of the ASCII character codes comprising the printed representation of Number.
Arguments:
Number
<number>
Chars
<list of char>
Description:
Exceptions:
Examples:
| ?- number_chars(foo, L). no | ?- number_chars(431, L). L = [52,51,49] | ?- number_chars(X, [102,111,111]). no | ?- number_chars(X, [52,51,49]). X = 431 | ?- number_chars(X, "15.0e+12"). X = 1.5e+13
See Also:
atom_chars/2

L-3-121: numbervars/3 meta-logical

Synopsis:
numbervars(+-Term, +FirstVar, -LastVar)
instantiates each of the variables in Term to a term of the form '$VAR'(N).
Arguments:
Term
<term>
FirstVar
<integer> Integer
LastVar
<integer>
Description:
Exceptions:
Example:
| ?- Term = foo(A, A, B), numbervars(Term, 22, _), display(Term). foo($VAR(22),$VAR(22),$VAR(23))
See Also:
write_term/1, write_canonical/1

L-3-122: on_exception/3

Synopsis:
on_exception(-Exception, +*ProtectedGoal, +*Handler)
Specify an exception handler for ProtectedGoal, and call ProtectedGoal.
Arguments:
Exception
<term> Any term.
ProtectedGoal
<callable> A goal. MOD
Handler
<callable> A goal. MOD
Description:
ProtectedGoal is executed. This will behave just as if ProtectedGoal had been written without the on_exception/3 wrapper. If ProtectedGoal is determinate, then on_exception/3 will also be determinate. ProtectedGoal can also be non-determinate. As a general rule, code is easier to read when ProtectedGoal is a simple goal, however a conjunction of goals (Goal1,...GoalN) or any other form that call/1 accepts is allowed.
If an exception is raised while ProtectedGoal is running, Prolog will abandon ProtectedGoal entirely. Any bindings made by ProtectedGoal will be undone, just as if it had failed. Side effects, such as data-base changes and input/output, are not undone, just as they are not undone when a goal fails. After undoing the bindings, Prolog then tries to unify an object called an EXCEPTION CODE with the ExceptionCode argument. If this unification succeeds, Handler will be executed as if you had written
              ErrorCode=the actual EXCEPTION CODE,
              Handler

           
If this unification fails, Prolog will keep looking for a handler. It will always find a handler at the top level, which prints out a message corresponding to the exception.
In applications lacking a top level (C calling Prolog, where QP_toplevel() has not been called) exceptions are indicated by the return status QP_ERROR. For more details refer to Chapter I-4.
Exceptions:
Same as call/1.
Tip:
More efficient code is generated when ProtectedGoal is a simple goal. In other cases, such as where ProtectedGoal is a conjunction of goals (Goal1,...GoalN), the compiler treats this as if it were call((Goal1,..., GoalN)). This potential inefficiency does not apply to Handler.
Examples:
Fail on exception:

          :-meta_predicate fail_on_exception/1.
          fail_on_exception(C):-
              on_exception(E,C,print_exception_then_fail(C,E)).

          print_exception_then_fail(C,E):-
              format('Exception occured while calling ~q:~n',
                                                        [C]),
              print_message(warning,E),
              fail.

          
See Also:
raise_exception/1, print_message/2.
Chapter EXCEPTIONHANDLING.

L-3-123: op/3

Synopsis:
op(+Precedence, +Type, +Name)
declares Name to be an operator of the stated Type and Precedence.
Arguments:
Precedence
<integer> integer in the range 1-1200
Type
must be one of the atoms

                            xfx  xfy  yfx  fx  fy  xf  yf

                    
Name
<atom> atom or a list of atoms.
Description:
Operators are a notational convenience to read and write Prolog terms. You can define new operators using op/3.
The Precedence of an operator is used to disambiguate the way terms are parsed. The general rule is that the operator with the highest precedence is the principal functor.
The Type of an operator decides the position of an operator and its associativity. In the atom which represents the type the character f represents the position of the operator. For example, a type fx says that the operator is a prefix operator. The character y indicates that the operator is associative in that direction. For example, an operator of type xfy is a right-associative, infix operator.
To cancel the operator properties of Name (if any) set Precedence to 0.
For more details, see section G-1-4
Exceptions:
See Also:
current_op/3
Chapter G-1-4

L-3-124: open/[3,4]

Synopsis:
open(+FileSpec, +Mode, -Stream)
open(+FileSpec, +Mode, +Options, -Stream)
Creates a Prolog stream by opening the file FileSpec in mode Mode with options Options.
Arguments:
FileSpec
<file_spec> a file specification (Chapter G-6).
Mode
an atom specifying the open mode of the target file. One of:
read
open FileSpec for input.
write
open FileSpec for output. A new file is created if FileSpec does not exist. If the file already exists, then it is set to empty and its previous contents are lost.
append
opens FileSpec for output. If FileSpec already exists, adds output to the end of it. If not, a new file is created.
Options
<list> (optional) a list of zero or more of the following.
text
Specifies that the file stream is a text stream. This sets the line border code to linefeed character, the file border code to -1, and turns on trimming. This is the default.
binary
Specifies that the file stream is a binary stream. This sets the line border code to none, the file border code to -1, the format to variable, and turns off trimming.
record(Size)
Size is a integer value to specify the maximum record (line) size in the file. This also sets the internal buffer size to be used for input/output options on the stream to Size. If Size is 0, the opened stream operates in non-buffered mode. The value of Size should be greater than or equal to 0.
In UNIX, the default is 256 for tty streams and 8192 for other stream.
end_of_line(EolCode)
EolCode is an integer value to specify the line (record) border code for the stream. EolCode is
-1
Indicates there is no line border code.
Charcode
ASCII code for EOL character. Default = linefeed character (ASCII code for linefeed char).
If an output predicate writes out the character whose code is the line border code of the stream, the Prolog system terminates the output record according to the format of the stream.
end_of_file(EofCode)
EofCode is an integer value to specify the file border code for an input stream.
-2
Indicates there is no file border code for the stream. Reading at the end of file is same as reading past end of file.
The file border code is the value to be returned to an input predicate when an input stream reaches the end of file. The default file border code is -1.
eof_action(Action)
Specifies what to do for reading past end of file. This option has no effect on an output stream. Action is one of the following.
error
It's an error to read past end of file. This is the default for text binary streams.
eof_code
Return file border code as set in end_of_file option for reading past end of file.
reset
Reset the stream and make an attempt to read for input past end of file. This is the default for tty stream.
overflow(OvAction)
Specifies what to do when output overflows the current record size. This option has no effect on an input stream. OvAction is one of the following.
error
It's an error.
truncate
Discard the overflow characters.
flush
Write out the overflow partial record (line). No characters are discarded. This is the default on UNIX.
seek(SeekOption)
Request seeking method that will be performed on the file. SeekOption is defined as follows:
error
It's an error to issue a seeking command on the stream. This is the default for a tty stream.
previous
The seeking request will be made only to a previous input/output position. stream_position/3 is the only predicate that can be used to seek on the stream. This is the default for both text and binary streams.
byte
Seeking to an arbitrary byte position on the stream. This option also permits seek(previous). Both stream_position/3 and seek/4 work on the stream.
record
Seeking to the beginning of an arbitrary record in the file stream. This option is not available under UNIX.
flush(FlushType)
Request flushing method for an output stream. This option has no effect on an input stream. It can be one of the following.
error
It's an error to try to flush an output stream.
flush
Write out all the characters buffered. This is the default on UNIX.
trim
Turns on the trimming on the file stream. Trimming means that trailing blanks are deleted in input records. The default is no trimming. See format below.
system(SysAttrs)
This option is provided to allow extensions.
SysAttrs
must be an atom and is passed to the QU_open() function which can be redefined by the user. The default version of QU_open() will report an error, causing an permission_error to be raised, if system(SysAttrs) is specified.
format(Format)
Specifies the file format. For Prolog running under UNIX, the default format is format(delimited(lf)) for text stream, format(variable) for binary stream, and format(delimited(tty)) for tty file. UNIX users will not normally need to use the format(Format) options directly. Format is one of:
variable
Each record in the file has its own length. There are no delimiter characters between records. The Prolog system removes the trailing blank characters for each input record it reads if the trim option is set.
delimited(lf)
a single linefeed character (ASCII code 10) terminates each record in the file.
delimited(tty)
FileSpec is a terminal device, a pseudo-terminal device, or a terminal emulator. The delimiter character depends on the host operating system and the particular tty connected. On UNIX systems, it is the linefeed character.
If one of these delimiters is specified, the Prolog system removes the delimiter characters at the end of record for input. The line border code (specified by end_of_line option) is returned instead as the character code at the end of the record. Prolog system also puts delimiter characters at the end of record when a record is written out.
On UNIX systems, when no format has been specified, the format is decided as follows: if there is no line border code and trimming is off, then format(variable) is used; otherwise format(delimited(lf)) is used.
Stream
<stream_object> the resulting opened Prolog stream.
Description:
Exceptions:
Comments:
Examples:
  1. Opening a stream that behaves like a C standard I/O stream without maintaining correct line count and line position.
    
                         open(FileSpec, Mode, [binary, seek(byte),
                                 eof_action(eof_code)], Stream).
    
                 
  2. opening a non-buffered stream
    
         open(FileSpec, Mode, [record(0)], Stream).
    
                 
  3. On UNIX systems, if FileSpec is /dev/tty, it means that the file is the default tty for the Prolog system. Terminal is used interactively.
See Also:
open_null_stream/1, close/1, QP_prepare_stream/[3,4] QP_fopen(), QP_fdopen(), QU_open()
Chapter I-2-2-3

L-3-125: open_null_stream/1

Synopsis:
open_null_stream(-Stream)
opens an output stream which is not connected to any file and unifies its stream object with Stream.
Arguments:
Stream
<stream_object>
Description:
See Also:
character_count/2, line_count/2, line_position/2

L-3-126: otherwise/0

Synopsis:
otherwise
Always succeeds (same as true/0).
Description:
otherwise/0 is useful for laying out conditionals (see section G-2-7) in a readable way.
Examples:
( test1 -> goal1 | test2 -> goal2 | otherwise -> goal3 )

L-3-127: peek_char/[1,2]

Synopsis:
peek_char(-Char)
peek_char(+Stream, -Char)
looks ahead for next input character on the current input stream or on the input stream Stream.
Arguments:
Stream
<stream_object> a valid Prolog stream.
Char
<char> the resulting next input character available on the stream.
Description:
Example:
<<NEEDS EXAMPLE>> depends on what next char is.]
Exceptions:
Stream errors (see section G-7-6-2), plus:
Comments:
It is safe to call peek_char/[1,2] several times without actually inputting any character. For example:

          | ?- peek_char(X), peek_char(X), get0(X).
          |: a

          X = 97

          
See Also:
get0/[1,2], get/[1,2], open/[3,4]
Chapter G-7

L-3-128: phrase/[2,3]

Synopsis:
phrase(+*PhraseType, +*List)
phrase(+*PhraseType, +*List, *Rest)
Used in conjunction with a grammar to parse or generate strings.
Arguments:
PhraseType
<callable> non-variable, name of a phrase type. MOD
List
<term> a list of symbols -- tokens or character codes.
Rest
<term> a tail of List; what remains of List after PhraseType has been found.
Description:
Exceptions:
Examples:
See example in section G-16-3.
See also:
-->/2, 'C'/3, expand_term/2, term_expansion/2 Chapter G-16

L-3-129: portray/1 hook

Synopsis:
portray(+Term)
A way for the user to over-ride the default behavior of print/1.
Arguments:
Term
<term>
Description:
Tips:
If you define clauses for this hook predicate, it should be declared multifile in each file containing clauses for it. Without this multifile declaration, it will be impossible to use this code with other (possibly library) code that has clauses for this hook.
See Also:
print/1 section G-7-3-5

L-3-130: portray_clause/1

Synopsis:
portray_clause(+Clause)
Writes Clause to the current output stream. Used by listing/[1,2].
Arguments:
Clause
<term>
Description:
Exceptions:
Always succeeds without error.
Example:
| ?- portray_clause((X:- a -> b ; c)). A :- ( a -> b ; c ). X = _3185 | ?- portray_clause((X:- a -> (b -> c ; d ; e); f)). A :- ( a -> ( b -> c ; d ; e ) ; f ). X = _3295 | ?- portray_clause((a:-b)). a :- b. yes | ?- portray_clause((a:-b,c)). a :- b, c. yes | ?- portray_clause((a:-(b,!,c))). a :- b, !, c. yes
See Also:
listing/1, read/[1,2]
section G-7-3-6

L-3-131: predicate_property/2

Synopsis:
predicate_property(*Callable, *PredProperty)
Unifies PredProperty with a predicate property of an existing predicate, and Callable with the most general term that corresponds to that predicate.
Arguments:
Callable
<callable> the skeletal specification (see section G-1-6) of a loaded predicate
PredProperty
<atom> the various properties associated with Callable. Each loaded predicate will have one or more of the properties:
Property
Comments
compiled
can have the 'multifile' property
interpreted
can have either the 'dynamic' or 'multifile' property or both
built_in
multifile
dynamic
exported
on the public predicate list of its source module
imported_from(Module)
imported into the source module from Module )
foreign
meta_predicate(Term)
Term was specified in a meta_predicate declaration. Thus Term consists of the principal functor name followed by mode declarations for its arguments. For example:

                                        mysort(:, +, -)

                                
See section G-13-16 for further information.
volatile
not to be saved in QOF files
locked
not visible in the debugger due to use of -h option to qpc
has_advice
advice has been added for the predicate
checking_advice
advice checking is enabled for the predicate
Description:
Examples:
NOTE: All dynamic predicates are currently interpreted.
See Also:
fileerrors/0, nofileerrors/0, gc/0, compile/1, module/[1,2], foreign/[2,3], meta_predicate/1, volatile/1, add_advice/3, check_advice/[0,1], current_predicate/2
section G-13-13-2

L-3-132: print/1 hookable

Synopsis:
print(+Term)
print(+Stream, +Term)
Writes Term to the current output stream, or Stream. Can be redefined with the hook portray/1.
Arguments:
Stream
<stream_object>
Term
<term>
Description:
Exceptions:
Succeeds without error, except for any errors which may occur in the execution of portray/1.
See Also:
portray/1, library(printchars)

L-3-133: print_message/2 hookable

Synopsis:
print_message(+Severity, +MessageTerm)
Print a Message of a given Severity. The behavior can be customized using the two hooks generate_message_hook/3 and message_hook/3.
Arguments:
Severity
Unless the default system portrayal is overidden with message_hook/3, Severity must be one of
Value
Prefix
informational
%
warning
*
error
!
help
no prefix
silent
no prefix
MessageTerm
<term> any term
Description:
See Also:
message_hook/3, generate_message/3, print_message_lines/3, generate_message_hook/3
Chapter G-20-2

L-3-134: print_message_lines/3

Synopsis:
print_message_lines(+Stream, +Prefix, +Lines)
Print the Lines to Stream, preceding each line with Prefix. Note that print_message_lines/3 only succeeds if Lines is a list of pair.
Arguments:
Stream
<stream_object> Any valid output stream.
Prefix
<term> Any term.
Lines
<term> is of the form [Line1, Line2, ...], where each Linen is of the form [Control_1-Args_1,Control_2-Args_2, ...].
Description:
Exceptions:
Any exception that format/3 might raise.
Examples:
A typical use of this would be when using the user defined predicate, message_hook/3 to redirect output. For example:
message_hook(_,_,Lines):- my_stream(MyStream), print_message_lines(MyStream,'',Lines).
See Also::
message_hook/3, print_message/2, generate_message/3, query_hook/6

L-3-135: profile/[0,1]

Synopsis:
profile
profile(+Goal)
Turns on the profiler and profiles the execution of Goal.
Description:
See Also:
noprofile/0, show_profile_results/[0,1,2]

L-3-136: prolog_flag/[2,3]

Synopsis:
prolog_flag(*FlagName, *Value)
FlagName is a flag which currently is set to Value.
prolog_flag(+FlagName, -OldValue, +NewValue)
Unifies the current value of FlagName with OldValue and then sets the value of the flag to NewValue.
Arguments:
FlagName
<atom>
Value
<atomic>
OldValue
<atomic>
NewValue
<atomic>
Currently, the supported FlagNames and Values for both prolog_flag/2 and prolog_flag/3 are:


               FlagNames        Values
               character_escapes 'on' or 'off'
               debugging         'trace', 'debug', 'zip', or 'off'
               fileerrors        'on' or 'off'
               gc                'on' or 'off'
               gc_margin         non-negative integer
                                 in thousands of bytes
               gc_trace          'on' or 'off'
               unknown           'error' or 'fail'
               syntax_errors     (see section G-19-4-10)

               single_var        'on' or 'off'
               discontiguous\'on' or 'off'
               multiple          'on' or 'off'
          
Values available only to prolog_flag/2 (query-only) are:


               FlagNames        Values
          
add_ons
an atom containing the list of add-on products which are statically linked into the Prolog system. If no add-ons are part of the system, the empty atom '' is returned.
host_type
the host type, which is generally a hardware-operating system combination. This prolog_flag is used to create the system file_search_path/2 facts (see section G-6-1-4, and section G-6-1-5.
quintus_directory
the absolute path of the Quintus directory. The Quintus directory is the root of the entire Quintus installation hierarchy.
runtime_directory
the absolute path of the directory where all the Prolog executables reside.
version
the version of the Prolog being run.
system_type
development, runtime.
Description:
Backtracking:
prolog_flag/2 enumerates all valid flagnames of a given current value, or all pairs of flags and their current values. It is not a way to find out non-current values for a flag.
Exceptions:
See Also:
gc/0, nogc/0, style_check/1, no_style_check/1, unknown/2, fileerrors/0, nofileerrors/0
Chapter G-10

L-3-137: prolog_load_context/2

Synopsis:
prolog_load_context(+Key, -Value)
prolog_load_context(*Key, *Value)
Finds out the context of the current load.
Arguments:
Key
<term>
Value
<atom>
Description:
You can call prolog_load_context/2 from an embedded command or by term_expansion/2 to find out the context of the current load. If called outside the context of a load, it simply fails.
Key
Value
module
the module you are compiling into
file
absolute filename of the file being compiled
stream
the stream you are compiling from
directory
directory of the file on which the stream is open
term_position
a stream position object referring to the position of the clause just read
Backtracking:
This predicate is meant to be used in the mode (+, -), but it is also possible to backtrack through it.
See Also:
load_files/[1,2]
Chapter G-10

L-3-138: prompt/[2,3]

Synopsis:
prompt(-OldPrompt, +NewPrompt)
prompt(+Stream, -OldPrompt, +NewPrompt)
Queries or changes the prompt string of the current input stream or an input stream Stream.
Arguments:
Stream
<stream_object> a valid Prolog input stream.
OldPrompt
<atom> the old prompt atom of the stream.
NewPrompt
<atom> the new prompt atom of the stream.
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
Comments:
See Also:
QP_add_tty(), read/[1,2], read_term/[2,3], get/[1,2], get0/[1,2] Chapter I-5

L-3-139: public/1 declaration

Synopsis:
public+Term
Dummy declaration for backwards compatibility.
Arguments:
Term
<term> MOD

L-3-140: put/[1,2]

Synopsis:
put(+Char)
put(+Stream, +Char)
Evaluates the integer expression Char, and writes the lower 8-bits to the current output stream or to Stream.
Arguments:
Stream
<stream_object> a valid Prolog output stream
Char
<expr> a legal character code or an integer expression. An useful form of integer expression for this argument is a single character following 0', such as 0'a, 0'b, etc.
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
See Also:
nl/[0,1], skip_line/[0,1], open/[3,4]
Chapter G-7

L-3-141: query_abbreviation/3 extendable

Synopsis:
query_abbreviation(+Tag, -Prompt, -Pairs)
A way to specify one letter abbreviations for responses to queries from the Prolog System.
Arguments:
Tag
<atom> This indicates which query type.
Prompt
<atom> An atom indicating appropriate abbreviations.
Pairs
<a list of pairs> A list of word-abbreviation pairs.
Description:
Prolog only asks for keyboard input in a few different ways. These are enumerated in the clauses for query_abbreviation/3 in the module messages(language(('QU_messages'))). These clauses specify valid abbreviations for a given key word. For example,
query_abbreviation(yes_or_no,'(y/n)',[yes-"yY",no-"nN"]).
a French translator might decide that the letters 'O' and 'o' are reasonable abreviations for 'oui' (yes), and therefore write
query_abbreviation(yes_or_no,'(o/n)',[yes-"oO",no-"nN"]).
For an example of how this is used with query_hook/6, see the reference page for query_hook_example.
See Also::
section G-20-3-4, and the reference page for query_hook/6

L-3-142: query_hook/6 hook

Synopsis:
query_hook(+QueryClass, +Prompt, +PromptLines, +Help, +HelpLines, -Answer)
Provides a method of overriding Prolog's default keyboard based input requests. The query hook is used by the Quintus User Interface.
Arguments:
QueryClass
determines the allowed values for the atom Answer.
If QueryClass is:
Answer must be:
yes_or_no(Question)
yes or no.
toplevel
yes or no
yes_no_proceed
yes, no, or proceed.
Prompt
<list of pair> A message term.
PromptLines
<list of pair> The message generated from the Prompt message term.
Help
<term> A message term.
HelpLines
<list of pair> The message generated from the Help message term.
Answer
see QueryClass
Description:
This provides a way of overriding Prolog's default method of interaction. If this predicate fails, Prolog's default method of interaction is invoked.
The default method first prints out the prompt, then if the response from the user is not one of the allowed values, the help message is printed.
It is useful to compare this predicate to message_hook/3, since this explains how you might use the Prompt, PromptLines, Help, HelpLines.
Exceptions:
An exception raised by this predicate causes an error message to be printed and then the default method of interation is invoked. In other words, exceptions are treated as failures.
Examples:
If Prolog is looking for a yes-no response to one question `Done?', as in the toplevel, this request for input can be captured

          query_hook(toplevel,_,_,_,_,Answer):-
              my_yes_no('Done?',Answer).

           
where my_yes_no/2 binds Answer to either yes or no.
Here is roughly how the default method works. Notice the interaction with query_abbreviation/3.


          


          query_hook(QueryClass,_,PromptLines,_,HelpLines,Answer):-
              'QU_messages':query_abbreviation(QueryClass,
                                               AbbreviationPrompt,
                                               Pairs),
              repeat,
                  (   print_message_lines(user_output,'',PromptLines),
                      (   AbbreviationPrompt == ''
                      ->  write(Stream,' ')
                      ;   format(Stream,' ~w ',[AbbreviationPrompt])
                      ),
                      flush_output(Stream),
                      get0(C),
                      member(Answer-Abrv,Pairs),
                      member(C,Abrv),
                      !
                  ;   print_message_lines(Stream,'',HelpLines),
                      fail
                  ).

          
Tips:
If you define clauses for this hook predicate, it should be declared multifile in each file containing clauses for it. Without this multifile declaration, it will be impossible to use this code with other (possibly library) code that has clauses for this hook.
See Also:
query_abbreviation/3, message_hook/3, print_message_lines/3
Chapter G-20

L-3-143: raise_exception/1

Synopsis:
raise_exception(+Exception)
Raise an exception (that might be intercepted by on_exception/3).
Arguments:
Exception
<nonvar> Any term.
Description:
A call to raise_exception/1 can never backtrack, fail or succeed. Rather, raise_exception/1 searches for an ancestor of the current goal, ProtectedGoal, which is of the form:
on_exception(E,ProtectedGoal,Handler)
The first argument, E, unifies with Exception. It then executes the Handler instead of the ProtectedGoal. It will always find a handler at the top level, which prints out a message corresponding to the exception. See section G-20-2 for a discussion on how exceptions are printed.
Exceptions:
See Also:
on_exception/3.
Chapter G-19

L-3-144: read/[1,2]

Synopsis:
read(-Term)
read(+Stream, -Term)
Reads the next term from the current input stream or Stream and unifies it with Term.
Arguments:
Stream
<stream_object> a valid Prolog stream which is open for input
Term
<term> the term to be read
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
See Also:
read_term/[2,3], prompt/[2,3]
Chapter G-1-7

L-3-145: read_term/[2,3]

Synopsis:
read_term(+Options, -Term)
read_term(+Stream, +-Options, -Term)
Read a term from the current input stream or from Stream, optionally returning extra information about the term.
Arguments:
Stream
<stream_object> A valid Prolog stream which is open for input
Term
<term> the term that is read
Options
<list of term> a list of zero or more of the following:
syntax_errors(Val)
Val must be bound to one of the following, indicating what should be done when a syntax error is found:
quiet
nothing is printed, and read_term/[2,3] fails
dec10
a syntax error message is printed, and read_term/[2,3] tries to read the next term (this is compatible with DEC-10 Prolog and previous versions of Quintus Prolog)
fail
a syntax error message is printed, and read_term/[2,3] fails
error
an exception is raised.
The default value if this option is not specified is the current value of the syntax_errors prolog flag. The default value for this flag is dec10. See prolog_flag/2 for more information on these flags.
variable_names(Names)
On completion, Names is bound to a list of Name=Var pairs, where each Name is an atom indicating the spelling of the name of a variable in the term just read, and Var is the corresponding variable. Note that anonymous variables, written as _, are not included in this list.
singletons(Singletons)
On completion, Singletons is bound to a list of Name=Var pairs, one for each variable only appearing once in the term. Anonymous variables are not included on this list.
term_position(Position)
On completion, Position is the position of the start of the actual term, as might be returned by stream_position/2. Any white space and comments before the actual term are not reflected by the position. To find the position of the end of the term, you need only call stream_position/2; it will give you the position of the first character after the period ending the term.
subterm_positions(PositionTerm)
On completion, PositionTerm is bound to a position term that describes the position of the term just read and all of its subterms. A position term is of one of the forms listed below. In all these forms, Start and End are the character positions of first character of the term and the character following the last character of the term, respectively. Similarly FStart and FEnd specify the start and end of the principle functor of the term. Note that the positions are character positions, not position terms as returned by stream_position/2.
Start-End
The term corresponding to this position term is either atomic or a variable. Start and End are the character positions of the first character of the term and the character following the last character of the term, respectively.
list_position(Start,End,Elts,Tail)
The term corresponding to this position term is a list which was written using bracket notation (for example, [a,list]). Elts is a list of position terms for each proper element of the list. Tail is the position of the tail of the list (the part following the |), or the atom 'none' if the list has no tail part.
string_position(Start,End)
The term corresponding to this position term is a list of character codes written as a quoted string (for example, "a string"). The positions specified include the quote characters.
brace_term_position(Start,End,Arg)
The term corresponding to this position term is of the form {X}. Arg is a position term describing the argument of this term.
term_position(Start,End,FStart,FEnd,Args)
The term corresponding to this position term is a compound term not specifically mentioned above. This includes terms written with operators. Args is a list of position terms, one for each argument of the term.
Exceptions:
Examples:
| ?- read_term([variable_names(L)], T). |: append([U|X],Y,[U|Z]) :- append(X,Y,Z). L = ['U'=_1988,'X'=_2003,'Y'=_2020,'Z'=_2046], T = (append([_1988|_2003],_2020,[_1988|_2046]):- append(_2003,_2020,_2046)) | ?- read_term([subterm_positions(P)], T). |: foo+bar+baz. P = term_position(1642,1653,1649,1650, [term_position(1642,1649,1645,1646, [1642-1645,1646-1649]), 1650-1653]), T = foo+bar+baz
See Also:
read/[1,2], prompt/[2,3] prolog_flag/[2,3]
Chapter G-7

L-3-146: reconsult/1

Synopsis:
reconsult(+Files)
Same as compile/1
Arguments:
Files
file_spec or <list of file_spec> MOD

L-3-147: recorda/3

Synopsis:
recorda(+Key, +Term, -Ref)
records the Term in the internal database as the first item for the key Key; a database reference to the newly-recorded term is returned in Ref.
Arguments:
Key
<atomic>
Term
<term>
Ref
<db_reference>
Description:
Exceptions:
See Also:
recorded/3, recordz/3, current_key/2
Chapter G-14

L-3-148: recorded/3

Synopsis:
recorded(-Key, -Term, +Ref)
recorded(+Key, *Term, *Ref)
searches the internal data base for a term recorded under the key Key which unifies with Term, and whose data base reference unifies with Ref.
Arguments:
Key
<atomic>
Term
<term>
Ref
<db_reference>
Description:
Backtracking:
Can be used to backtrack through all the matching terms recorded under the specified key. Therefore, if you want to match only a single term you should use a cut to prevent backtracking. Alternatively, use the library(not) predicate, once/1.
Exceptions:
See Also:
record/3, recorda/3, current_key/3

L-3-149: recordz/3

Synopsis:
recordz(+Key, +Term, -Ref)
Records the term Term in the internal data base as the last item for the key Key; a data base reference to the newly-recorded term is returned in Ref.
Arguments:
Key
<atomic>
Term
<term>
ref
<db_reference>
Exceptions:
See Also::
recorded/3, recorda/3, current_key/2

L-3-150: remove_advice/3

Synopsis:
remove_advice(+Goal,+*Port,+*Action)
remove the association of an action with entry to a port of a procedure. remove_advice/3 will only succeed when Port is var or one of {call, exit, done, redo, fail}, and Action is var or callable.
Arguments:
Goal
<callable> a term to be unified against a calling goal of existing advice. MOD
Port
<term> any term.
Action
<term> any term. MOD
Description:
See Also:
add_advice/3, current_advice/3, check_advice/[0,1], nocheck_advice/[0,1]

L-3-151: remove_spypoint/1

Synopsis:
remove_spypoint(+Spyspec)
removes a spypoint from the specified predicate or call.
Arguments:
Spyspec
<compound> a specification of an individual spypoint. Two forms of spyspec are allowed:
predicate(Pred)
A spypoint on any call to Pred. Pred must be a skeletal predicate specification, and may be module qualified.
call(Caller,Clausenum,Callee,Callnum)
A spypoint on the Callnum call to Callee in the body of the Clausenum clause of Caller. Callee and Callnum must be skeletal predicate specifications. Callnum and Clausenum must be integers, and begin counting from 1. Note that Callnum specifies a lexical position, that is, the number of the occurrence of Callee counting from the beginning of the body of the clause, and ignoring any punctuation.
Description:
This predicate is not supported in runtime systems. When building a runtime system, qld treats a call to remove_spypoint/1 as it would a call to any other undefined predicate, printing a warning. If it is called during the execution of a runtime system, an existence exception is raised.
See Also:
current_spypoint/1, add_spypoint/1, spy/1, nospy/1, debugging/0
Chapter E-1

L-3-152: repeat/0

Synopsis:
repeat
Succeeds immediately when called and whenever reentered by backtracking.
Description:
Tips:
Examples:

repeat/0 could have been written in Prolog as follows:


                  repeat.
                  repeat :- repeat.

          

L-3-153: restore/1

Synopsis:
restore(+FileSpec)
Restores a saved-state.
Arguments:
FileSpec
<file_spec> The name of a QOF file.
Description:
Exceptions:
See Also:
load_files/[1,2], save_modules/2, save_predicates/2, save_program/[1,2]
Chapter G-5

L-3-154: retract/1

Synopsis:
retract(+*Clause)
Removes the first occurrence of dynamic clause Clause from module M.
Arguments:
Clause
<callable> A valid Prolog clause. MOD
Description:
Exceptions:
See Also::
abolish/[1,2], assert/1, dynamic/1, erase/1, retractall/1.

L-3-155: retractall/1

Synopsis:
retractall(+Head)
Removes every clause in module M whose head matches Head.
Arguments:
Head
<callable> Head of a Prolog clause. MOD
Description:
Exceptions:
See Also:
abolish/[1,2], assert/1, dynamic/1, erase/1, retract/1
Chapter G-14

L-3-156: runtime_entry/1 hook

Synopsis:
runtime_entry(+Event)
This predicate is called upon start-up and exit of stand alone applications.
Arguments:
Event
one of {start, abort}
Description:
See Also:
QP_toplevel()
section I-2-2-1

L-3-157: save_modules/2

Synopsis:
save_modules(+Modules, +File)
Saves all predicates in Modules in QOF format to File.
Arguments:
Modules
atom or <list of atom> An atom representing a current module, or a list of such atoms representing a list of modules.
File
<file_spec> An atom representing a file name
Description:
Exceptions:
See Also::
load_files/1, save_predicates/2, save_program/1, volatile/1

L-3-158: save_predicates/2

Synopsis:
save_predicates(+PredSpecs, +File)
Saves the predicates specified by the PredSpecs in QOF format to File.
Arguments:
PredSpecs
<pred_spec_tree> A list of predicate specifications. MOD
File
<file_spec> An atom representing a file name
Description:
Exceptions:
See Also::
load_files/1, save_modules/2, save_program/1, volatile/1

L-3-159: save_program/[1,2]

Synopsis:
save_program(+File)
save_program(+File, +Goal)
Saves the state of the current execution in QOF format to File. A goal, Goal, to be called upon execution/restoring of the saved state, may be specified.
Arguments:
File
<file_spec> An atom representing a file name.
Goal
<callable> A goal.
Description:
Exceptions:
See Also:
load_files/[1,2], restore/1, save_modules/2, save_predicates/2, volatile/1
Chapter G-5

L-3-160: see/1

Synopsis:
see(+FileOrStream)
Makes file FileOrStream the current input stream.
Arguments:
FileOrStream
file_spec or <stream_object> File specification or stream object.
Description:
Exceptions:
See Also:
seen/0, close/1, abort/0, seeing/1
Chapter G-7-6-4

L-3-161: seeing/1

Synopsis:
seeing(-FileOrStream)
Unifies FileOrStream with the current input stream or file.
Arguments:
FileOrStream
file_spec or <stream_object>
Description:
See Also:
see/1, open/[3,4], current_input/1

L-3-162: seek/4

Synopsis:
seek(+Stream, +Offset, +Method, -NewLocation)
Seeks to an arbitrary byte position in Stream.
Arguments:
Stream
<stream_object> a valid Prolog stream
Offset
<integer> the offset in bytes to seek relative to Method specified.
Method
specifies where to start seeking. It is one of the following.
bof
Seek from beginning of the file stream.
current
Seek from current position of the file stream.
eof
Seek from end of the file stream.
NewLocation
<integer> The byte offset from beginning of the file after seeking operation.
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
See Also:
stream_position/[2,3], open/4, character_count/2, line_count/2, line_position/2.
Chapter G-7

L-3-163: seen/0

Synopsis:
seen
Closes the current input stream.
Description:
See Also:
close/1

L-3-164: set_input/1

Synopsis:
set_input(+Stream)
makes Stream the current input stream.
Arguments:
Stream
<stream_object> a valid input stream
Exceptions:
Stream errors (see section G-7-6-2), plus:
See Also:
read/1, get/1

L-3-165: set_output/1

Synopsis:
set_output(+Stream)
makes Stream the current output stream.
Arguments:
Stream
<stream_object> a valid output stream
Description:
Subsequent output predicates such as write/1 and put/1 will use this stream.
Exceptions:
Stream errors (see section G-7-6-2), plus:
See Also::
write/1, put/[1,2]

L-3-166: setof/3

Synopsis:
setof(+Template, +*Generator, *Set)
Returns the set Set of all instances of Template such that Generator is provable.
Arguments:
Template
<term>
Generator
<callable> a goal to be proved as if by call/1. MOD
Set
<list of term> non-empty set
Description:
Examples:
See findall/3 for examples that illustrate the differences among findall/3, setof/3, and bagof/3.
Exceptions:
As for call/1:
See Also:
bagof/3, ^/2
Chapter G-15

L-3-167: show_profile_results/[0,1,2]

Synopsis:
show_profile_results
show_profile_results(+By)
show_profile_results(+By,+Num)
Displays the results of the last profiled execution.
Arguments:
By
<atom> must be one of the atoms

                          by_time  by_choice_points
                          by_calls by_redos

                  
Num
<integer>
Description:
Example:
| ?- show_profile_results(by_time, 3). Proc Calls ChPts Redos Time % Caller(proc,cl#,cll#,%) user:setof/3 227 0 0 2.04 34.0 user:satisfy/1,6,1 152 61.0 user:seto/3,1,1 48 20.0 user:satisfy/1,7,1 27 17.0 user:satisfy/1 35738 36782 14112 0.32 5.3 user:satisfy/1,1,2 13857 43.0 user:satisfy/1,2,1 12137 31.0 user:satisfy/1,1,1 7315 18.0 user:satisfy/1,3,1 1155 6.0 user:inv_map_l/5 4732 4732 3115 0.20 3.3 user:inv_map_l/5,2,1 3115 60.0 user:inv_map/4,5,1 1617 40.0
See Also:
profile/[0,1], get_profile_results/4, noprofile/0

L-3-168: simple/1 meta-logical

Synopsis:
simple(+Term)
Term is currently instantiated to either an atom, a number, a data base or a variable.
Arguments:
Term
<term>
Examples:
| ?- simple(9). yes | ?- simple(_X). _X = _2487 | ?- simple("a"). no
See Also:
atom/1, number/1, var/1, compound/1, callable/1, nonvar/1

L-3-169: skip/[1,2]

Synopsis:
skip(+Char)
skip(+Stream, +Char)
Skips over characters from the current input stream, or Stream, through the first character whith an ASCII code that match the lower 8-bits of the value of the integer expression Char.
Arguments:
Stream
<stream_object>
Char
<expr> an integer expression.
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
See Also:
tab/1

L-3-170: skip_line/[0,1]

Synopsis:
skip_line
skip_line(+Stream)
Skip the remaining input characters on the current line on the current input stream, or on Stream.
Arguments:
Stream
<stream_object> a valid Prolog input stream
Exceptions:
Comments:
Coding with skip_line/[0,1] and at_end_of_line/[0,1] to handle line input is more portable among different operating systems than checking end of line by the input character code.
See Also:
get0/[1,2], at_end_of_line/[0,1], at_end_of_file/[0,1].

L-3-171: sort/2

Synopsis:
sort(+List1, -List2)
Sorts the elements of the list List1 into the ascending standard order, and removes any multiple occurrences of an element. The resulting sorted list is unified with the list List2.
Arguments:
List1
<list of term>
List2
<list of term>
Examples:
| ?- sort([a,X,1,a(x),a,a(X)], L). L = [X,1,a,a(X),a(x)] (The time taken to do this is at worst order (N log N) where N is the length of the list.)
Exceptions:
See Also:
keysort/2 Chapter G-9-7-2

L-3-172: source_file/[1,2,3]

Synopsis:
source_file(+AbsFile)
source_file(*AbsFile)
source_file(*Pred, *AbsFile)
source_file(*Pred, *ClauseNumber, *AbsFile)
AbsFile is the absolute name of a loaded file, and ClauseNumber is the number of a clause for Pred in that file.
Arguments:
AbsFile
<atom> absolute file name
Pred
<callable> selected predicate specification. MOD
ClauseNumber
<integer> integer representing clause number
Description:
Backtracking:
See Also:
absolute_file_name/[2,3], multifile/1

L-3-173: spy/1

Synopsis:
spy(+PredSpecs)
Sets spypoints on all the predicates represented by PredSpecs
Arguments:
PredSpecs
<gen_pred_spec_tree> Single predicate specification of form MOD
  • Name
  • Name/Arity
List of predicate specifications
Description:
See Also:
nospy/1, nospyall/0, debug/0, current_spypoint/1, add_spypoint/1, remove_spypoint/1

L-3-174: statistics/[0,2]

Synopsis:
statistics
Displays statistics relating to memory usage and execution time.
statistics(+Keyword, -List)
statistics(*Keyword, *List)
Obtains individual statistics.
Arguments:
Keyword
<atom> atom - keyword such as 'runtime'
List
<list of integer> list of statistics (see Example)
__________ Keyword List Times are given in milliseconds and sizes are given in bytes. runtime [cpu time used by Prolog, cpu time since last call to statistics/[0,2](in millisecs)] system_time [cpu time used by the operating system, cpu time used by the system since the last call to statistics/2] real_time [wall clock time since 00:00 GMT 1/1/1970, wall clock time since the last call to statistics/2] memory [total virtual memory in use, total virtual memory free] stacks [total global stack memory, total local stack memory] program [program space, 0] global_stack [global stack in use, global stack free] local_stack [local stack in use, local stack free] trail [size of trail, 0] garbage_collection [number of GCs, freed bytes, time spent] stack_shifts [number of global stack area shifts, number of local stack area shifts, time spent shifting] atoms [number of atoms, atom space in use, atom space free] atom_garbage_collection [number of AGCs, freed bytes, time spent] core (same as memory) heap (same as program) __________
Description:
statistics/0 displays various statistics relating to memory usage, runtime and garbage collection, including information about which areas of memory have overflowed and how much time has been spent expanding them.
Garbage collection statistics are initialized to zero when a Prolog session starts (this includes sessions started from saved-states created by save_program/[1,2], and includes re-starts caused when restore/1 is used). The statistics increase until the session is over.
statistics/2 is usually used with Keyword instantiated to a keyword such as 'runtime' and List unbound. The predicate then binds List to a list of statistics related to the keyword. It can be used in programs which depend on current runtime statistical information for their control strategy, and in programs which choose to format and write out their own statistical summaries.
If keyword is 'garbage_collection' the list returned contains three elements:
Examples:
The output from statistics/0 looks like this:

__________
memory (total)     377000 bytes: 350636 in use,  26364 free
   program space   219572 bytes
      atom space    (2804 atoms)  61024 in use,  43104 free
   global space     65532 bytes:   9088 in use,  56444 free
      global stack   6984 bytes
      trail                          16 bytes
      system                       2088 bytes
   local stack      65532 bytes:    356 in use,  65176 free
      local stack                   332 bytes
      system                         24 bytes

 0.000 sec. for 0 global and 0 local space shifts
 0.000 sec. for 0 garbage collections
                  which collected 0 bytes
 0.000 sec. for 0 atom garbage collections
                  which collected 0 bytes
 0.233 sec. runtime
__________

          
To report information on the runtime of a predicate p/0, add the following to your program:

          :- statistics(runtime, [T0|_]),
             p,
             statistics(runtime, [T1|_]),
             T is T1 - T0,
             format('p/0 took ~3d sec.~n', [T]).

          
See Also:
Chapter DISPLAYINGSTATISTICS

L-3-175: stream_code/2

Synopsis:
stream_code(-Stream, +CStream)
stream_code(+Stream, -CStream)
Converts between Prolog representation, Stream, and C representation, CStream, of a stream.
Arguments:
Stream
<stream_object> a variable or a valid Prolog stream
CStream
<integer> a variable or a valid C stream
Description:
Exceptions:
Comments:
The most frequent use of stream_code/2 is to get a stream value to be used in Prolog code for a stream created in foreign code. This is necessary when a desired stream can not be obtained through open/[3,4]; e.g., a stream referring to a socket or an encrypted file.
See Also::
open/[3,4], QP_fopen(), QP_fdopen()

L-3-176: stream_position/[2,3]

Synopsis:
stream_position(+Stream, -Current)
True when Current represents the current position of Stream.
stream_position(+Stream, -Current, +New)
Unifies the current position of the read/write pointer for Stream with Current, then sets the position to New.
Arguments:
Stream
<stream_object> an open stream
Current
<term> stream position object representing the current position of Stream.
New
<term> stream position object
Caution:
A stream position object is represented by a special Prolog term. The only safe way of obtaining such an object is via stream_position/3 or stream_position/2. You should not try to construct, change, or rely on the form of this object. It may vary under different operating systems and/or change in subsequent versions of Quintus Prolog. On some systems, a stream position object currently has the form:

'$stream_position'(CharCount, LineCount, LinePos, Magic1,
                   Magic2)

          
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
Example:
To find the current position of a stream without changing it, one can ask

                  | ?- stream_position(Stream, Current).

          
See Also:
seek/4, open/[3,4], character_count/2, line_count/2, line_position/2. Chapter G-7

L-3-177: style_check/1

Synopsis:
style_check(+Type)
Turns on the specified Type of compile-time style checking.
Arguments:
Type is one of the following atoms:
all
Turn on all style checking.
single_var
Turn on checking for clauses containing a single instance of a named variable, where variables that start with a '_' are not considered named.
discontiguous
Turn on checking for procedures whose clauses are not all adjacent to one another in the file.
multiple
Turn on checking for multiple definitions of the same procedure in different files.
Description:
Exceptions:
See Also:
no_style_check/1.

L-3-178: subsumes_chk/2

Synopsis:
subsumes_chk(+General, +Specific)
True when General subsumes Specific; that is, when Specific is an instance of General.
Arguments:
General
<term>
Specific
<term>
Description:
Comments:
There are two other related predicates defined in library(subsumes), subsumes/2 and variant/2. These predicates are defined in terms of subsumes_chk/2, and they are still available in that library package.
See Also:
library(subsumes), library(occurs)

L-3-179: tab/[1,2]

Synopsis:
tab(+Integer)
tab(+Stream, +Integer)
Writes Integer spaces to the current output stream, or Stream.
Arguments:
Stream
<stream_object>
Integer
<expr> an integer expression.
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
See Also:
ttyflush/0

L-3-180: tell/1

Synopsis:
tell(+FileOrStream)
makes FileOrStream the current output stream.
Arguments:
FileOrStream
file_spec or <stream_object> file specification or, stream object.
Description:
Exceptions:
See Also:
told/0, telling/1

L-3-181: telling/1

Synopsis:
telling(-FileOrStream)
Unifies FileOrStream with the current output stream.
Arguments:
FileOrStream
file_spec or <stream_object>
Description:
Examples:
See Also:
tell/1, open/[3,4], current_output/1

L-3-182: term_expansion/2 hook

Synopsis:
term_expansion(+Term1, -Term2)
The user may override the standard transformations to be done by expand_term/2 by defining clauses for term_expansion/2.
Arguments:
Term1
<term>
Term2
<term>
Description:
Tip:
If you define clauses for this hook predicate, it should be declared multifile in each file containing clauses for it. Without this multifile declaration, it will be impossible to use this code with other (possibly library) code that has clauses for this hook.
See Also:
expand_term/2, -->/2, phrase/[2,3], 'C', prolog_load_context/2. Chapter G-16

L-3-183: told/0

Synopsis:
told
Closes the current output stream.
Description:

L-3-184: trace/0

Synopsis:
trace
Turns the debugger on and starts it creeping; that is, it sets the debugger to trace mode.
Description:
See Also:
debug/0, notrace/0

L-3-185: trimcore/0

Synopsis:
trimcore/0
Force reclamation of memory in all of Prolog's data areas.
Description:
Reduces the free space in all the data areas as much as possible, and gives the space no longer needed back to the operating system.
Exceptions:
Automatically called after each directive at the top level.
See Also:
Chapter G-12-1-1

L-3-186: true/0

Synopsis:
true
Always succeeds. This could have been trivially defined in Prolog by the single clause:

                  true.

          

L-3-187: ttyflush/0, ttyget/1, ttyget0/1, ttynl/0, ttyput/1, ttyskip/1, ttytab/1

Synopsis:
ttyflush Equivalent to flush_output(user).
ttyget(-Char) Equivalent to get(user, Char).
ttyget0(-Char) Equivalent to get0(user, Char).
ttynl Equivalent to nl(user).
ttyput(+Char) Equivalent to put(user, Char).
ttyskip(+Char) Equivalent to skip(user, Char).
ttytab(+Integer) Equivalent to tab(user, Integer).
Arguments:
Char
<char>
Integer
<expr>
Description:

L-3-188: unix/1

Synopsis:
unix(shell(+UnixCommand)) Spawns a unix shell and executes UnixCommand.
unix(system(+UnixCommand)) Spawns a unix sh(1) process and executes UnixCommand.
unix(system(+UnixCommand, -Status)) Spawns a unix sh(1) process and executes UnixCommand. The exit status of the executed command is returned in Status.
unix(cd(+Path)) Changes working directory to Path.
unix(argv(-ArgList)) Returns in ArgList the list of commandline arguments as Prolog objects.
unix(args(-ArgList)) Returns in ArgList the list of commandline arguments as a list of atoms.
Arguments:
UnixCommand
<term> atom corresponding to a unix command (or null) Status exit status of the unix command executed
Path
atom corresponding to a legal directory (or null)
ArgList
list of arguments used to start up current session.
Description:
Exceptions:
Examples:
See Also:
QP_initialize(), QP_toplevel(), system/1 -- from library(strings)
Chapter G-18

L-3-189: unknown/2

Synopsis:
unknown(-OldAction, +NewAction)
Unifies OldAction with the current action on unknown procedures, and then sets the current action to NewAction.
Arguments:
OldAction
one of {error, fail}
NewAction
one of {error, fail}
Description:
See Also:
unknown_predicate_handler/3

L-3-190: unknown_predicate_handler/3 hook

Synopsis:
unknown_predicate_handler(+Goal, +Module, -NewGoal)
User definable hook to trap calls to unknown predicates
Arguments:
Goal
<callable> Any Prolog term
Module
<atom> Any atom that is a current module
NewGoal
<callable> Any callable Prolog term
Description:
When Prolog comes across a call to an unknown predicate and the unknown flag is set to 'error', Prolog makes a call to unknown_predicate_handler/3 in module user with the first two arguments bound. Goal is bound to the call to the undefined predicate and Module is the module in which that predicate is supposed to be defined. If the call to unknown_predicate_handler/3 succeeds then Prolog replaces the call to the undefined predicate with the call to NewGoal. By default NewGoal is called in module user. This can be overridden by making NewGoal have the form Module:SomeGoal.
Examples:
Tips:
If you define clauses for this hook predicate, it should be declared multifile in each file containing clauses for it. Without this multifile declaration, it will be impossible to use this code with other (possibly library) code that has clauses for this hook.
See Also:
unknown/2, prolog_flag/3

L-3-191: use_module/[1,2,3]

Synopsis:
use_module(+Files)
Loads the module file(s) Files, if not already loaded and up-to-date imports all exported predicates.
use_module(+File, +Imports)
Loads module file File, if not already loaded and up-to-date imports according to Imports.
use_module(+Module, -File, +Imports)
Module is already loaded and up-to-date. Imports according to Imports.
use_module(-Module, +File, +Imports)
Module has not been loaded, or is out-of-date. Loads Module from File and imports according to Imports.
Arguments:
File
<file_spec> or <list of file_spec> Any legal file specification. Only use_module/1 accepts a list of file specifications. A ".pl" or ".qof" extension may be omitted in a file specification. MOD
Imports
<list of simple_pred_spec> A list of predicate specifications in the Name/Arity form to import into the calling module
all
all predicates exported by the module are to be imported.
Module
<atom> The module name in Files, or a variable, in which case the module name is returned.
Description:
Exceptions:
See Also:
compile/1, ensure_loaded/1, initialization/1, load_files/[1,2], volatile/1,
Chapter G-4, Chapter G-6

L-3-192: user_help/0 hook

Synopsis:
user_help
A hook for users to add more information when help/0 is called.
Description:
Useful when you want a standard way to tell users something, like how to run a demo.
help/0 always calls user_help/0 in module 'user'. Therefore, to be visible to help/0, user_help/0 must either be defined in or imported into module 'user'.
Example:
The common test harness for many Quintus test suites includes the clause:


user_help :-
  suite_type(_,Type), suite_host(Host),
  write('You have loaded the Quintus test suite for '),
  write(Type), write(' on '), write(Host), nl, nl,
  write('You can invoke the suite as follows:'), nl, nl,
  write(' ?- quiet.               % run suite, concise output'), nl,
  write(' ?- verbose.             % run suite, verbose output'), nl,
  write(' ?- quiet(+Pred).        % run suite, concise output for'), nl,
  write('                         % tests of predicate Pred'), nl,
  write(' ?- quiet(+Pred, +N).    % similar to above, but runs the'),nl,
  write('                         %  test specified by N'), nl,
  write(' ?- verbose(+Pred).      % run suite, verbose output for'), nl,
  write('                         %  tests of predicate Pred'), nl,
  write('                         %  (Pred a name, NOT name/arity!'),nl,
  write(' ?- verbose(+Pred, +N).  % similar to above, but runs the'),nl,
  write('                         %  test specified by N'), nl,
  write(' ?- help.                % to get this message'), nl.

So if you compile the Prolog, C, Pascal or FORTRAN suites, you have a consistent help message telling you how to run the suites:
<run prolog> <compile /ptg/suite/plsuite.pl> | ?- help.
If You have loaded the Quintus test suite for Prolog on Sun ??? You can invoke the suite as follows:
?- quiet. % run suite, concise output ?- verbose. % run suite, verbose output ?- quiet(+Pred). % run suite, concise output for % tests of predicate Pred ?- quiet(+Pred, +N). % similar to above, but runs the % test specified by N ?- verbose(+Pred). % run suite, verbose output for % tests of predicate Pred % (Pred a name, NOT name/arity! ?- verbose(+Pred, +N). % similar to above, but runs the % test specified by N ?- help. % to get this message
See Also:
help/1 Chapter G-17

L-3-193: var/1 meta-logical

Synopsis:
var(+Term)
Term is currently uninstantiated ('var' is short for variable).
Arguments:
Term
<term>
Description:
An uninstantiated variable is one which has not been bound to anything, except possibly another uninstantiated variable. Note that a compound term with some arguments which are uninstantiated is not itself considered to be uninstantiated.
Examples:
| ?- var(foo(X,Y)). no | ?- var([X,Y]). no | ?- var(X). X = _3437 ; no | ?- Term = foo(X,Y), var(Term). no
See Also:
atom/1, atomic/1, number/1, compound/1, callable/1, nonvar/1, simple/1

L-3-194: version/[0,1]

Synopsis:
version
version(+Atom)
Display system identification messages
Add the atom A to the list of introductory messages.
Arguments:
Atom
<atom>

L-3-195: vms/[1,2]

Synopsis:
vms(+-Command)
vms(+-Command, +Flag)
Issue a VMS specific system command (only available on VMS platforms).
Arguments:
Command
<term>
Flag
n | i

L-3-196: volatile/1 declaration

Synopsis:
:-volatile(+PredSpecs)
Declares PredSpecs to be volatile. Volatile predicates are not saved in QOF files by Prolog 'save' predicates.
Arguments:
PredSpecs
<pred_spec_forest> A single predicate specification of the form Name/Arity, or a sequence of predicate specifications separated by commas. Name must be an atom and Arity an integer in the range 0..255. MOD
Description:
Exceptions:
Comments:
Examples:
see examples under initialization/1.
See Also:
initialization/1, save_program/[1,2], save_modules/2, save_predicates/2
Chapter G-5-6-2

L-3-197: write/[1,2]

Synopsis:
write(+Term)
write(+Stream, +Term)
Writes Term to the current output stream or Stream.
Arguments:
Stream
<stream_object> a valid output stream
Term
<term> the term to be written
Description:
Exceptions:
Stream errors (see section G-7-6-2), plus:
Example:
| ?- write('a b'). a b
See Also:
read[1,2], writeq/[1,2], write_canonical/[1,2] or write_term/[2,3].

L-3-198: write_canonical/[1,2]

Synopsis:
write_canonical(+Term)
write_canonical(+Stream, +Term)
Writes Term to the current or specified output stream in standard syntax.
Arguments:
Stream
<stream_object> a valid Prolog stream which is open for output
Term
<term> the term to be written
Description:
Exceptions:
Stream errors (see section G-7-6-2).
Examples:
See Also:
write_term/[2,3], write/[1,2], writeq/[1,2], read/[1,2]
Chapter G-7-3-2

L-3-199: write_term/[2,3]

Synopsis:
write_term(+Term, +Options)
write_term(+Stream, +Term, +Options)
Writes Term to the current output stream or to Stream in a format given by the options.
Arguments:
Stream
<stream_object> a valid Prolog stream which is open for output
Term
<term> the term to be written
Options
<list of term> a list of zero or more of the following, where Bool must be true or false (false is the default).
quoted(Bool)
Should atoms and functors be quoted as necessary to make them acceptable as input to read?
ignore_ops(Bool)
Ignore current operator declarations? If Bool is true, compound terms are always written in the form,

                               <predicate name>(<arg1>,...,<argn>).

                       
portrayed(Bool)
Call user:portray/1 for each subterm. By default the behavior of write_term/[2,3] is controlled by Options, but you can change its effect by providing clauses for the predicate portray/1.
character_escapes(Bool)
Use character escapes. Bool must be true or false (the default depends on the value of the character_escapes flag as set by prolog_flag/3). If Bool is 'true' then write_term/[2,3] tries to write layout characters (except ASCII 9 and ASCII 32) in the form \<lower-case-letter>, if possible; otherwise, write_term/[2,3] writes the \^<control-char> form. If Bool is 'false' then it writes the actual character, without using an escape sequence.
numbervars(Bool)
Should terms like '$VAR'(N) be treated specially? If Bool is true, write_term/[2,3] writes 'A' if N=0, 'B' if N=1, ...'Z' if N=25, 'A1' if N=26, etc. Terms of this form are generated by numbervars/3.
max_depth(N)
Depth limit on printing. N is any integer; 0 means no limit and approximately 33 million is the default.
Description:
Exceptions:
Comments:
Examples:
See Also:
write/[1,2], writeq/[1,2], write_canonical/[1,2], display/1, print/1, portray_clause/1
Chapter G-7-3-2

L-3-200: writeq/[1,2]

Synopsis:
writeq(+Term)
writeq(+Stream, +Term)
Writes the term Term to Stream or the current output stream.
Arguments:
Stream
<stream_object> a valid Prolog stream which is open for output
Term
<term> the term to be written
Description:
Comments:
Exceptions:
Stream errors (see section G-7-6-2)
See Also:
write_term/[2,3], write/[1,2], write_canonical/[1,2]
section G-1-3 for information about character escaping.

M: C Reference Pages


Copyright (C) 1998 SICS
contact: product support sales information