<!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> Constant term streams </TITLE> </HEAD> <BODY TEXT=black BGCOLOR=white> <A HREF="manual033.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="manual023.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual035.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="htoc133">7.11</A></B></FONT></TD> <TD WIDTH="100%" ALIGN=center><FONT SIZE=4><B>Constant term streams</B></FONT></TD> </TR></TABLE></DIV></TD> </TR></TABLE><UL> <LI><A HREF="manual034.html#toc101"> Introduction</A> <LI><A HREF="manual034.html#toc102"> <TT>open_input_atom_stream/2</TT>, <TT>open_input_chars_stream/2</TT>,<BR> <TT>open_input_codes_stream/2</TT></A> <LI><A HREF="manual034.html#toc103"> <TT>close_input_atom_stream/1</TT>, <TT>close_input_chars_stream/1</TT>,<BR> <TT>close_input_codes_stream/1</TT></A> <LI><A HREF="manual034.html#toc104"> <TT>open_output_atom_stream/1</TT>, <TT>open_output_chars_stream/1</TT>,<BR> <TT>open_output_codes_stream/1</TT></A> <LI><A HREF="manual034.html#toc105"> <TT>close_output_atom_stream/2</TT>, <TT>close_output_chars_stream/2</TT>,<BR> <TT>close_output_codes_stream/2</TT></A> </UL> <A NAME="Constant-term-streams"></A><BR> <A NAME="toc101"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc134">7.11.1</A></B></TD> <TD WIDTH="100%" ALIGN=center><B>Introduction</B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="Introduction:(Constant-term-streams)"></A> Constant term streams allow the user to consider a constant term (atom, character list or character code list) as a source/sink by associating to them a stream. Reading from a constant term stream will deliver the characters of the constant term as if they had been read from a standard file. Characters written on a constant term stream are stored to form the final constant term when the stream is closed. The built-in predicates described in this section allow the user to open and close a constant term stream for input or output. However, very often, a constant term stream is created to be only read or written once and then closed. To avoid the creation and the destruction of such a stream, GNU Prolog offers several built-in predicates to perform single input/output from/to constant terms (section <A HREF="manual038.html#Input/output-from/to-constant-terms">7.15</A>).<BR> <BR> <A NAME="toc102"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc135">7.11.2</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>open_input_atom_stream/2</TT>, <TT>open_input_chars_stream/2</TT>,<BR> <TT>open_input_codes_stream/2</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> open_input_atom_stream(+atom, -stream)<BR> open_input_chars_stream(+character_list, -stream)<BR> open_input_codes_stream(+character_code_list, -stream)</TT></DL> <B>Description</B><BR> <BR> <TT>open_input_atom_stream(Atom, Stream)</TT> unifies <TT>Stream</TT> with the stream-term which is associated to a new input text-stream whose data are the characters of <TT>Atom</TT>.<BR> <BR> <TT>open_input_chars_stream(Chars, Stream)</TT> is similar to <TT>open_input_atom_stream/2</TT> except that data are the content of the character list <TT>Chars</TT>.<BR> <BR> <TT>open_input_codes_stream(Codes, Stream)</TT> is similar to <TT>open_input_atom_stream/2</TT> except that data are the content of the character code list <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>Stream</TT> is not a variable</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(variable, Stream)</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 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 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 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>Atom</TT> is neither a variable nor a 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><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><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>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>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)</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></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc103"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc136">7.11.3</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>close_input_atom_stream/1</TT>, <TT>close_input_chars_stream/1</TT>,<BR> <TT>close_input_codes_stream/1</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> close_input_atom_stream(+stream_or_alias)<BR> close_input_chars_stream(+stream_or_alias)<BR> close_input_codes_stream(+stream_or_alias)</TT></DL> <B>Description</B><BR> <BR> <TT>close_input_atom_stream(SorA)</TT> closes the constant term stream associated with the stream-term or alias <TT>SorA</TT>. <TT>SorA</TT> must a stream open with <TT>open_input_atom_stream/2</TT> (section <A HREF="#Introduction:(Constant-term-streams)">7.11.1</A>).<BR> <BR> <TT>close_input_chars_stream(SorA)</TT> acts similarly for a character list stream.<BR> <BR> <TT>close_input_codes_stream(SorA)</TT> acts similarly for a character code list stream.<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>SorA</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>SorA</TT> is neither a variable nor a stream-term or alias</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>domain_error(stream_or_alias, SorA)</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>SorA</TT> is not associated with an open stream</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>existence_error(stream, SorA)</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>SorA</TT> is an output stream</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>permission_error(close, stream, SorA)</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>SorA</TT> is a stream-term or alias but does not refer to a constant term stream.</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>domain_error(term_stream_or_alias, SorA)</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></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc104"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc137">7.11.4</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>open_output_atom_stream/1</TT>, <TT>open_output_chars_stream/1</TT>,<BR> <TT>open_output_codes_stream/1</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="open-output-atom-stream/1"></A> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> open_output_atom_stream(-stream)<BR> open_output_chars_stream(-stream)<BR> open_output_codes_stream(-stream)</TT></DL> <B>Description</B><BR> <BR> <TT>open_output_atom_stream(Stream)</TT> unifies <TT>Stream</TT> with the stream-term which is associated to a new output text-stream. All characters written to this stream are collected and will be returned as an atom when the stream is closed by <TT>close_ouput_atom_stream/2</TT> (section <A HREF="#close-output-atom-stream/2">7.11.5</A>).<BR> <BR> <TT>open_output_chars_stream(Stream)</TT> is similar to <TT>open_output_atom_stream/1</TT> except that the result will be a character list.<BR> <BR> <TT>open_output_codes_stream(Stream)</TT> is similar to <TT>open_output_atom_stream/1</TT> except that the result will be a character code list.<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>Stream</TT> is not a variable</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>type_error(variable, Stream)</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></TABLE><BR> <B>Portability</B><BR> <BR> GNU Prolog predicates.<BR> <BR> <A NAME="toc105"></A><TABLE CELLPADDING=0 CELLSPACING=0 WIDTH="100%"> <TR><TD BGCOLOR="#98e7ff"><DIV ALIGN=center><TABLE> <TR><TD><B><A NAME="htoc138">7.11.5</A></B></TD> <TD WIDTH="100%" ALIGN=center><B><TT>close_output_atom_stream/2</TT>, <TT>close_output_chars_stream/2</TT>,<BR> <TT>close_output_codes_stream/2</TT></B></TD> </TR></TABLE></DIV></TD> </TR></TABLE> <A NAME="close-output-atom-stream/2"></A> <BR> <B>Templates</B> <DL COMPACT=compact><DT><DD><TT> close_output_atom_stream(+stream_or_alias, ?atom)<BR> close_output_chars_stream(+stream_or_alias, ?character_list)<BR> close_output_codes_stream(+stream_or_alias, ?character_code_list)</TT></DL> <B>Description</B><BR> <BR> <TT>close_output_atom_stream(SorA, Atom)</TT> closes the constant term stream associated with the stream-term or alias <TT>SorA</TT>. <TT>SorA</TT> must be associated to a stream open with <TT>open_output_atom_stream/1</TT> (section <A HREF="#open-output-atom-stream/1">7.11.4</A>). <TT>Atom</TT> is unified with an atom formed with all characters written on the stream.<BR> <BR> <TT>close_output_chars_stream(SorA, Chars)</TT> acts similarly for a character list stream.<BR> <BR> <TT>close_output_codes_stream(SorA, Codes)</TT> acts similarly for a character code list stream.<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>SorA</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><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><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><TT>SorA</TT> is neither a variable nor a stream-term or alias</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>domain_error(stream_or_alias, SorA)</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>SorA</TT> is not associated with an open stream</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>existence_error(stream, SorA)</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>SorA</TT> is an input stream</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>permission_error(close, stream, SorA)</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>SorA</TT> is a stream-term or alias but does not refer to a constant term stream</TD> <TD VALIGN=top ALIGN=center NOWRAP> </TD> <TD VALIGN=top ALIGN=left><TT>domain_error(term_stream_or_alias, SorA)</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></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="manual033.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A> <A HREF="manual023.html"><IMG SRC ="contents_motif.gif" ALT="Contents"></A> <A HREF="manual035.html"><IMG SRC ="next_motif.gif" ALT="Next"></A> </BODY> </HTML>