Basic input/output
Author(s): Daniel Cabeza, Mats Carlsson.
This module provides predicates for character input/output and for canonical term output. From the ISO-Prolog predicates for character input/output, only the _code versions are provided, the rest are given by library(iso_byte_char), using these. 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.
Usage and interface
- Library usage:
These predicates are builtin in Ciao, so nothing special has to be done to use them. - Exports:
- Predicates:
get_code/2, get_code/1, get1_code/2, get1_code/1, peek_code/2, peek_code/1, skip_code/2, skip_code/1, skip_line/1, skip_line/0, put_code/2, put_code/1, nl/1, nl/0, tab/2, tab/1, code_class/2, getct/2, getct1/2, display/2, display/1, displayq/2, displayq/1.
- Predicates:
- Imports:
- System library modules:
assertions/native_props. - Packages:
prelude, nonpure, assertions, nortchecks, nativeprops, isomodes.
- System library modules:
Documentation on exports
Reads from Stream the next character and unifies Code with its character code. At end of stream, unifies Code with the integer -1.
(Trust) 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:
(streams_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.
Behaves like current_input(S), get_code(S,Code).
(Trust) 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.
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.
(Trust) 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:
(streams_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.
Behaves like current_input(S), get1_code(S,Code).
(Trust) 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.
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.
(Trust) 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:
(streams_basic:stream/1)Stream is an open stream. - The following properties hold upon exit:
(basic_props:int/1)Code is an integer.
Behaves like current_input(S), peek_code(S,Code).
(Trust) 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.
Skips just past the next character code Code from Stream.
(Trust) Usage:
- The following properties should hold at call time:
(streams_basic:stream/1)Stream is an open stream.
(basic_props:int/1)Code is an integer.
Behaves like current_input(S), skip_code(S,Code).
(Trust) Usage:
- The following properties should hold at call time:
(basic_props:int/1)Code is an integer.
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.
(Trust) Usage:
- The following properties should hold at call time:
(streams_basic:stream/1)Stream is an open stream.
Outputs to Stream the character corresponding to character code Code.
(Trust) Usage:ISO
- The following properties should hold at call time:
(streams_basic:stream/1)Stream is an open stream.
(basic_props:int/1)Code is an integer. - The following properties hold globally:
(basic_props:native/1)This predicate is understood natively by CiaoPP.
(native_props:is_det/1)All calls of the form put_code(Stream,Code) are deterministic.
Behaves like current_output(S), put_code(S,Code).
(Trust) Usage:ISO
- The following properties should hold at call time:
(basic_props:int/1)Code is an integer. - The following properties hold globally:
(basic_props:native/1)This predicate is understood natively by CiaoPP.
(native_props:is_det/1)All calls of the form put_code(Code) are deterministic.
Outputs a newline character to Stream. Equivalent to put_code(Stream, 0'\n).
(Trust) Usage:ISO
- The following properties should hold at call time:
(streams_basic:stream/1)Stream is an open stream. - The following properties hold globally:
(basic_props:native/1)This predicate is understood natively by CiaoPP.
(native_props:is_det/1)All calls of the form nl(Stream) are deterministic.
(native_props:not_fails/1)All the calls of the form nl(Stream) do not fail.
Behaves like current_output(S), nl(S).
(Trust) Usage:ISO
- The following properties hold globally:
(basic_props:native/1)This predicate is understood natively by CiaoPP.
(native_props:is_det/1)All calls of the form nl are deterministic.
(native_props:not_fails/1)All the calls of the form nl do not fail.
(native_props:relations/2)Goal nl produces 1 solutions.
Outputs Num spaces to Stream.
(Trust) Usage:
- The following properties should hold at call time:
(streams_basic:stream/1)Stream is an open stream.
(basic_props:int/1)Num is an integer. - The following properties hold globally:
(basic_props:native/1)This predicate is understood natively by CiaoPP.
(native_props:is_det/1)All calls of the form tab(Stream,Num) are deterministic.
Behaves like current_output(S), tab(S,Num).
(Trust) Usage:
- The following properties should hold at call time:
(basic_props:int/1)Num is an integer. - The following properties hold globally:
(basic_props:native/1)This predicate is understood natively by CiaoPP.
(native_props:is_det/1)All calls of the form tab(Num) are deterministic.
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 !;"'%(),[]{|} )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.
(Trust) 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.
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))
(Trust) Usage:
- Calls should, and exit will be compatible with:
(basic_props:int/1)Code is an integer.
(basic_props:int/1)Type is an integer. - The following properties hold upon exit:
(basic_props:int/1)Code is an integer.
(basic_props:int/1)Type is an integer.
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))
(Trust) Usage:
- Calls should, and exit will be compatible with:
(basic_props:int/1)Code is an integer.
(basic_props:int/1)Type is an integer. - The following properties hold upon exit:
(basic_props:int/1)Code is an integer.
(basic_props:int/1)Type is an integer.
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.
(Trust) Usage:
- The following properties should hold at call time:
(streams_basic:stream/1)Stream is an open stream.
(basic_props:term/1)Term is any term. - The following properties hold upon exit:
(basic_props:term/1)Term is any term. - The following properties hold globally:
(basic_props:not_further_inst/2)Term is not further instantiated.
(basic_props:native/1)This predicate is understood natively by CiaoPP.
Behaves like current_output(S), display(S,Term).
(Trust) Usage:
- The following properties should hold at call time:
(basic_props:term/1)Term is any term. - The following properties hold upon exit:
(basic_props:term/1)Term is any term. - The following properties hold globally:
(basic_props:not_further_inst/2)Term is not further instantiated.
(basic_props:native/1)This predicate is understood natively by CiaoPP.
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.
(Trust) Usage:
- The following properties should hold at call time:
(streams_basic:stream/1)Stream is an open stream.
(basic_props:term/1)Term is any term. - The following properties hold upon exit:
(basic_props:term/1)Term is any term. - The following properties hold globally:
(basic_props:not_further_inst/2)Term is not further instantiated.
Behaves like current_output(S), displayq(S,Term).
(Trust) Usage:
- The following properties should hold at call time:
(basic_props:term/1)Term is any term. - The following properties hold upon exit:
(basic_props:term/1)Term is any term. - The following properties hold globally:
(basic_props:not_further_inst/2)Term is not further instantiated.
Known bugs and planned improvements
- Run-time checks have been reported not to work with this code. That means that either the assertions here, or the code that implements the run-time checks are erroneous.