<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <META name="GENERATOR" content="hevea 1.06-7 of 2001-11-14"> <TITLE> Input/output from/to constant terms </TITLE> </HEAD> <BODY TEXT=black BGCOLOR=white> <A HREF="manual037.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="manual023.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual039.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> <HR> <TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#66dbff"><DIV ALIGN=center><TABLE> <TR><TD><FONT SIZE=4><B><A NAME="htoc164">7.15</A></B></FONT></TD> <TD WIDTH="100%" ALIGN=center><FONT SIZE=4><B>Input/output from/to constant terms</B></FONT></TD> </TR></TABLE></DIV></TD> </TR></TABLE><UL> <LI><A HREF="manual038.html#toc128"> <TT>read_term_from_atom/3</TT>, <TT>read_from_atom/2</TT>, <TT>read_token_from_atom/2</TT></A> <LI><A HREF="manual038.html#toc129"> <TT>read_term_from_chars/3</TT>, <TT>read_from_chars/2</TT>, <TT>read_token_from_chars/2</TT></A> <LI><A HREF="manual038.html#toc130"> <TT>read_term_from_codes/3</TT>, <TT>read_from_codes/2</TT>, <TT>read_token_from_codes/2</TT></A> <LI><A HREF="manual038.html#toc131"> <TT>write_term_to_atom/3</TT>, <TT>write_to_atom/2</TT>, <TT>writeq_to_atom/2</TT>,<BR> <TT>write_canonical_to_atom/2</TT>, <TT>display_to_atom/2</TT>, <TT>print_to_atom/2</TT>,<BR> <TT>format_to_atom/3</TT></A> <LI><A HREF="manual038.html#toc132"> <TT>write_term_to_chars/3</TT>, <TT>write_to_chars/2</TT>, <TT>writeq_to_chars/2</TT>,<BR> <TT>write_canonical_to_chars/2</TT>, <TT>display_to_chars/2</TT>, <TT>print_to_chars/2</TT>,<BR> <TT>format_to_chars/3</TT></A> <LI><A HREF="manual038.html#toc133"> <TT>write_term_to_codes/3</TT>, <TT>write_to_codes/2</TT>, <TT>writeq_to_codes/2</TT>,<BR> <TT>write_canonical_to_codes/2</TT>, <TT>display_to_codes/2</TT>, <TT>print_to_codes/2</TT>,<BR> <TT>format_to_codes/3</TT></A> </UL> <A NAME="Input/output-from/to-constant-terms"></A> 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 <A HREF="manual034.html#Constant-term-streams">7.11</A>). They are however simpler to use.<BR> <BR> <A NAME="toc128"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc165">7.15.1</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>read_term_from_atom/3</TT>, <TT>read_from_atom/2</TT>, <TT>read_token_from_atom/2</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="read-term-from-atom/3"></A> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> read_term_from_atom(+atom ?term, +read_option_list)<BR> read_from_atom(+atom, ?term)<BR> read_token_from_atom(+atom, ?nonvar)</TT></DL> <B>Description</B><BR> <BR> Like <TT>read_term/3</TT>, <TT>read/2</TT> (section <A HREF="manual037.html#read-term/3">7.14.1</A>) and <TT>read_token/2</TT> (section <A HREF="manual037.html#read-token/2">7.14.3</A>) except that characters are not read from a text-stream but from <TT>Atom</TT>; the atom given as first argument.<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Atom</TT> is a variable</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Atom</TT> is neither a variable nor an atom</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(atom, Atom)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>see associated predicate errors</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left>(section <A HREF="manual037.html#read-term/3">7.14.1</A>) and (section <A HREF="manual037.html#read-token/2">7.14.3</A>)</TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc129"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc166">7.15.2</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>read_term_from_chars/3</TT>, <TT>read_from_chars/2</TT>, <TT>read_token_from_chars/2</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> read_term_from_chars(+character_list ?term, +read_option_list)<BR> read_from_chars(+character_list, ?term)<BR> read_token_from_chars(+character_list, ?nonvar)</TT></DL> <B>Description</B><BR> <BR> Like <TT>read_term/3</TT>, <TT>read/2</TT> (section <A HREF="manual037.html#read-term/3">7.14.1</A>) and <TT>read_token/2</TT> (section <A HREF="manual037.html#read-token/2">7.14.3</A>) except that characters are not read from a text-stream but from <TT>Chars</TT>; the character list given as first argument.<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Chars</TT> is a partial list or a list with an element <TT>E</TT> which is a variable</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Chars</TT> is neither a partial list nor a list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(list, Chars)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>an element <TT>E</TT> of the <TT>Chars</TT> list is neither a variable nor a character</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(character, E)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>see associated predicate errors</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left>(section <A HREF="manual037.html#read-term/3">7.14.1</A>) and (section <A HREF="manual037.html#read-token/2">7.14.3</A>)</TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc130"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc167">7.15.3</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>read_term_from_codes/3</TT>, <TT>read_from_codes/2</TT>, <TT>read_token_from_codes/2</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> read_term_from_codes(+character_code_list ?term, +read_option_list)<BR> read_from_codes(+character_code_list, ?term)<BR> read_token_from_codes(+character_code_list, ?nonvar)</TT></DL> <B>Description</B><BR> <BR> Like <TT>read_term/3</TT>, <TT>read/2</TT> (section <A HREF="manual037.html#read-term/3">7.14.1</A>) and <TT>read_token/2</TT> (section <A HREF="manual037.html#read-token/2">7.14.3</A>) except that characters are not read from a text-stream but from <TT>Codes</TT>; the character code list given as first argument.<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Codes</TT> is a partial list or a list with an element <TT>E</TT> which is a variable</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Codes</TT> is neither a partial list nor a list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(list, Codes)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>an element <TT>E</TT> of the <TT>Codes</TT> list is neither a variable nor an integer</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(integer, E)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>an element <TT>E</TT> of the <TT>Codes</TT> list is an integer but not a character code</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>representation_error(character_code, E)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>see associated predicate errors</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left>(section <A HREF="manual037.html#read-term/3">7.14.1</A>) and (section <A HREF="manual037.html#read-token/2">7.14.3</A>)</TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc131"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc168">7.15.4</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>write_term_to_atom/3</TT>, <TT>write_to_atom/2</TT>, <TT>writeq_to_atom/2</TT>,<BR> <TT>write_canonical_to_atom/2</TT>, <TT>display_to_atom/2</TT>, <TT>print_to_atom/2</TT>,<BR> <TT>format_to_atom/3</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> write_term_to_atom(?atom, ?term, +write_option_list)<BR> write_to_atom(?atom, ?term)<BR> writeq_to_atom(?atom, ?term)<BR> write_canonical_to_atom(?atom, ?term)<BR> display_to_atom(?atom, ?term)<BR> print_to_atom(?atom, ?term)<BR> format_to_atom(?atom, +character_code_list_or_atom, +list)</TT></DL> <B>Description</B><BR> <BR> Similar to <TT>write_term/3</TT>, <TT>write/2</TT>, <TT>writeq/2</TT>, <TT>write_canonical/2</TT>, <TT>display/2</TT>, <TT>print/2</TT> (section <A HREF="manual037.html#write-term/3">7.14.6</A>) and <TT>format/3</TT> (section <A HREF="manual037.html#format/3">7.14.7</A>) except that characters are not written onto a text-stream but are collected as an atom which is then unified with the first argument <TT>Atom</TT>.<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Atom</TT> is neither a variable nor an atom</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(atom, Atom)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>see associated predicate errors</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left>(section <A HREF="manual037.html#write-term/3">7.14.6</A>) and (section <A HREF="manual037.html#format/3">7.14.7</A>)</TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc132"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc169">7.15.5</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>write_term_to_chars/3</TT>, <TT>write_to_chars/2</TT>, <TT>writeq_to_chars/2</TT>,<BR> <TT>write_canonical_to_chars/2</TT>, <TT>display_to_chars/2</TT>, <TT>print_to_chars/2</TT>,<BR> <TT>format_to_chars/3</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> write_term_to_chars(?character_list, ?term, +write_option_list)<BR> write_to_chars(?character_list, ?term)<BR> writeq_to_chars(?character_list, ?term)<BR> write_canonical_to_chars(?character_list, ?term)<BR> display_to_chars(?character_list, ?term)<BR> print_to_chars(?character_list, ?term)<BR> format_to_chars(?character_list, +character_code_list_or_atom, +list)</TT></DL> <B>Description</B><BR> <BR> Similar to <TT>write_term/3</TT>, <TT>write/2</TT>, <TT>writeq/2</TT>, <TT>write_canonical/2</TT>, <TT>display/2</TT>, <TT>print/2</TT> (section <A HREF="manual037.html#write-term/3">7.14.6</A>) and <TT>format/3</TT> (section <A HREF="manual037.html#format/3">7.14.7</A>) 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 <TT>Chars</TT>.<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Chars</TT> is neither a partial list nor a list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(list, Chars)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>see associated predicate errors</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left>(section <A HREF="manual037.html#write-term/3">7.14.6</A>) and (section <A HREF="manual037.html#format/3">7.14.7</A>)</TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc133"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc170">7.15.6</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>write_term_to_codes/3</TT>, <TT>write_to_codes/2</TT>, <TT>writeq_to_codes/2</TT>,<BR> <TT>write_canonical_to_codes/2</TT>, <TT>display_to_codes/2</TT>, <TT>print_to_codes/2</TT>,<BR> <TT>format_to_codes/3</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> write_term_to_codes(?character_code_list, ?term, +write_option_list)<BR> write_to_codes(?character_code_list, ?term)<BR> writeq_to_codes(?character_code_list, ?term)<BR> write_canonical_to_codes(?character_code_list, ?term)<BR> display_to_codes(?character_code_list, ?term)<BR> print_to_codes(?character_code_list, ?term)<BR> format_to_codes(?character_code_list, +character_code_list_or_atom, +list)</TT></DL> <B>Description</B><BR> <BR> Similar to <TT>write_term/3</TT>, <TT>write/2</TT>, <TT>writeq/2</TT>, <TT>write_canonical/2</TT>, <TT>display/2</TT>, <TT>print/2</TT> (section <A HREF="manual037.html#write-term/3">7.14.6</A>) and <TT>format/3</TT> (section <A HREF="manual037.html#format/3">7.14.7</A>) 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 <TT>Codes</TT>.<BR> <BR> <B>Errors</B><BR> <TABLE CELLSPACING=2 CELLPADDING=0> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left><TT>Codes</TT> is neither a partial list nor a list</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(list, Codes)</TT></TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR> <TR><TD VALIGN=top ALIGN=left>see associated predicate errors</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left>(section <A HREF="manual037.html#write-term/3">7.14.6</A>) and (section <A HREF="manual037.html#format/3">7.14.7</A>)</TD> </TR> <TR><TD BGCOLOR=black COLSPAN=3><TABLE BORDER=0 WIDTH="100%" CELLSPACING=0 CELLPADDING=1><TR><TD></TD></TR></TABLE></TD> </TR></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <HR SIZE=2> Copyright (C) 1999-2002 Daniel Diaz <BR> <BR> Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. <BR> <BR> <A HREF="index.html#copyright">More about the copyright</A> <HR> <A HREF="manual037.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="manual023.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual039.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> </BODY> </HTML>