Module console

This module supports access to the console. The first part consists of read utilities. Among the read utilities there are currently the predicates read_line/[1,2] and read_line_max/[2,3]. The former does an unbounded read the later does a bounded read.

Since the line read predicates work with a text stream and does not fully consume a line, so that it can cater for different line formats with CR LF, LF or CR termination, we introduced fur-ther predicates read_punch/[1,2] and read_punch_max/[2,3].

Example:
?- format('res=%20d',[123123123]), nl.
res=           123123123
Yes
?- format('res=%25.4f',[123123123.123]), nl.
res=           123123123.1230
Yes

The second part consist Quintus Prolog inspired formatted output predicates. Among the formatted output there are currently the predicates format/[2,3] with the difference that it currently only supports the Java formatting format.

Finally the predicates error_make/[2,3] can be used to retrieve the message of a Prolog exception term. Further the predicates print_stack_trace/[2,3] allows sending the message and the context of a Prolog exception term to a stream.

The following console predicates are provided:

read_line(C):
read_line(T, C):
The predicate succeeds in C in reading a line. The predicate fails upon an empty line and an end of file. The binary predicate allows specifying a text stream T.
read_line_max(L, C):
read_line_max(T, L, C):
The predicate succeeds in C in reading a line with maximally L characters. The predicate fails upon an empty line and an end of file. The ternary predicate allows specifying a text stream T.
read_punch(C):
read_punch(T, C):
The predicate succeeds in C in reading a punch. The predicate fails upon end of file. The punch must end in CR LF, otherwise an exception is thrown. The binary predicate allows specifying a binary stream T.
read_punch_max(L, C):
read_punch_max(T, L, C):
The predicate succeeds in C in reading a punch with maximally L bytes. The predicate fails upon end of file. If less than L bytes different from CR are read, the punch must end in CR LF otherwise an exception is thrown. The ternary predicate allows specifying a binary stream T.
format(F, A):
format(T, F, A):
The predicate formats the list of arguments A according to the format F using the cur-rent locale and writes it to the current output. The ternary predicate allows specifying a text stream T.
error_make(E, S):
error_make(L, E, S):
The predicate formats the error term E without its context unifies the result with S. The quaternary predicate allows specifying a locale L.
print_stack_trace(T, E):
print_stack_trace(L, T, E):
The predicate formats the error term E with the context to the output stream T. The quaternary predicate allows specifying a locale L.

Comments