Deleted text is marked as strike-through text, inserted text
is underlined.
5.5.12 Options
A processor may support one or more additional options such as stream-options (7.10.2.11), close-options (7.10.2.12), read-options (7.10.3), and write-options (7.10.4) as an implementation specific feature. An invalid optionE
shall be associated with only two error conditions: an instantiation error when there is an instance (3.95) ofE
that is a valid option, and a domain error for the domainoptname_option
when there is no instance ofE
that is a valid option. Further, an instantiation error may occur in place of the domain error if a component ofE
is a variable, and an instantiated component is required.
- NOTE — A valid option may be associated with other error conditions like 8.11.5.3 l and m.
p text = [ layout text sequence (* 6.4.1 *) ] ;
a) If Tunifies withhas the form^(_, G)
then ...
Table 21 and 22 show the execution stack before and
after executing the control constructcall(G)
with goal
obtained fromG
in step 7.8.3.1 f via 7.6.2.
N + 1 ( (goal, N – 1), Σ nilG
variable_names/1
and singletons/1
.
Clarify unification for variables/1
.
variables(Vars)
— After inputting a term,Vars
shall be unified with a list of the variables in the term input, in left-to-right traversal order.
variable_names(VN_list)
— After inputting a
term,VN_list
shall be unified with a list of ele-
ments where: (1) each element is a termA = V
, and
(2)V
is a named variable of the term, and (3)A
is an
atom whose name is the characters ofV
, and (4) there is exactly one element for each named variable, and (5) the elements appear in the order of the first occurrence of their variablesV
in the term input, in left-to-right traversal order.
singletons(VN_list)
— After inputting a term,
VN_list
shall be unified with a list of elements
where: (1) each element is a termA = V
, and (2)V
is
a named variable which occurs only once in the term,
and (3)A
is an atom whose name is the characters ofV
,
and (4) there is exactly one element for each named variable occuring only once, and (5) the elements appear in the order of the first occurrence of their variablesV
in the term input, in left-to-right traversal order.
variable_names(VN_list)
before
numbervars(Bool)
in analogy to
the read-option.
Modify write-optionnumbervars(Bool)
.
3.206 write-option: Agroundterm that controls the
output produced by the built-in predicatewrite_term/3
(8.14.2) and its bootstrapped * built-in predicates (see
7.10.4, 7.1.4.2).
variable_names(VN_list)
— Each variableV
is output as the sequence of characters defined by the syntax for the atomA
iff a termA = V
is an element of the listVN_list
. If more than one element applies, the leftmost is used.VN_list
is a list of termsA = T
withA
an atom andT
any term, possibly a variable.
numbervars(Bool)
— IffBool
(7.1.4.2) istrue
a
term of the form'$VAR'(N)
, whereN
isana non-negative integer, is
output as a variable name consisting of a capital letter
possibly followed by an integer.
- NOTE 2 — Many Prolog processors modified write option
numbervars/1
to print arbitrary variable names. The write optionvariable_names/1
serves this purpose and avoids vulnerabilities.
variable_names/1
, correct terminology and writing of {}, lists,
extra round brackets
a1) IfTerm
is a variable and there is an effective write-optionvariable_names(VN_list)
and there is an elementA = Term
of the listVN_list
withA
an atom, thenA
is output with effective write-optionquoted(false)
.
a) Ifa2) Else ifTerm
is a variable, a character sequence repre-
senting that variable is output. The sequence begins
with _ (underscore) and the remaining characters are
implementation dependent. During the execution ofwrite_term/3
, the
Thesame character sequence
is used for each occurrence of a particular variableinand a different character sequence is used for each
Term
. A
distinct variablein.Term
e)e1) IfTerm
has the form'$VAR'(N)
for somepos-non-negative integer
itiveNN
, and there is an effective write-option
numbervars(true)
, a variable name as defined in
subclause 7.10.4 is output,
g)e2) Else ifTerm
has the form'.'(Head, Tail)
, and
there is an effective write-optionignore_ops(false)
,
thenTerm
is output using list notation, that is:
- 1)
[
(open list char) is output.- 2)
Head
is output by recursively applying these
rules.Head
is preceded by(
(open char)
and followed by)
(close char), if the term could not be
re-input correctly with same set of current operators.- 3) If
Tail
has the form'.'(H,T)
then,
(comma
char) is output, setHead:=H
,Tail:=T
, and goto (2).- 4) If
Tail
is[]
then a closing bracket]
(close list
char) is output,- 5) Else a
|
(head tail separator char) is output,
Tail
is output by recursively applying these rules,.
Tail
is preceded by(
(open char)
and followed by)
(close char), if the term could not be
re-input correctly with same set of current operators.
andAnd finally,]
(close list char) is output.
e3) Else ifTerm
has the form'{}'(Arg)
, and there is an effective write-optionignore_ops(false)
, thenTerm
is output as a curly bracketed term (6.3.6), that is:
- 1)
{
(open curly char) is output.- 2)
Arg
is output by recursively applying these rules.- 3)
}
(close curly char) is output.
f) Else ifTerm
has a principal functor which is not
a current operator, or if there is an effective write-
optionignore_ops(true)
, then the term is output in
canonical formfunctional notation (6.3.3), that is:h)
- 1) The atom of the principal functor is output.
- 2)
(
(open char) is output.- 3) Each argument of the term is output by recursively
applying these rules. The argument is preceded by(
(open char) and followed by)
(close char), if the term could not be re-input correctly with the same set of current operators.- 4)
,
(comma char) is output between each successive
pair of arguments.- 5)
)
(close char) is output.IfElse ifTerm
has a principal functor which is an
operator, and there is an effective write-option
ignore_ops(false)
, then the term is output in operator
form, that is:1) The atom of the principal functor is output
in front of its argument (prefix operator), between
its arguments (infix operator), or after its argument
(postfix operator). In all cases, a space is output
to separate an operator from its argument(s) if any
ambiguity could otherwise arise.Operators
','
and'|'
are output as,
(comma char) and|
(bar char) respectively.2) Each argument of the term is output by recursively
applying these rules.When anAn argumentis itselfis preceded by (
to be output in operator form, it
(open char) and followed by ) (close char) if: (i) the argument's
principal functor is an operator whose priority is so
high that the term could not be re-input correctly with
same set of current operators, or (ii) the argument is
an atom which is a current operator, or (iii) the principal functor is output as a prefix operator-
and the argument is a non-negative number, or (iv) the principal functor is output as a prefix operator-
and the argument is output in infix or postfix operator form.
float
to the set ValidType
.
character_code_list
ValidDomain
.
PermissionType ∈ {
binary_stream, flag
_list
to types close_options
and stream_options
. Add Note 7 for options lists
close_options_list
— a list of close options (8.11.6),
...
stream_options_list
— a list of stream options (7.10.2.11),
7 When a built-in predicate has an argumentOptions
whose type is a list of optname-options as input, the argument is always+optname_options_list
. It is always associated with:A valid option may be associated with other error conditions.
- an instantiation error, when
Options
is a partial list, or an element of a list prefix ofOptions
is not a valid option but an instance of the element is a valid option;- a type error of the form
type_error(list, Options)
, whenOptions
is neither a partial list nor a list;- a domain error of the form
domain_error(optname_option, E)
, when an elementE
of a list prefix ofOptions
is neither a valid option nor any instance ofE
is a valid option; an instantiation error may occur in place of the domain error, if a component is a variable, and an instantiated component is required.
open(@source_sink, @io_mode, -stream, @stream_options_list)
close(@stream_or_alias, @close_options_list)
current_prolog_flag(max_arity, A), X is A + 1, functor(T, foo, X). If the Prolog flag max_arity has the value unbounded type_error(evaluable, unbounded/0) else representation_error(max_arity).
B
by G
e) Constructs the clause with headH
and bodyB
G
[a, b, f(b),
f(a)]
as it originally was in IS 13211-1:1995.
b) the goal succeeds.
Add to the four subclauses 8.11.5.3 i, 8.11.6.3 e, 8.14.1.3 e, 8.14.2.3 e using in place of stream-option for the latter three close-option, read-option, and write-option respectively:
- c/b)
Options
is a partial list or has a list prefix with an element
E
which is a variable or which has a component
which is a variable, and an instantiated component is required.
—instantiation_error.
- i/e) An element
E
of a list prefix of theOptions
list is neither a
variable nor a stream-option and there is no instance ofE
that is a stream-option.
—domain_error(stream_option, E).
- k) Parses
C_Seq
as a read-term(6.4)(6.2.2)T.
,
write_canonical([1,2,3]). Succeeds, outputting the characters.(1,.(2,.(3,[ ]'.'(1,'.'(2,'.'(3,[]))) to the current output stream.
write_term(1,[quoted(non_boolean)]). domain_error(write_option,quoted(non_boolean)), write_term(1,[quoted(B)]). instantiation_error. B = true, write_term(1,[quoted(B)]). Succeeds, unifying B with true, and outputting the character 1.
set_prolog_flag(date, 'July 1988'). domain_error(flagprolog_flag, date).
Y
by VY
:
c)VX
is negative andY
VY
is not.
(^)/2
when resulting value is not an
integer but still a real number. Adjust example
- e)
VX
andVY
are integers andVX
is not equal to 1 andVY
is less than -1VX
is not equal to 1, 0, or -1 andVY
is negative.
—type_error(float, VX).
- NOTE — Error condition 9.3.10.3 e is satisfied when a float as an argument is needed for a defined result.
2^(-1).evaluation_error(undefined).type_error(float, 2). 2.0^(-1). Evaluates to the value 0.5.