# Term input

Author(s): Daniel Cabeza (modifications and documentation, adapted from SICStus 0.6 code), Manuel Carro (modifications and documentation), Jose F. Morales (modifications for curly blocks,postfix blocks, infix dot, string constants, and doccomments), Manuel Hermenegildo (minor in documentation).

This module provides facilities for reading terms in Prolog syntax. This is very convenient in many cases (and not only if you are writing a Prolog compiler) because Prolog terms are easy to write and can encode a large amount of information in a human-readable fashion. Note that, in addition, the use of operator definitions makes it possible to enhance the readibility of such terms, or, for example, data files composed of Prolog terms.

The behavior of these reading predicates can be modified in two ways:

• The operators that are active at run time when the reading predicate is called (see Defining operators).

• A number of flags (see below) which control how some special terms are read in or activate some syntax extensions.

## Documentation on exports

Like read(Stream,Term) with Stream associated to the current input stream.

Usage:ISO

• Call and exit should be compatible with:
Term is any term.
• The following properties should hold upon exit:
Term is any term.

The next term, delimited by a full-stop (i.e., a . followed by either a space or a control character), is read from Stream and is unified with Term. The syntax of the term must agree with current operator declarations. If the end of Stream has been reached, Term is unified with the term end_of_file. Further calls to read/2 for the same stream will then cause an error, unless the stream is connected to the terminal (in which case a prompt is opened on the terminal).

• The following properties should hold at call time:
Stream is currently a term which is not a free variable.
Stream is an open stream.
Term is any term.

• The following properties should hold at call time:
Options is currently a term which is not a free variable.
Term is any term.
Options is a list of read_options.

Reads a Term from Stream with the ISO-Prolog Options. These options can control the behavior of read term (see read_option/1).

• The following properties should hold at call time:
Stream is currently a term which is not a free variable.
Options is currently a term which is not a free variable.
Stream is an open stream.
Term is any term.
Options is a list of read_options.

Predicate used to read in the Top Level.

Usage:second_prompt(Old,New)

Changes the prompt (the second prompt, as opposed to the first one, used by the toplevel) used by read/2 and friends to New, and returns the current one in Old.

• The following properties should hold upon exit:
Old is currently instantiated to an atom.
New is currently instantiated to an atom.

Option is an allowed read_term/[2,3] option. These options are:

read_option(variables(_V)).

They can be used to return the singleton variables in the term, a list of variables, etc.

## Documentation on multifiles

PREDICATEdefine_flag/3
The folowing flags are defined:
define_flag(read_hiord,[on,off],off).

(See Changing system behaviour and various flags).

If flag is on (it is off by default), a variable followed by a parenthesized list of arguments is read as a call/N term, except if the variable is anonymous, in which case it is read as an anonymous predicate abstraction head. For example, P(X) is read as call(P,X) and _(X,Y) as ”(X,Y).

When enabled, read terms of the form '{ <list of sentences> }'.

When enabled, allow '<term> <term>' as valid terms.

When enabled, strings are read as '\6\string' terms (not as lists).

When enabled, infix dot '.' is read as '\6\dot' terms (not as a list).

Usage:define_flag(Flag,FlagValues,Default)

• The following properties hold upon exit:
Flag is an atom.
Define the valid flag values
The predicate is multifile.

## Documentation on imports

This module has the following direct dependencies:

## Known bugs and planned improvements

• The comma cannot be redefined as an operator, it is defined in any case as op(1000, xfy,[',']).