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 optionEshall be associated with only two error conditions: an instantiation error when there is an instance (3.95) ofEthat is a valid option, and a domain error for the domainoptname_optionwhen there is no instance ofEthat is a valid option. Further, an instantiation error may occur in place of the domain error if a component ofEis 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 fromGin 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,Varsshall 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_listshall be unified with a list of ele-
ments where: (1) each element is a termA = V, and
(2)Vis a named variable of the term, and (3)Ais 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 variablesVin the term input, in left-to-right traversal order.
singletons(VN_list)— After inputting a term,
VN_listshall be unified with a list of elements
where: (1) each element is a termA = V, and (2)Vis
a named variable which occurs only once in the term,
and (3)Ais 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 variablesVin 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 variableVis output as the sequence of characters defined by the syntax for the atomAiff a termA = Vis an element of the listVN_list. If more than one element applies, the leftmost is used.VN_listis a list of termsA = TwithAan atom andTany term, possibly a variable.
numbervars(Bool)— IffBool(7.1.4.2) istruea
term of the form'$VAR'(N), whereNisana 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/1to print arbitrary variable names. The write optionvariable_names/1serves this purpose and avoids vulnerabilities.
variable_names/1, correct terminology and writing of {}, lists,
extra round brackets
a1) IfTermis a variable and there is an effective write-optionvariable_names(VN_list)and there is an elementA = Termof the listVN_listwithAan atom, thenAis output with effective write-optionquoted(false).
a) Ifa2) Else ifTermis 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) IfTermhas 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 ifTermhas the form'.'(Head, Tail), and
there is an effective write-optionignore_ops(false),
thenTermis output using list notation, that is:
- 1)
[(open list char) is output.- 2)
Headis output by recursively applying these
rules.Headis 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
Tailhas the form'.'(H,T)then,(comma
char) is output, setHead:=H,Tail:=T, and goto (2).- 4) If
Tailis[]then a closing bracket](close list
char) is output,- 5) Else a
|(head tail separator char) is output,
Tailis output by recursively applying these rules,.
Tailis 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 ifTermhas the form'{}'(Arg), and there is an effective write-optionignore_ops(false), thenTermis output as a curly bracketed term (6.3.6), that is:
- 1)
{(open curly char) is output.- 2)
Argis output by recursively applying these rules.- 3)
}(close curly char) is output.
f) Else ifTermhas 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 ifTermhas 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_listValidDomain.
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 argumentOptionswhose 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
Optionsis a partial list, or an element of a list prefix ofOptionsis not a valid option but an instance of the element is a valid option;- a type error of the form
type_error(list, Options), whenOptionsis neither a partial list nor a list;- a domain error of the form
domain_error(optname_option, E), when an elementEof a list prefix ofOptionsis neither a valid option nor any instance ofEis 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 headHand bodyBG
[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)
Optionsis a partial list or has a list prefix with an element
Ewhich is a variable or which has a component
which is a variable, and an instantiated component is required.
—instantiation_error.
- i/e) An element
Eof a list prefix of theOptionslist is neither a
variable nor a stream-option and there is no instance ofEthat is a stream-option.
—domain_error(stream_option, E).
- k) Parses
C_Seqas 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)VXis negative andYVYis not.
(^)/2 when resulting value is not an
integer but still a real number. Adjust example
- e)
VXandVYare integers andVXis not equal to 1 andVYis less than -1VXis not equal to 1, 0, or -1 andVYis 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.