Previous Up Next

8.15  Input/output from/to constant terms

These built-in predicates enable a Prolog term to be input from or output to a Prolog constant term (atom, character list or character code list). All these predicates can be defined using constant term streams (section 8.11). They are however simpler to use.

8.15.1  read_term_from_atom/3, read_from_atom/2, read_token_from_atom/2

Templates

read_term_from_atom(+atom ?term, +read_option_list)
read_from_atom(+atom, ?term)
read_token_from_atom(+atom, ?nonvar)

Description

Like read_term/3, read/2 (section 8.14.1) and read_token/2 (section 8.14.3) except that characters are not read from a text-stream but from Atom; the atom given as first argument.

Errors

Atom is a variable  instantiation_error
Atom is neither a variable nor an atom  type_error(atom, Atom)
see associated predicate errors  (section 8.14.1) and (section 8.14.3)

Portability

GNU Prolog predicates.

8.15.2  read_term_from_chars/3, read_from_chars/2, read_token_from_chars/2

Templates

read_term_from_chars(+character_list ?term, +read_option_list)
read_from_chars(+character_list, ?term)
read_token_from_chars(+character_list, ?nonvar)

Description

Like read_term/3, read/2 (section 8.14.1) and read_token/2 (section 8.14.3) except that characters are not read from a text-stream but from Chars; the character list given as first argument.

Errors

Chars is a partial list or a list with an element E which is a variable  instantiation_error
Chars is neither a partial list nor a list  type_error(list, Chars)
an element E of the Chars list is neither a variable nor a character  type_error(character, E)
see associated predicate errors  (section 8.14.1) and (section 8.14.3)

Portability

GNU Prolog predicates.

8.15.3  read_term_from_codes/3, read_from_codes/2, read_token_from_codes/2

Templates

read_term_from_codes(+character_code_list ?term, +read_option_list)
read_from_codes(+character_code_list, ?term)
read_token_from_codes(+character_code_list, ?nonvar)

Description

Like read_term/3, read/2 (section 8.14.1) and read_token/2 (section 8.14.3) except that characters are not read from a text-stream but from Codes; the character code list given as first argument.

Errors

Codes is a partial list or a list with an element E which is a variable  instantiation_error
Codes is neither a partial list nor a list  type_error(list, Codes)
an element E of the Codes list is neither a variable nor an integer  type_error(integer, E)
an element E of the Codes list is an integer but not a character code  representation_error(character_code, E)
see associated predicate errors  (section 8.14.1) and (section 8.14.3)

Portability

GNU Prolog predicates.

8.15.4  write_term_to_atom/3, write_to_atom/2, writeq_to_atom/2,
write_canonical_to_atom/2, display_to_atom/2, print_to_atom/2,
format_to_atom/3

Templates

write_term_to_atom(?atom, ?term, +write_option_list)
write_to_atom(?atom, ?term)
writeq_to_atom(?atom, ?term)
write_canonical_to_atom(?atom, ?term)
display_to_atom(?atom, ?term)
print_to_atom(?atom, ?term)
format_to_atom(?atom, +character_code_list_or_atom, +list)

Description

Similar to write_term/3, write/2, writeq/2, write_canonical/2, display/2, print/2 (section 8.14.6) and format/3 (section 8.14.7) except that characters are not written onto a text-stream but are collected as an atom which is then unified with the first argument Atom.

Errors

Atom is neither a variable nor an atom  type_error(atom, Atom)
see associated predicate errors  (section 8.14.6) and (section 8.14.7)

Portability

GNU Prolog predicates.

8.15.5  write_term_to_chars/3, write_to_chars/2, writeq_to_chars/2,
write_canonical_to_chars/2, display_to_chars/2, print_to_chars/2,
format_to_chars/3

Templates

write_term_to_chars(?character_list, ?term, +write_option_list)
write_to_chars(?character_list, ?term)
writeq_to_chars(?character_list, ?term)
write_canonical_to_chars(?character_list, ?term)
display_to_chars(?character_list, ?term)
print_to_chars(?character_list, ?term)
format_to_chars(?character_list, +character_code_list_or_atom, +list)

Description

Similar to write_term/3, write/2, writeq/2, write_canonical/2, display/2, print/2 (section 8.14.6) and format/3 (section 8.14.7) except that characters are not written onto a text-stream but are collected as a character list which is then unified with the first argument Chars.

Errors

Chars is neither a partial list nor a list  type_error(list, Chars)
An element E of the list Chars is neither a variable nor a one-char atom  type_error(character, E)
see associated predicate errors  (section 8.14.6) and (section 8.14.7)

Portability

GNU Prolog predicates.

8.15.6  write_term_to_codes/3, write_to_codes/2, writeq_to_codes/2,
write_canonical_to_codes/2, display_to_codes/2, print_to_codes/2,
format_to_codes/3

Templates

write_term_to_codes(?character_code_list, ?term, +write_option_list)
write_to_codes(?character_code_list, ?term)
writeq_to_codes(?character_code_list, ?term)
write_canonical_to_codes(?character_code_list, ?term)
display_to_codes(?character_code_list, ?term)
print_to_codes(?character_code_list, ?term)
format_to_codes(?character_code_list, +character_code_list_or_atom, +list)

Description

Similar to write_term/3, write/2, writeq/2, write_canonical/2, display/2, print/2 (section 8.14.6) and format/3 (section 8.14.7) except that characters are not written onto a text-stream but are collected as a character code list which is then unified with the first argument Codes.

Errors

Codes is neither a partial list nor a list  type_error(list, Codes)
An element E of the list Codes is neither a variable nor an integer  type_error(integer, E)
An element E of the list Codes is an integer but not a character code  representation_error(character_code)
see associated predicate errors  (section 8.14.6) and (section 8.14.7)

Portability

GNU Prolog predicates.


Copyright (C) 1999-2013 Daniel Diaz Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. More about the copyright
Previous Up Next