In the examples below, assume the database contains
?- dynamic(test/1). ?- public(test/2). test(1). test(1). % Note that this is asserted twice test(2) :- atom(a). test(3). test(a, b). test(a, c).
Also, assume that the standard input stream will yield the following when read
(where <space>
stands for a single space).
<space>a(b, C). /* This is a comment */ abc.
Also, assume that there exists a text input stream with alias
textin
, a text output stream with alias textout
, a
binary input stream with alias binaryin
, a binary output stream
with alias binaryout
, and a repositionable binary stream with
alias repositionable_binary
. Assume that the the first line of
textin
contains
<space>x(y, Z).
and that the first byte in binaryin
is 42.
at_end_of_stream / 0
at_end_of_stream
at_end_of_stream
- fails.at_end_of_stream / 1
at_end_of_stream(StreamOrAlias)
StreamOrAlias
is at or past end of stream.at_end_of_stream(textin)
- fails.atom_chars / 2
atom_chars(Atom, List)
List
with a list of characters corresponding to the name of Atom.
One (but not both) of the arguments may be uninstantiated - can either convert an atom to a list of characters or a list of characters to an atom.atom_chars(abc, L)
- instantiates L to [
a,
b,
c
].
atom_chars(A, [c, b, a])
- instantiates A to cba.
atom_codes / 2
atom_codes(Atom, List)
List
with a list of character codes corresponding to the name of Atom.
One (but not both) of the arguments may be uninstantiated - can either convert an atom to a list of character codes or a list of character codes to an atom.atom_codes(abc, L)
- instantiates L to [
97,
98,
99
]).
atom_codes(A, [99, 98, 97])
- instantiates A to cba.
atom_concat / 3
atom_concat(Atom1, Atom2, Atom3)
Atom3
with the concatenation of the names of Atom1
and Atom2.
If Atom1
and Atom2
are instantiated, Atom3
may be uninstantiated. If Atom3
is instantiated, one or both of Atom1
and Atom2
may be uninstantiated.atom_concat(abc, def, A)
- instantiates A
to abcdef.
atom_concat(abc, A, abcdef)
- instantiated A
to def.
atom_concat(A1, A2, abc)
- instantiates A1
to ''
and A2
to abc.
On backtracking, instantiates A1
and A2
to a
and bc
respectively, then ab
and c,
then abc
and ''.
atom_length / 2
atom_length(Atom, Length)
Length
with the number of characters in the name of Atom.
atom_length(abc, N)
- instantiates N
to 3.
bagof / 3
bagof(Template, BagofGoal, List)
Template
for each way of satisfying the goal contained in BagofGoal
then unify the resulting bag with List.
BagofGoal
may contain variables that are not to be considered when forming the bag. Because List
is a bag, the same element may occur more than once. Opaque to cuts in the subgoal.bagof(X, test(X, Y), L)
- instantiates L
to [
a,
a,
].
bagof(X, Y^test(X, Y), L)
- instantiates L
to [
a
].
(The specification of Y
as a bound variable causes distinct values to be ignored in forming the bag).catch / 3
catch(Goal, Ball, RecoverGoal)
Goal
and succeed if Goal
succeeds. If Goal
throws a ball that unifies with Ball,
call RecoverGoal
instead. If Goal
throws a ball that does not unify with Ball,
or if RecoverGoal
throws a ball, it is propagated instead. Either Goal
or RecoverGoal
(as appropriate) can be redone. Opaque to cuts occurring in either subgoal.catch(test(X), error(E, _), write(E))
- instantiates X to 1
initially, and to 1,
2,
3
if redone.catch(nonexistent, error(E, _), write(E))
- writes error(existence,
procedure, nonexistent/0).char_code / 2
char_code(Character, Code)
Code
with the numeric code for Character.
One or the other argument (but not both) may be uninstantiated.char_code(a, C)
- instantiates C
to 97.
char_code(A, 99)
- instantiated A
to c.
char_conversion / 2
char_conversion(InChar, OutChar)
InChar
in unquoted text read subsequently to be replaced by OutChar.
Specifying the same character for InChar
and OutChar
turns off conversion for that character in subsequent reads.char_conversion(a, b)
- causes every occurrence of a
in unquoted input to be replaced by b.
close / 1
close(StreamOrAlias)
StreamOrAlias.
close(textin)
- terminates access to textin.
close / 2
close(StreamOrAlias, OptionList)
StreamOrAlias,
with the operation being modified by options specified in OptionList.
See below.close(textin, [force(true)])
- terminates access to textin,
ignoring any system error that may occur.force
Force this stream to close even if there is an IO error.
Possible values:
false
true
compound / 1
compound(Term)
Term
is compound.compound(a(b))
- succeeds.compound([a, b])
- succeeds.compound(1)
- fails.compound(A)
- fails.copy_term / 2
copy_term(Term, Copy)
Copy
with a copy of Term
in which uninstantiated variables are replaced with fresh variables.copy_term(a(B, C), T)
- instantiates T
to a fresh copy of a(B,
C)
- with fresh variables in place of B
and C.
current_char_conversion / 2
current_char_conversion(InChar, OutChar)
OutChar
with the current conversion for InChar
- or fail if no conversion for it is currently in force.current_char_conversion(a, C)
- instantiates C
to the current conversion for a,
or fails if there is no conversion in force.current_input / 1
current_input(Stream)
Stream
with the current input stream.current_input(S)
- instantiates S
to the current input stream - e.g. standard input or the stream most recently set by set_input/1
or see/1.
current_op / 3
current_op(P, A, S)
P
with the priority, A
the associativity, and S
the symbol of a currently defined operator.current_op(P, A, +)
- instantiates P
to 500
and A
to yfx
(assuming standard operator declarations are in force).current_op(1200, A, S)
- instantiates A
to xfx
and S
to :-.
On backtracking, instantiates A
to fx
and S
to :-,
then A
to fx
and S
to ?-.
current_output / 1
current_output(Stream)
Stream
with the current output stream.current_output(S)
- instantiates S
to the current output stream - e.g. standard output or the stream most recently set by set_output/1
or tell/1.
current_predicate / 1
current_predicate(PredicateIndicatorPattern)
PredicateIndicatorPattern
with the predicate indicator for a user predicate. On backtracking, unifies it with an other pattern. (Builtin predicates are not seen.)current_predicate(test/A)
- instantiates A
to 1.
On backtracking, instantiates it to 2.
current_prolog_flag / 2
current_prolog_flag(Flag, Value)
Flag
and Value
with a current flag value. Can be redone on backtracking if Flag
is a variable. current_prolog_flag(debug, V)
- unifies V
with on
or off
as the case may be.current_prolog_flag(F, on)
- unifies F,
in turn, with the name of each flag whose current setting is on.
current_prolog_flag(F, V)
- unifies F
and V,
in turn, with the name and value of each of the flags supported by the system.findall / 3
findall(Template, Goal, List)
Template
for each way of satisfying Goal
then unify the resulting bag with List.
Opaque to cuts in the subgoal.findall(X, test(X), L)
- instantiates L
to [
1,
1,
2,
3
].
float / 1
float(Term)
Term
is a real number.float(1.0)
- succeeds.float(1)
- fails.float(a(b))
- fails.float(A)
- fails.flush_output / 0
flush_output
flush_output
- flushes pending output on the current output stream.flush_output / 1
flush_output(StreamOrAlias)
StreamOrAlias.
flush_output(textout)
- flushes pending output to textout.
get_byte / 1
get_byte(Byte)
Byte
with it. End of file is represented by a value of -1.get_byte(B)
- (Assume that binaryin
is the current input stream.) instantiates B
to 42.
get_byte / 2
get_byte(StreamOrAlias, Byte)
StreamOrAlias,
and unifies Byte
with it. End of file is represented by a value of -1.get_byte(binaryin, B)
- instantiates B
to 42.
get_char / 1
get_char(Char)
Char.
End of file is represented by the atom end_of_file.
get_char(C)
- instantiates C
to '
'.
get_char / 2
get_char(StreamOrAlias, Char)
StreamOrAlias
and unifies it with Char.
End of file is represented by by the atom end_of_file.
get_char(textin, C)
- instantiates C
to '
'.
get_code / 1
get_code(Code)
Code.
End of file is represented by a code of -1.get_code(C)
- instantiates C
to 32
(the code for space).get_code / 2
get_code(StreamOrAlias, Code)
StreamOrAlias
and unifies its code with Code.
End of file is represented by a code of -1.get_code(textin, C)
- instantiates C
to 32
(the code for space).-> / 2
Condition -> Then
Condition
as if by once/1
and, if it succeeds, calls Then;
otherwise fails. Then
is redoable, but Condition
is not. Opaque to cuts ocurring in Condition,
but transparent to cuts occurring in Then.
atom(a) -> test(X)
- instantiates X
to 1, and if redone to 1
again, then 2,
then 3.
atom(1) -> test(X)
- fails.-> ; / 3
Condition -> Then ; Else
Condition
as if by once/1
and, if it succeeds, calls Then;
otherwise calls Else.
Only one of Then
or Else
is called, and which ever one is called is is redoable, but Condition
is not. Opaque to cuts ocurring in Condition,
but transparent to cuts occurring in Then
or Else.atom(a) -> test(X);write(hello).
- instantiates X
to 1, and if redone to 1
again, then 2,
then 3.
atom(1) -> test(X);write(hello).
- writes hello.
nl / 1
nl(StreamOrAlias)
StreamOrAlias.
nl(textout)
- writes a newline to textout.
\+ / 1
\+ Goal
Goal
as if by once/1.
If Goal
succeeds, this predicate fails; if Goal
fails, this predicate succeeds. Not redoable Opaque to cuts occurring in Goal.
\+ atom(a)
- fails.\+ atom(1)
- succeeds.number / 1
number(Term)
Term
is a number.number(1)
- succeeds.number(1.0)
- succeeds.number(a(b))
- fails.number(A)
- fails.number_chars / 2
number_chars(Number, List)
List
with a list of characters corresponding to the printed form of Number.
One (but not both) of the arguments may be uninstantiated - can either convert a number to a list of characters or a list of characters to a number.number_chars(3.14, L)
- instantiates L
to [
'3',
'.',
'1',
'4'
].
number_chars(N, ['3', '.', '1', '4'])
- instantiates N
to 3.14.number_codes / 2
number_codes(Number, List)
List
with a list of character codes corresponding to the printed form of Number.
One (but not both) of the arguments may be uninstantiated - can either convert a number to a list of character codes or a list of character codes to a number.number_codes(3.14, L)
- instantiates L
to [
51,
46,
49,
52
].
number_codes(N, [51, 46, 49, 52 ])
- instantiates N
to 3.14.once / 1
once(Goal)
Goal,
and succeeds if Goal
succeeds. During backtracking, Goal
cannot be redone. Opaque to cuts in Goal.
once(test(X))
- instantiates X
to 1,
and cannot be redone.open / 3
open(Path, Mode, Stream)
Stream
(which must initially be a variable) with a newly-created stream connected to a file specified by Path,
having mode as specified by Mode.
Mode
can be read
(input), write
(output - a new file is always created, replacing any file of the same name, append
(append to an existing file if possible).open('foo/bar', read, S)
- instantiates S
to a newly opened text input file connected to a file named bar
in subdirectory foo
of the user's current default directory.open / 4
open(Path, Mode, Stream, OptionList)
Stream
(which must initially be a variable) with a newly-created stream connected to a file specified by Path,
having mode as specified by Mode,
with the options specified in OptionList.
Mode
can be any of the values specified for open/3,
or read_write
or read_append
to create an input-output stream (which must be of type(binary)).
See below.open('foo/bar', read, S, [alias(foo)])
- instantiates S
to a newly opened text input file connected to a file named bar
in subdirectory foo
of the user's current default directory. The new stream will have alias foo.
type
The type of stream to be created.
Possible values:
text
binary
reposition
Whether this stream's position can be set by set_position/2
.
Possible values:
false
true
alias
An alias for this stream. (A stream may have more than one, but the same name cannot be an alias for more than one stream.)
eof_action
The action to be taken after passing end-of-file.
Possible values:
error
eof_code
reset
peek_byte / 1
peek_byte(Byte)
Byte
with the byte that would be accessed by get_byte/1,
without actually extracting the byte from the input stream.peek_byte(B)
- instantiates B
to 42.
peek_byte / 2
peek_byte(StreamOrAlias, Byte)
Byte
with the byte that would be accessed by get_byte/2
on the same stream, without actually extracting the byte from the input stream.peek_byte(binaryin, B)
- instantiates B
to 42.
peek_char / 1
peek_char(Char)
Char
with the character that would be accessed by get_char/1
on the same stream, without actually extracting the character from the input stream.peek_char(C)
- instantiates C
to '
'.
peek_char / 2
peek_char(StreamOrAlias, Char)
Char
with the character that would be accessed by get_char/2
on the same stream, without actually extracting the character from the input stream.peek_char(textin, C)
- instantiates C
to '
'.
peek_code / 1
peek_code(StreamOrAlias, Code)
Code
with the code for the character that would be accessed by get_code/2
on the same stream, without actually extracting the character from the input stream.peek_code(C)
- instantiates C
to 32
(the code for space).peek_code / 2
peek_code(StreamOrAlias, Code)
Code
with the code for the character that would be accessed by get_code/2
on the same stream, without actually extracting the character from the input stream.peek_code(textin, C)
- instantiates C
to 32
(the code for space).put_byte / 1
put_byte(Byte)
Byte
to the current output stream (which must be a binary stream).put_byte(42)
- writes A
to the current output stream.put_byte / 2
put_byte(StreamOrAlias, Byte)
Byte
to the binary stream / stream having alias StreamOrAlias.
put_byte(textout, 42)
- writes 42
to textout.
put_char / 1
put_char(Char)
Char
to the current output stream.put_char('A')
- writes A
to the current output stream.put_char / 2
put_char(StreamOrAlias, Char)
Char
to the stream / stream having alias StreamOrAlias.
put_char(textout, 'A')
- writes A
to textout.
put_code / 1
put_code(Code)
Code
to the current output stream.put_code(65)
- writes A
to the current output stream.put_code / 2
put_code(StreamOrAlias, Code)
Code
to the stream / stream having alias StreamOrAlias.
put_code(textout, 65)
- writes A
to textout.
read / 2
read(StreamOrAlias, Term)
StreamOrAlias
and unifies it with Term.
read(T)
- instantiates T
to x(y,
_0).
read_term / 2
read_term(Term, Options)
Term.
Unifies variables specified by Options
with the names of variables read. See below.read_term(T, variables_names(V))
- instantiates T
to a(b,
_0),
and V
to [
C
=
_0
].
variables
The argument must be a variable, which will be instantiated to a list of the variables occurring in the term that was read.
variable_names
The argument must be a variable, which will be instantiated to a list of elements of the form VariableName = Variable
for each variable name occurring in the term that was read.
singletons
The argument must be a variable, which will be instantiated to a list of the singleton variables occurring in the term that was read.
read_term / 3
read_term(StreamOrAlias, Term, Options)
StreamOrAlias,
and then unifies it with Term.
Unifies variables specified by Options
with the names of variables read. See below.read_term(textin, T, variables_names(V))
- instantiates T
to x(y,
_0),
and V
to [
Z
=
_0
].
variables
The argument must be a variable, which will be instantiated to a list of the variables occurring in the term that was read.
variable_names
The argument must be a variable, which will be instantiated to a list of elements of the form VariableName = Variable
for each variable name occurring in the term that was read.
singletons
The argument must be a variable, which will be instantiated to a list of the singleton variables occurring in the term that was read.
set_input / 1
set_input(StreamOrAlias)
StreamOrAlias
be the current input stream.set_input(textin)
- makes textin
the current input stream.set_output / 1
set_output(StreamOrAlias)
StreamOrAlias
be the current output stream.set_output(textout)
- makes textin
the current output stream.set_prolog_flag / 2
set_prolog_flag(Name, Value)
Name
to Value.
set_prolog_flag(debug, on)
- set the debug
flag to on.
set_stream_position / 2
set_stream_position(StreamOrAlias, Position)
StreamOrAlias
to be Position,
where Position
is typically a previous value of the stream's position
property.set_stream_position(repositionable_binary, X)
- set the position or repositionable_binary
to the value of the (previously instantiated) variable X.
setof / 3
setof(Template, BagofGoal, List)
Template
for each way of satisfying the goal contained in BagofGoal
then unify the resulting set with List.
BagofGoal
may contain variables that are not considered when forming the set. Because List
is a set, the same element will not occur more than once. Opaque to cuts in thesubgoal.setof(X, test(X, Y), L)
- instantiates L
to [
a
].
stream_property / 2
stream_property(Stream, Property)
Stream
and Property
with a stream / stream property pair. Either or both parameters may be uninstantiated.stream_property(S, alias(textin))
- instantiates S
to the stream whose alias is textin.
sub_atom / 5
sub_atom(Atom, Before, Actual, After, SubAtom)
SubAtom
with a substring constructed from the name of Atom,
beginning at position Before,
Actual
characters long and with After
characters following it. Any or all of the arguments (except Atom)
may be uninstantiated, in which case the predicate may succeed multiple times.sub_atom(ab, B, Act, Aft, S)
- instantiates B
to 0,
Act
to 0,
Aft
to 2,
and S
to ''.
On backtracking, instantiates these, in turn, to 0,
1,
1,
a;
0,
2,
0,
ab;
1,
0,
1,
'';
1,
1,
0,
b;
2,
0,
0,
''.
@> / 2
Term1 @> Term2
Term1
comes after Term2
in term_precedes order.a(b, c) @>a(b, c)
- fails.a(b, X) @>a(b, c)
- fails.a(b, c) @>a(b, X)
- succeeds.@>= / 2
Term1 @>= Term2
Term1
comes after Term2
in term_precedes order, or they are identical.a(b, c) @>=a(b, c)
- succeeds.a(b, X) @>=a(b, c)
- fails.a(b, c) @>=a(b, X)
- succeeds.@< / 2
Term1 @< Term2
Term1
comes before Term2
in term_precedes order.a(b, c) @ - fails.
Example: a(b, X) @ - succeeds.
Example: a(b, c) @ - fails.
@=< / 2
Prototype: Term1 @=< Term2
Succeeds if Term1
comes before Term2
in term_precedes order, or they are identical.
Example: a(b, c) @= - succeeds.
Example: a(b, X) @= - succeeds.
Example: a(b, c) @= - fails.
throw / 1
Prototype: throw(Ball)
Throw a ball that might be caught by catch/3.
Example: throw(foo)
- throws the ball foo.
unify_with_occurs_check / 2
Prototype: unify_with_occurs_check(Term1, Term2)
Unifies Term1
with Term2,
unless doing so would result in instantiating a variable to a term which contains it (the occurs check).
Example: unify_with_occurs_check(a(X, c), a(b, Y))
- instantiates X
to b
and Y
to c.
Example: unify_with_occurs_check(a, 1)
- fails.
Example: unify_with_occurs_check(X, a(X))
- fails, because X
occurs in a(X).
write / 2
Prototype: write(StreamOrAlias, Term)
Writes a printed representation of Term
to the stream / stream having alias StreamOrAlias,
using operator and list notation as appropriate, but not quotes.
Example: write(textout, 1)
- writes 1
to textout.
Example: write(textout, [ 2 + 2, a(b) ]
- writes [
2
+
2,
a(b)
]
to textout.
Example: write(textout, 'Hello, world')
- writes Hello,
World
(with no quotes) to textout.
write_canonical / 1
Prototype: write_canonical(Term)
Writes Term
to the current output stream, without using operator or list notation. Atoms that would need to be quoted to be accepted by read
are quoted.
Example: write_canonical([2 + 2])
- writes '.'(+(2,
2),
[])
to the current output stream.
write_canonical / 2
Prototype: write_canonical(StreamOrAlias, Term)
Writes Term
to stream / stream having alias StreamOrAlias,
without using operator or list notation. Atoms that would need to be quoted to be accepted by read
are quoted.
Example: write_canonical(textout, [2 + 2])
- writes '.'(+(2,
2),
[])
to textout.
write_term / 2
Prototype: write_term(Term, Options)
Writes a printed representation of Term
to the current output stream, with formatting controlled by the list of options specified by Options.
See below.
Example: write_term('a3' + 2, [ quoted(true), ignoreops(true) ])
- writes +('a3',
2)
to the current output stream.
Possible options:
quoted
Quote atoms that would need to be quoted to be accepted by read
.
Possible values:
false
true
ignore_ops
Do not use operator or list notation.
Possible values:
false
true
numbervars
Convert terms of the form $VAR(number)
to a generated variable name.
Possible values:
false
true
escaped
Escape characters that Java requires to be escaped.
Possible values:
false
true
keep_variable_numbers
Retain previous _number
values for uninstantiated variables.
Possible values:
false
true
write_term / 3
Prototype: write_term(StreamOrAlias, Term, Options)
Writes a printed representation of Term
to the stream / stream, having alias StreamOrAlias
with formatting controlled by the list of options specified by Options.
See below.
Example: write_term(textout, 'a3' + 2, [ quoted(true), ignoreops(true) ])
- writes +('a3',
2)
to textout.
Possible options:
quoted
Quote atoms that would need to be quoted to be accepted by read
.
Possible values:
false
true
ignore_ops
Do not use operator or list notation.
Possible values:
false
true
numbervars
Convert terms of the form $VAR(number)
to a generated variable name.
Possible values:
false
true
escaped
Escape characters that Java requires to be escaped.
Possible values:
false
true
keep_variable_numbers
Retain previous _number
values for uninstantiated variables.
Possible values:
false
true
writeq / 2
Prototype: writeq(StreamOrAlias, Term)
Writes a printed representation of Term
to the stream / stream having alias StreamOrAlias,
but atoms that would need to be quoted to be accepted by read
are quoted
Example: writeq(textout, 'Hello, world')
- writes 'Hello,
World' (with quotes) to textout.
Example: writeq(textout, (a, b))
- writes a
','
b
to textout.
Example: writeq(textout, [ 2 + 2, a(b) ]
- writes [
2 +
2,
a(b),
]
to textout.