Recent Changes - Search:

PmWiki

pmwiki.org

edit SideBar

WriteOptions

Non-standard write-options for write_term/3

Author: Joachim Schimpf, 2013

The ISO-Prolog Standard defines the following required write-options in section 7.10.4.

quoted(Bool)
Iff Bool (7.1.4.2) is true each atom and functor is quoted if this would be necessary for the term to be input by read_term/3.
ignore_ops(Bool)
Iff Bool (7.1.4.2) is true each compound term is output in functional notation (6.3.3). Neither operator (6.3.4.3) notation nor list notation (6.3.5) is used when this write-option is in force.
numbervars(Bool)
Iff Bool (7.1.4.2) is true a term of the form '$VAR'(N), where N is an integer, is output as a variable name consisting of a capital letter possibly followed by an integer. The capital letter is the (i+1)th letter of the alphabet (see the syntax rule for capital letter char, 6.5.2), and the integer is j, where i = N mod 26, j = N // 26. The integer j is omitted if it is zero.

In addition, the following option was added via corrigendum 3:

variable_names(List)
Assign names to variables in Term. List is a list of terms Name = Var, where Name is an atom that represents a valid Prolog variable name. Terms where Var is bound or is a variable that does not appear in Term are ignored.

A processor may support one or more additional write-options as an implementation specific feature. We suggest that systems doing so aim to be compatible with the following suggestions.

Options meaningful for every ISO system:

nl(Bool) (ECLiPSe/SWI)
If true, print a newline sequence (as with nl/1) after the term. If this is used together with the fullstop(true) option, this newline serves as the blank space after the fullstop. Default false.
fullstop(Bool) (ECLiPSe/SWI)
If true, terminate the term with a fullstop (a dot followed by blank space), so it can be read back. The blank space after the dot is a newline if the nl(true) option is present, otherwise a space character. If necessary, an extra space will be inserted before the fullstop, in order to separate it from the end of the term.
priority(Prec) (Sicstus,SWI,GP,Ciao,ECLiPSe) or precedence(Prec) (ECLiPSe)
Prec is an integer between 0 and 1200 (default 1200), representing context operator precedence. Can be used to force correct parenthesizing when partial terms are written as arguments of operators. The written term will be enclosed in parentheses if its precedence is higher than Prec.
max_depth(N) (Sicstus,SWI,ECLiPSe,GP,Ciao) or maxdepth(N) (IF)
If MaxDepth is a positive integer, print the term only up to a maximum nesting depth of MaxDepth, and represent more deeply nested subterms as ... . If 0, impose no depth limit. IF-Prolog also has maxdepth(N,TermAbbrev,ListAbbrev) for specifying the atoms that are used to abbreviate the omitted subterms.

Meaningful, but of lesser interest:

dotlists(Bool) (ECLiPSe,SWI)
If false (default), write lists in the common square bracket notation, e.g. [1, 2]. If true, write lists in the dot functor notation, e.g. .(1, .(2, [])). This is subsumed by the ignore_ops option.
brace_terms(Bool) (SWI)
If true (default), write {}(X) as {X}. See also dot_lists and ignore_ops.

To be discussed:

spacing(Atom) (SWI) or compact(Bool) (ECLiPSe) or space_args(Bool) (GP)
Specifies whether and where to print extra spaces for readability. Default is to print spaces only where needed to avoid syntactical ambiguity. TBD: agree on possible values, e.g. minimal, standard, next_argument, around_operators, etc. .
character_escapes(Bool) (SWI)
If true and quoted(true) is active, special characters in quoted atoms and strings are emitted as ISO escape sequences. TBD: as opposed to what exactly?

In the case where options conflict, the more specific one should take precedence, e.g. dotlists over ignore_ops.

Options meaningful only with other extensions:

portrayed(Bool) (Sicstus,ECLiPSe,IF,GP,Ciao,SWI) or portray(Bool) (SWI)
If true, call the user-defined predicate portray/1,2 in the way print/1,2 does. Note that print/portray/1 is traditional. ISO doesn't define print/portray at all. ECLiPSe prefers print/portray/2 with stream argument.
attributes(Atom) (ECLiPSe,SWI)
Determines how variable attributes are printed. Options are: do not print attributes (none or ignore); print {...} (dots); print the attributes as subterms surrounded by curly braces (full or write); pretty-print the arrtributes (pretty or portray). Default is none. TBD: agree on the names.
cycles(Bool) (Sicstus,SWI)
If true (default), cyclic terms are written as @(Template, Substitutions), where Substitutions is a list Var = Value. TBD: since this syntax conflicts with other uses of @/2, it would be preferable to have cycles(Atom) to be able to specify different alternatives for representing cycles.
float_format(Atom) (Sicstus)
How to print floats. This is sensible, but unfortunately defined in terms of non-standard format/2,3. IF-Prolog may have a better format spec for its float_format/2 builtin.
Edit - History - Print - Recent Changes - Search
Page last modified on March 07, 2022, at 05:41 PM