Basic input/output stream operations

Author(s): Daniel Cabeza, Mats Carlsson, Jose F. Morales (minor).

This module provides the basic input/output operations on streams (byte/code input/output and canonical term output). Most predicates are provided in two versions: one that specifies the input or output stream as the first argument and a second which omits this argument and uses the current input or output stream.

From the ISO-Prolog predicates for character input/output, only the _code versions are provided, the _char versions are given by library(iso_char).

Documentation on exports

PREDICATEget_code/2
get_code(Stream,Code)

Reads from Stream the next character and unifies Code with its character code. At end of stream, unifies Code with the integer -1.

Usage:ISO

  • Calls should, and exit will be compatible with:
    (basic_props:int/1)Code is an integer.
  • The following properties should hold at call time:
    (stream_basic:stream/1)Stream is an open stream.
  • The following properties hold upon exit:
    (basic_props:int/1)Code is an integer.
  • The following properties hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATEget_code/1
get_code(Code)

Behaves like current_input(S), get_code(S,Code).

Usage:ISO

  • Calls should, and exit will be compatible with:
    (basic_props:int/1)Code is an integer.
  • The following properties hold upon exit:
    (basic_props:int/1)Code is an integer.
  • The following properties hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATEget1_code/2
get1_code(Stream,Code)

Reads from Stream the next non-layout character (see code_class/2) and unifies Code with its character code. At end of stream, unifies Code with the integer -1.

Usage:

  • Calls should, and exit will be compatible with:
    (basic_props:int/1)Code is an integer.
  • The following properties should hold at call time:
    (stream_basic:stream/1)Stream is an open stream.
  • The following properties hold upon exit:
    (basic_props:int/1)Code is an integer.
  • The following properties hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATEget1_code/1
get1_code(Code)

Behaves like current_input(S), get1_code(S,Code).

Usage:

  • Calls should, and exit will be compatible with:
    (basic_props:int/1)Code is an integer.
  • The following properties hold upon exit:
    (basic_props:int/1)Code is an integer.
  • The following properties hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATEpeek_code/2
peek_code(Stream,Code)

Unifies Code with the character code of the next character of Stream, leaving the stream position unaltered. At end of stream, unifies Code with the integer -1.

Usage:ISO

PREDICATEpeek_code/1
peek_code(Code)

Behaves like current_input(S), peek_code(S,Code).

Usage:ISO

PREDICATEskip_code/2
skip_code(Stream,Code)

Skips just past the next character code Code from Stream.

Usage:

PREDICATEskip_code/1
skip_code(Code)

Behaves like current_input(S), skip_code(S,Code).

Usage:

  • The following properties should hold at call time:
    (basic_props:int/1)Code is an integer.

PREDICATEskip_line/1
skip_line(Stream)

Skips from Stream the remaining input characters on the current line. If the end of the stream is reached, the stream will stay at its end. Portable among different operating systems.

Usage:

PREDICATEskip_line/0
skip_line

Behaves like current_input(S), skip_line(S).

PREDICATEput_code/2
put_code(Stream,Code)

Outputs to Stream the character corresponding to character code Code.

Usage:ISO

PREDICATEput_code/1
put_code(Code)

Behaves like current_output(S), put_code(S,Code).

Usage:ISO

PREDICATEnl/1
nl(Stream)

Outputs a newline character to Stream. Equivalent to put_code(Stream, 0'\n).

Usage:ISO

PREDICATEnl/0
nl

Behaves like current_output(S), nl(S).

Usage:ISO

PREDICATEtab/2
tab(Stream,Num)

Outputs Num spaces to Stream.

Usage:

PREDICATEtab/1
tab(Num)

Behaves like current_output(S), tab(S,Num).

Usage:

PREDICATEcode_class/2
code_class(Code,Class)

Unifies Class with an integer corresponding to the lexical class of the character whose code is Code, with the following correspondence:

0 - layout (includes space, newline, tab)
1 - small letter
2 - capital letter (including '_')
3 - digit
4 - graphic (includes #$&*+-./:<=>?@^\`~ )
5 - punctuation (includes !;"'%(),[]{|} )
6 - extended identifier continuation
7 - invalid
Note that in ISO-Prolog the back quote ` is a punctuation character, whereas in Ciao it is a graphic character. Thus, if compatibility with ISO-Prolog is desired, the programmer should not use this character in unquoted names.

Usage:

  • Calls should, and exit will be compatible with:
    (basic_props:int/1)Class is an integer.
  • The following properties should hold at call time:
    (basic_props:int/1)Code is an integer.
  • The following properties hold upon exit:
    (basic_props:int/1)Class is an integer.

string_bytes(String,Bytes)

String is the list of the character codes encoded by the list of bytes Bytes (equivalent to String=Bytes if any of the lists is a list of ASCII codes).

PREDICATEgetct/2
getct(Code,Type)

Reads from the current input stream the next character, unifying Code with its character code, and Type with its lexical class. At end of stream, unifies both Code and Type with the integer -1. Equivalent to

   get(Code), (Code = -1 -> Type = -1 ; code_class(Code,Type))

Usage:

PREDICATEgetct1/2
getct1(Code,Type)

Reads from the current input stream the next non-layout character, unifying Code with its character code, and Type with its lexical class (which will be nonzero). At end of stream, unifies both Code and Type with the integer -1. Equivalent to

   get1(Code), (Code = -1 -> Type = -1 ; code_class(Code,Type))

Usage:

PREDICATEget_byte/2
get_byte(Stream,Byte)

Reads from Stream the next byte and unifies it with Byte. At end of stream, unifies Byte with the integer -1.

Usage:ISO

  • Calls should, and exit will be compatible with:
    (basic_props:int/1)Byte is an integer.
  • The following properties should hold at call time:
    (stream_basic:stream/1)Stream is an open stream.
  • The following properties hold upon exit:
    (basic_props:int/1)Byte is an integer.
  • The following properties hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATEget_byte/1
get_byte(Byte)

Behaves like current_input(S), get_byte(S,Byte).

Usage:ISO

  • Calls should, and exit will be compatible with:
    (basic_props:int/1)Byte is an integer.
  • The following properties hold upon exit:
    (basic_props:int/1)Byte is an integer.
  • The following properties hold globally:
    (basic_props:native/1)This predicate is understood natively by CiaoPP.

PREDICATEpeek_byte/2
peek_byte(Stream,Byte)

Unifies Byte with the next byte of Stream, leaving the stream position unaltered. At end of stream, unifies Byte with the integer -1.

Usage:ISO

PREDICATEpeek_byte/1
peek_byte(Byte)

Behaves like current_input(S), peek_byte(S,Byte).

Usage:ISO

PREDICATEput_byte/2
put_byte(Stream,Byte)

Outputs to Stream the byte Byte.

Usage:ISO

PREDICATEput_byte/1
put_byte(Byte)

Behaves like current_output(S), put_byte(S,Byte).

Usage:ISO

at_end_of_stream

Behaves like current_input(S), at_end_of_stream(S).

at_end_of_stream(Stream)

Stream has a stream position end-of-stream or past-end-of-stream. This predicate is provided for ISO compatibility, but its usage is discouraged, since it cannot reliably detect that no more data is available in the stream (e.g., without blocking). Use peek_byte/2 or peek_code/2 instead.

Usage:ISO

PREDICATEdisplay/2
display(Stream,Term)

Displays Term onto Stream. Lists are output using list notation, the other compound terms are output in functional notation. Similar to write_term(Stream, Term, [ignore_ops(ops)]), except that curly bracketed notation is not used with {}/1, and the write_strings flag is not honored.

Usage:

PREDICATEdisplay/1
display(Term)

Behaves like current_output(S), display(S,Term).

Usage:

PREDICATEdisplayq/2
displayq(Stream,Term)

Similar to display(Stream, Term), but atoms and functors that can't be read back by read_term/3 are quoted. Thus, similar to write_term(Stream, Term, [quoted(true), ignore_ops(ops)]), with the same exceptions as display/2.

Usage:

PREDICATEdisplayq/1
displayq(Term)

Behaves like current_output(S), displayq(S,Term).

Usage:

at_end_of_stream(Stream)

Stream has a stream position end-of-stream or past-end-of-stream. This predicate is provided for ISO compatibility, but its usage is discouraged, since it cannot reliably detect that no more data is available in the stream (e.g., without blocking). Use peek_byte/2 or peek_code/2 instead.

Usage:ISO

at_end_of_stream

Behaves like current_input(S), at_end_of_stream(S).

Documentation on imports

This module has the following direct dependencies: