November 17, 2008
This proposal is written as an extension to the ISO/IEC 13211-1 Prolog standard, adopting a similar structure. Specifically, this proposal either adds new sections and clauses to, or modifies the reading of existing clauses on ISO/IEC 13211-1.
This draft proposal may contain in several places informative text, type-set in italics. Such informative text is used for editorial comments deemed useful during the development of this draft and may not be included in the final version.
NOTE — This part of ISO/IEC 13211 will eventually merge with ISO/IEC 13211-1:1995 resulting in a new version of the Part 1 standard.
Priority Specifier Operators(s) 500 yfx + - /\ \/ ><The prefix operator `+' (unary plus) is added to the operator table with the same specification as the unary minus or the bitwise complement operators:
Priority Specifier Operators(s) 200 fy + - \
P
is a pair if it is a compound term '-'(Key,
Value)
where Key
and Value
are terms.
NOTE — In Prolog text and this part of ISO/IEC
13211 a pair'-'(Key, Value)
is normally written
as Key-Value
or (Key)-(Value)
depending on
whether or not Key
and Value
are operators.
encoding(E)
specifies that the Prolog text
being prepared for execution uses the encoding E
. When
used, this directive shall be the first term, on the first line, in a
Prolog text with no extra layout characters (6.5.4) before
the :-/1
directive operator. Moreover, a single layout
character shall be used between the directive operator and the
directive functor. No layout characters or comments shall appear
between the directive opening and closing parenthesis.
Three streams are predefined and open during the execution of every
goal: the standard input stream has the alias user_input
,
the standard output stream has the alias user_output
, and
the standard error output stream has the
alias user_error
.
NOTES
3 Prolog implementation on systems that do not support an error
output stream shall redirect output to the standard output stream.
bom(Bool)
— If Bool
(7.1.4.2) is
true then a Unicode encoding Byte Order Mark shall be written
when opening a text stream for writing in mode write
or
is probed for when opening the text stream for reading. This option
shall be ignored when opening a stream in
mode append
. If Bool
is false
then a Unicode encoding Byte Order Mark shall not be written
when opening the text stream for writing.
When no bom(Bool)
stream-option is specified, the
default value shall be true
when the text stream is
opened for reading and false
when the text stream is
opened for writing.
encoding(Encoding)
— Encoding
is an
atom representing the text encoding that shall be used when opening
the stream for writing or the text encoding of the stream opened for
reading.
When opening the text stream for reading with the
default bom(Bool)
streamoption value or by explicitly
specifying the bom(true)
stream-option, if a Byte
Order Mark is detected, it will be used to set the corresponding
Unicode text stream encoding, overriding
any encoding(Encoding)
that might be also specified.
NOTES
1 These stream-options imply the
stream-option type(text)
.
2 The set of supported text encodings is implementation-defined.
bom(Bool)
— If present and if Bool
(7.1.4.2) is true
, a Unicode encoding Byte Order
Mark was detected while opening the text stream for reading or a
Byte Order Mark was written while opening the text stream for
writing.
encoding(Encoding)
— Encoding used for the text
stream.
NOTE — These stream properties imply the stream
property type(text)
.
Possible values: the default value only
Default: implementation defined
Changeable: No
Description: The value of this flag is the number of significant digits on the mantissa of a normalized floating point number (in base 10), an implementation defined integer value.
Possible values: the default value only
Default: implementation defined
Changeable: No
Description: The value of this flag is the distance
from 1.0
to the next largest floating point number, an
implementation defined value. Thus, it allows the programmer to query
an implementation about the relative accuracy when performing
arithmetic with floating point numbers.
Possible values: the default value only
Default: implementation defined
Changeable: No
Description: The value of this flag is smallest possible value of the exponent of a normalized floating point number, an implementation defined integer value.
Possible values: the default value only
Default: implementation defined
Changeable: No
Description: The value of this flag is greatest value of the exponent of a normalized floating point number, an implementation defined integer value.
Possible
values: fail
, cyclic
, unsafe
Default: implementation defined
Changeable: No
Description: This read-only flag describes the behaviour of the
Prolog system when a variable is unified with a compound term that
contains it (STO unification, 3.165). The flag value fail
implies that STO unification simply fails. The flag
value unsafe
means that if an STO unification is
encountered the further behavior of the system is undefined. The flag
value cyclic
implies that STO unifications will be
successful and result in the creation of cyclic terms. Moreover, this
flag indicates that the Prolog system is capable of handling certain
operations on cyclic terms safely, namely unifying,
comparing, and copying of cyclic terms is assured to terminate.
NOTES
1 The flag value fail
means that the built-in
predicate =/2
(8.2.1) behaves exactly as the built-in
predicate unify_with_occurs_check/2
(8.2.2). The flag
value unsafe
may imply that the STO unification itself,
or further unifications or built-in predicate calls may not terminate,
or cause the system to fail or raise an exception.
2 A conforming Prolog processor which supports the creation of
cyclic terms shall be accompanied by documentation that specifies
which built-in predicates may be safely called with arguments which
are cyclic terms.
Examples:
| ?- X = f(X).
fail
: fails
cyclic
: succeeds and unifies X
with a
cyclic term f(f(f(...)))
.
unsafe
: undefined. Often succeeds, but subsequent use
of X
, as e.g. in X=X
, causes an error.
| ?- X = f(X), Y = f(Y), X = Y. | ?- g(X,Y,X) = g(f(X),f(Y),Y). | ?- X = f(X), Y = f(Y), X == Y. | ?- X = f(X), asserta(p(X)).For all the above four examples:
fail
: fails
cyclic
: succeeds and unifies both X
and Y
with a cyclic term f(f(f(...)))
.
unsafe
: undefined. Often causes an error.
Possible values: an implementation defined atom
Default: implementation defined
Changeable: implementation defined
Description: This flag represents the default encoding for text streams. An implementation shall document if the flag value can be changed by programmer as well all the supported encodings.
pair
(see 7.12.2 b of ISO/IEC 13211-1).
order
and predicate_property
(see 7.12.2 c of ISO/IEC 13211-1).
property(Callable, Property)
,
where Callable
is a callable term. The predicate
properties supported shall include:
static
— The predicate is static
dynamic
— The predicate is dynamic
built_in
— The predicate is a built-in
predicate
multifile
— The predicate is the subject of a
multifile directive
subsumes(General, Specific)
is true iff there is a
substitution θ, including the empty substitution, such
that the term General is instantiated to Generalθ =
Specific. This predicate provides a one-way unification.
subsumes(?term, @term)
subsumes(f(X,Y), f(Z,Z)). Succeeds, unifying both X and Y to Z. subsumes(f(Z,Z), f(X,Y)). Fails.
callable(Term)
is true iff Term
is a callable term.
callable(@term)
callable(a). Succeeds. callable(3). Fails.
ground(Term)
is true iff Term
is a ground term.
ground(@term)
ground(3). Succeeds. ground(a(1, _)). Fails.
acyclic(Term)
is true iff Term
is an acyclic
term. For implementations not supporting STO unification 7.11.3.6,
calls to this predicate simply succeed.
acyclic(@term)
acyclic(a(1, _)). Succeeds. X = f(X), acyclic(X). Fails.
cyclic(Term)
is true iff Term
is a cyclic
term. For implementations not supporting STO unification 7.11.3.6,
calls to this predicate simply fail.
cyclic(@term)
cyclic(a(1, _)). Fails. X = f(X), cyclic(X). Succeeds.
compare(Order, Term1, Term2)
is true
iff Order
corresponds to the standard order
between Term1
and Term2
. The
argument Order
is unified with the atom <
when Term1
is less than Term2
, with the
atom =
when Term1
and Term2
are
equal, and with the atom >
when Term1
is
greater than Term2
.
compare(?atom, @term, @term)
Order
is neither a variable nor an
atomtype_error(atom, Order)
Order
an atom other
than <
, =
, or
>
domain_error(order, Order)
compare(Order, 3, 5). Succeeds, unifying Order with <. compare(Order, d, d). Succeeds, unifying Order with =. compare(Order, 3, 3.0). Succeeds, unifying Order with >.
numbervars(Term, Start, End)
is true. This predicate
unifies each free variable on Term
with a compound term
with the format '$VAR'(N)
where N
is an
integer starting from Start
and ending
at End-1
.
numbervars(?nonvar, +integer, -integer)
Start
is a
variableinstantiation_error
Start
is neither a variable nor an
integertype_error(integer, Start)
numbervars(foo(A, B, A), 0, End). Succeeds, unifying A with '$VAR'(0), B with '$VAR'(1), and End with 2.
predicate_property(Head, Property)
is true iff the
procedure associated with the argument Head
(3.84) has
predicate property Property
.
Procedurally, predicate_property(Head, Property)
is
executed as follows
P
and
arity N
associated
with Head
. P/N
is the associated predicate
indicator
P/N
identifies a procedure
which has predicate property PP and PP is unifiable
with Property
Property
and the predicate succeeds
Property
and the
goal succeeds
predicate_property(Head, Property)
is re-executable. On
backtracking, continue at 8.8.3.1 f.
The order in which properties are found
by predicate_property/2
is implementation dependent.
NOTES
1 A processor may support, as an implementation specific feature,
additional predicate properties.
2 For a dynamic predicate, all proprieties related to its
definition shall be removed when the predicate is abolished.
predicate_property(@callable_term, ?predicate_property)
Head
is a
variableinstantiation_error
Head
is neither a variable nor a callable
termtype_error(callable, Head)
Property
is neither a variable nor a predicate
propertydomain_error(predicate_property,
Property)
predicate_property(once(_), built_in). Succeeds. predicate_property(atom_codes(_, _), Property). Succeeds unifying Property with static. On re-execution, succeeds unifying Property with built_in.
permission_error
exception that should use the atom
modify
instead of access
in order to match
the specification of other database predicates.
Pred
of Head
is that of a static procedurepermission_error(modify,
static_procedure, Pred)
retractall(Head)
is true.
Procedurally, retractall(Head)
is executed as follows:
P
and
arity N
associated
with Head
. P/N
is the associated predicate
indicator
P/N
, then proceeds to 8.9.5.1 d,
Head
and the goal succeeds
NOTES
1
The dynamic predicate shall continue to be known by the system
even when all of its clauses are removed.
2
This predicate does not change any of the standard predicate
properties of the referenced predicate (as reported
by predicate_property(Head, Property)
), even when all of
its clauses are removed.
retractall(@callable_term)
Head
is a
variableinstantiation_error
Head
is neither a variable nor a callable
termtype_error(callable, Generate)
Pred
of Head
is that of a static procedurepermission_error(modify,
static_procedure, Pred)
:- dynamic(insect/1). insect(ant). insect(bee). insect(spider). retractall(insect(bee)). Succeeds, retracting the clause 'insect(bee)'. retractall(insect(_)). Succeeds, retracting all the clauses of predicate insect/1. retractall(insect(elephant)). Succeeds. retractall(mammal(_)). Succeeds. retractall(3). type_error(callable, 3)
forall(Generate, Test)
is true iff for all possible bindings of
Generate
, the goal Test
is
true. Procedurally, abstracting error checking, the predicate shall
behave as being defined by \+ (call(Generator), \+
call(Test)).
forall(@callable_term, @callable_term)
Generate
is a
variableinstantiation_error
Generate
is neither a variable nor a callable
termtype_error(callable, Generate)
Test
is a
variableinstantiation_error
Test
is neither a variable nor a callable
termtype_error(callable, Test)
a/1
and b/1
are defined with the following clauses:
a(1). a(2). a(3). b(1, a). b(2, b). b(3, c). forall(fail, true). Succeeds. forall(a(X), b(X, _)). Succeeds. forall(a(X), b(_, X)). Fails. forall(b(_, Y), write(Y)) Succeeds, outputting the characters abc to the current output stream.
call(Closure, Arg1, ...)
is true
iff call(Goal)
is true where Goal
is
constructed by appending Arg1, ...
additional arguments to the
arguments (if any) of Closure
.
call(@callable_term, ?term, ...)
Closure
is a variableinstantiation_error
Closure
is neither a variable nor a callable
termtype_error(callable, Closure)
representation_error(max_arity)
call(integer, 3). Succeeds. call(atom_concat(pro), log, Atom). Succeeds, unifying Atom with prolog.
call_cleanup(Goal, Cleanup)
is true
iff call(Goal)
is true. When the execution
of Goal
terminates, either by deterministic success, by
failure, by its choice-points being cut, or by raising an exception,
the goal Cleanup
is executed. The success or failure
of Cleanup
is ignored, as are any choice-points created
while proving it. An exception thrown by call(Goal)
may
be caught by Cleanup
. An exception thrown
by Cleanup
is handled as normal.
call_cleanup(+callable_term, @callable_term)
Goal
is a
variableinstantiation_error
Goal
is neither a variable nor a callable
termtype_error(callable, Goal)
Cleanup
is a
variableinstantiation_error
Cleanup
is neither a variable nor a callable
termtype_error(callable, Cleanup)
call_cleanup(true, write(terminated)). Succeeds, outputting the atom terminated to the current output stream. catch(call_cleanup(throw(e), catch(true, E, throw(E))), F, true). Succeeds, unifying F with e.
append(List1, List2, List3)
is true
iff List3
is a list resulting from the concatenation
of List1
and List2
.
append(?list, ?list, ?list)
append/3
:
append([], List, List). Succeeds.
length(List, Length)
is true iff Length
is
the length of the list List
.
length(?list, ?integer)
Length
is neither a variable nor an
integertype_error(integer, Length)
length([1, 2, 3], Length). Succeeds, unifying Length with 3. length(List, 3). Succeeds, unifying List with [_, _, _]
length(List, -2). Fails length(List, Length). List = [] Length = 0 ; List = [_] Length = 1 ; List = [_, _] Length = 2 yes
member(Element, List)
is true iff Element
is
a member of list List
.
member(?term, ?list)
member(2, [1, 2, 3]). Succeeds.
sort(List, Sorted)
is true iff Sorted
is a
list containing the non-duplicated elements of List
sorted in ascending order following standard order (7.2).
sort(@list, ?list)
List
is a partial
listinstantiation_error
List
is neither a partial list nor a
listtype_error(list, List)
Sorted
is neither a partial list nor a
listtype_error(list, Sorted)
sort([1, 2, 1, 8, 4], Sorted). Succeeds, unifying Sorted with [1, 2, 4, 8].
keysort(List, Sorted)
is true iff List
is a
list of elements with the format Key-Value
and Sorted
is a list containing the elements
of List
sorted according to the value of Key
in ascending order following standard order (7.2). The relative order
of elements of List
with the same key shall not change in
the Sorted
list.
keysort(@list, ?list)
List
is a partial
listinstantiation_error
List
is neither a partial list nor a
listtype_error(list, List)
Element
of List
is a
variableinstantiation_error
Element
of List
is neither
a variable nor a '-'/2
compound
termtype_error(pair, Element)
Sorted
is neither a partial list nor a
listtype_error(list, Sorted)
keysort([1-a, 3-f(_), 1-z, 2-44], Sorted). Succeeds unifying Sorted with [1-a, 1-z, 2-44, 3-f(_)].
Evaluable functor | Operation |
(+)/1 | posI , posF |
posI : I → I
For all x ∈ I, the following axioms shall apply:
posI (x) = x
posF : F → F
For all x ∈ F, the following axioms shall apply:
posF (x) = x
log(B, X)
evaluates the expression B
with
value VB
, the expression X
with
value VX
, and has the value of the logarithm to base
VB
of VX
.
log(int-exp, float-exp) = float
log(int-exp, int-exp) = float
B
is a
variableinstantiation_error
B
is not a variable and VB
is not an
integertype_error(integer, VB)
VB
is zero or
negativeevaluation_error(undefined)
X
is a
variableinstantiation_error
X
is not a variable and VX
is not a
numbertype_error(number, VX)
VX
is zero or
negativeevaluation_error(undefined)
log(10, 10.0). Evaluates to 1.0.
gcd(I, J)
evaluates the expression I
with
value VI
, the expression J
with
value VJ
, and has the value of the greatest common
divisor of VI
of VJ
.
gcd(int-exp, int-exp) = integer
I
is a
variableinstantiation_error
I
is not a variable and VI
is not an
integertype_error(integer, VI)
J
is a
variableinstantiation_error
J
is not a variable and VJ
is not an
integertype_error(integer, VJ)
gcd(2, 3). Evaluates to 1.
min(X, Y)
evaluates the expression X
with
value VX
, the expression Y
with
value VY
, and has the value of the minimum
of VX
and VY
. When used with expressions of
mixed-types, the result is implementation-dependent; an implementation
may chose either to return a value or to throw an exception.
min(float-exp, float-exp) = float
min(float-exp, int-exp) = implementation-dependent result
min(int-exp, float-exp) = implementation-dependent result
min(int-exp, int-exp) = integer
X
is a variable or Y
is a
variableinstantiation_error
X
is not a variable and VX
is not a
numbertype_error(number, VX)
Y
is not a variable and VY
is not a
numbertype_error(number, VY)
min(2, 3) Evaluates to 2. min(2.0, 3.0) Evaluates to 2.0. min(0, 0.0). Implementation-dependent result.
max(X, Y)
evaluates the expression X
with
value VX
, the expression Y
with
value VY
, and has the value of the maximum
of VX
and VY
. When used with expressions of
mixed-types, the result is implementation-dependent; an implementation
may chose either to return a value or to throw an exception.
max(float-exp, float-exp) = float
max(float-exp, int-exp) = implementation-dependent result
max(int-exp, float-exp) = implementation-dependent result
max(int-exp, int-exp) = integer
X
is a variable or Y
is a
variableinstantiation_error
X
is not a variable and VX
is not a
numbertype_error(number, VX)
Y
is not a variable and VY
is not a
numbertype_error(number, VY)
max(2, 3) Evaluates to 3. max(2.0, 3.0) Evaluates to 3.0. max(0, 0.0). Implementation-dependent result.
'><'(B1, B2)
evaluates the
expressions B1
and B2
with
values VB1
and VB2
and has the value such
that each bit is set iff only one of the corresponding bits
in VB1
and
VB2
is set.
The value shall be implementation defined if VB1
or VB2
is negative.
'><'(int-exp, int-exp) = integer
NOTE — '><' is an infix predefined operator (see 6.3.4.4).
B1
is a
variableinstantiation_error
B2
is a
variableinstantiation_error
B1
is not a variable and VB1
is not
an integertype_error(integer, VB1)
B2
is not a variable and VB2
is not
an integertype_error(integer, VB2)
'><'(10, 12). Evaluates to the value 6. '><'(125, 255). Evaluates to to the value 130. '><'(-10, 12). Evaluates to an implementation defined value. '><'(77, N) instantiation_error. '><'(foo, 2) type_error(integer, foo).
tan(X)
evaluates the expression X
with
value VX
and has the value of the tangent
of VX
(measured in radians).
tan(float-exp) = float
tan(int-exp) = float
X
is a
variableinstantiation_error
X
is not a variable and VX
is not a
numbertype_error(number, VX)
tan(pi). Evaluates to 0.0.
asin(X)
evaluates the expression X
with
value VX
and has the value of the arc sine
of VX
(in radians).
asin(float-exp) = float
asin(int-exp) = float
X
is a
variableinstantiation_error
X
is not a variable and VX
is not a
numbertype_error(number, VX)
asin(1.0). Evaluates to a value approximately equal to 1.570796326795.
acos(X)
evaluates the expression X
with
value VX
and has the value of the arc cosine
of VX
(in radians).
acos(float-exp) = float
acos(int-exp) = float
X
is a
variableinstantiation_error
X
is not a variable and VX
is not a
numbertype_error(number, VX)
acos(0.0). Evaluates to a value approximately equal to 1.570796326795.
atan(Y, X)
evaluates the expression Y
with
value VY
, the expression X
with
value VX
, and computes the principal value of the arc
tangent of VY/VX
(in radians), using the signs of both
arguments to determine the quadrant of the return value. When both
arguments are 0.0
, an implementation-dependent value is
returned.
atan(float-exp, float-exp) = float
atan(float-exp, int-exp) = float
atan(int-exp, float-exp) = float
atan(int-exp, int-exp) = float
X
is a
variableinstantiation_error
Y
is not a variable and VY
is not a
numbertype_error(number, VY)
X
is not a variable and VX
is not a
numbertype_error(number, VX)
atan(0.0, -0.0). Evaluates to a value approximately equal to 3.14159265358979.
pi
evaluates to the floating-point number which best
approximates the mathematical constant π, the ratio of a
circle's circumference to its diameter.
pi. Evaluates to the corresponding mathematical constant. The accuracy of the result is implementation-defined.
e
evaluates to the floating-point number which best
approximates the mathematical constant e, the base of natural
logarithms.
e. Evaluates to the corresponding mathematical constant. The accuracy of the result is implementation-defined.
epsilon
evaluates to the distance from 1.0
to the next largest floating point number, an implementation defined
value. Thus, it allows the programmer to retrieve the relative
accuracy when performing arithmetic with floating point numbers.
epsilon. Evaluates to an implementation defined value.