This section describes the basic term reading and writing predicates. The predicates format/[1,2] and writef/2 provide formatted output. Writing to Prolog datastructures such as atoms or code-lists is supported by with_output_to/2 and format/3.
There are two ways to manipulate the output format. The predicate
print/[1,2]
may be programmed using portray/1.
The format of floating point numbers may be manipulated using the
prolog_flag (see
current_prolog_flag/2) float_format
.
Reading is sensitive to the prolog_flag character_escapes
,
which controls the interpretation of the
character in quoted atoms and strings.
\
write_attributes
.
Defined values are ignore
(ignore the attribute), dots
(write the attributes as {...}
), write
(simply
hand the attributes recursively to write_term/2)
and portray
(hand the attributes to attr_portray_hook/2).true
, write a string object (see section
4.23) as
`
...`
. The default depends on the prolog flag
with the same name.true
, and quoted(true)
is active, special
characters in quoted atoms and strings are emitted as ISO
escape-sequences. Default is taken from the reference module (see
below).true
, the generic term-representation (<functor>(<args>
... )) will be used for all terms, Otherwise (default), operators,
list-notation and {}
/1 will be written using their special
syntax.?- write_term(a(s(s(s(s(0)))), [a,b,c,d,e,f]), [max_depth(3)]). a(s(s(...)), [a, b|...]) Yes
Used by the top-level and debugger to limit screen output. See also
the prolog-flags toplevel_print_options
and
debugger_print_options
.
user
). This defines
the default value for the character_escapes
option as well
as the operator definitions to use. See also op/3.true
, terms of the format $VAR(N)
, where <N>
is a positive integer, will be written as a variable name. If N
is an atom it is written without quotes. This extension allows for
writing variables with user-provided names. The default is
false
. See also numbervars/3.true
, the hook portray/1
is called before printing a term that is not a variable. If portray/1
succeeds, the term is considered printed. See also print/1.
The default is false
. This option is an extension to the
ISO write_term options.format('~w = ', [VarName]), write_term(Value, [quoted(true), priority(699)])
true
, atoms and functors that needs quotes will be
quoted. The default is false
.
ignore_ops
,
quoted
and numbervars
after numbervars/4
using the
singletons
option.
Note that due to the use of numbervars/4,
non-ground terms must be written using a single write_canonical/1
call. This used to be the case anyhow, as garbage collection between
multiple calls to one of the write predicates can change the _G
<NNN>
identity of the variables.
end_of_file
.style_check(singleton)
is active (default). Used to read Prolog source files (see consult/1).
New code should use read_term/2
with the option singletons(warning)
.true
, read `
...`
to a string
object (see
section 4.23). The default
depends on the prolog flag with the same name.\
escape-sequences in quoted atoms. See
the prolog-flags character_escapes
, current_prolog_flag/2.
(SWI-Prolog).double_quotes
, current_prolog_flag/2.
(SWI-Prolog).character_escapes
flag and double_quotes
flag. The value of the latter two is
overruled if the corresponding read_term/3
option is provided. If no module is specified, the current
`source-module' is used. (SWI-Prolog).variable_names
, but only reports the variables occurring
only once in the Term read. Variables starting with an
underscore (`_
') are not included in this list. (ISO). If Vars
is the constant warning
, singleton variables are reported
using
print_message/2.error
(default), throw and exception on a syntax error.
Other values are fail
, which causes a message to be printed
using
print_message/2,
after which the predicate fails, quiet
which causes the
predicate to fail silently and dec10
which causes syntax
errors to be printed, after which read_term/[2,3]
continues reading the next term. Using dec10
, read_term/[2,3]
never fails. (Quintus, SICStus)."
).
{...}
, as used in DCG rules. Arg
describes the argument.
|
<TailTerm>, Tail
is unified with the term-position of the tail, otherwise with the atom none
.
variable_names
, but allows for history
substitutions. read_history/6
is used by the top level to read the user's actions. Show is
the command the user should type to show the saved events. Help
is the command to get an overview of the capabilities. Special
is a list of commands that are not saved in the history. Prompt
is the first prompt given. Continuation prompts for more lines are
determined by prompt/2.
A
%w
in the prompt is substituted by the event number. See
section 2.7 for available
substitutions.
SWI-Prolog calls read_history/6 as follows:
read_history(h, '!h', [trace], '%w ?- ', Goal, Bindings)