PageRenderTime 47ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/gprolog-1.4.0/doc/html_node/gprolog035.html

#
HTML | 207 lines | 202 code | 5 blank | 0 comment | 0 complexity | fad151f9daa10b311efe4aa4f32faf35 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
  2. "http://www.w3.org/TR/REC-html40/loose.dtd">
  3. <HTML>
  4. <HEAD>
  5. <META http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  6. <META name="GENERATOR" content="hevea 1.10">
  7. <LINK rel="stylesheet" type="text/css" href="gprolog.css">
  8. <TITLE>Constant term streams</TITLE>
  9. </HEAD>
  10. <BODY TEXT=black BGCOLOR=white>
  11. <A HREF="gprolog034.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
  12. <A HREF="gprolog024.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
  13. <A HREF="gprolog036.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
  14. <HR>
  15. <H3 CLASS="subsection"><A NAME="htoc140">8.11</A>&#XA0;&#XA0;Constant term streams</H3><UL>
  16. <LI><A HREF="gprolog035.html#toc107">Introduction</A>
  17. </LI><LI><A HREF="gprolog035.html#toc108"><TT>open_input_atom_stream/2</TT>,
  18. <TT>open_input_chars_stream/2</TT>,<BR>
  19. <TT>open_input_codes_stream/2</TT></A>
  20. </LI><LI><A HREF="gprolog035.html#toc109"><TT>close_input_atom_stream/1</TT>,
  21. <TT>close_input_chars_stream/1</TT>,<BR>
  22. <TT>close_input_codes_stream/1</TT></A>
  23. </LI><LI><A HREF="gprolog035.html#toc110"><TT>open_output_atom_stream/1</TT>,
  24. <TT>open_output_chars_stream/1</TT>,<BR>
  25. <TT>open_output_codes_stream/1</TT></A>
  26. </LI><LI><A HREF="gprolog035.html#toc111"><TT>close_output_atom_stream/2</TT>,
  27. <TT>close_output_chars_stream/2</TT>,<BR>
  28. <TT>close_output_codes_stream/2</TT></A>
  29. </LI></UL>
  30. <P>
  31. <A NAME="Constant-term-streams"></A></P><H4 CLASS="subsubsection"><A NAME="toc107"></A><A NAME="htoc141">8.11.1</A>&#XA0;&#XA0;Introduction</H4><P>
  32. <A NAME="Introduction:(Constant-term-streams)"></A>
  33. Constant term streams allow the user to consider a constant term (atom,
  34. character list or character code list) as a source/sink by associating to
  35. them a stream. Reading from a constant term stream will deliver the
  36. characters of the constant term as if they had been read from a standard
  37. file. Characters written on a constant term stream are stored to form the
  38. final constant term when the stream is closed. The built-in predicates
  39. described in this section allow the user to open and close a constant term
  40. stream for input or output. However, very often, a constant term stream is
  41. created to be only read or written once and then closed. To avoid the
  42. creation and the destruction of such a stream, GNU Prolog offers several
  43. built-in predicates to perform single input/output from/to constant terms
  44. (section&#XA0;<A HREF="gprolog039.html#Input/output-from/to-constant-terms">8.15</A>).</P><H4 CLASS="subsubsection"><A NAME="toc108"></A><A NAME="htoc142">8.11.2</A>&#XA0;&#XA0;<TT>open_input_atom_stream/2</TT>,
  45. <TT>open_input_chars_stream/2</TT>,<BR>
  46. <TT>open_input_codes_stream/2</TT></H4><P><B>Templates</B></P><DL CLASS="list"><DT CLASS="dt-list">
  47. </DT><DD CLASS="dd-list"><TT>
  48. open_input_atom_stream(+atom, -stream)<BR>
  49. open_input_chars_stream(+character_list, -stream)<BR>
  50. open_input_codes_stream(+character_code_list, -stream)</TT></DD></DL><P><B>Description</B></P><P><TT>open_input_atom_stream(Atom, Stream)</TT> unifies <TT>Stream</TT>
  51. with the stream-term which is associated with a new input text-stream whose
  52. data are the characters of <TT>Atom</TT>.</P><P><TT>open_input_chars_stream(Chars, Stream)</TT> is similar to
  53. <TT>open_input_atom_stream/2</TT> except that data are the content of the
  54. character list <TT>Chars</TT>.</P><P><TT>open_input_codes_stream(Codes, Stream)</TT> is similar to
  55. <TT>open_input_atom_stream/2</TT> except that data are the content of the
  56. character code list <TT>Codes</TT>.</P><P><B>Errors</B></P><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  57. <TR><TD VALIGN=top ALIGN=left>
  58. <TT>Stream</TT> is not a variable</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(variable, Stream)</TT></TD></TR>
  59. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  60. <TR><TD VALIGN=top ALIGN=left>
  61. <TT>Atom</TT> is a variable</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD></TR>
  62. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  63. <TR><TD VALIGN=top ALIGN=left>
  64. <TT>Chars</TT> is a partial list or a list with an element
  65. <TT>E</TT> which is a variable</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD></TR>
  66. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  67. <TR><TD VALIGN=top ALIGN=left>
  68. <TT>Codes</TT> is a partial list or a list with an element
  69. <TT>E</TT> which is a variable</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD></TR>
  70. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  71. <TR><TD VALIGN=top ALIGN=left>
  72. <TT>Atom</TT> is neither a variable nor a an atom</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(atom, Atom)</TT></TD></TR>
  73. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  74. <TR><TD VALIGN=top ALIGN=left>
  75. <TT>Chars</TT> is neither a partial list nor a list</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(list, Chars)</TT></TD></TR>
  76. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  77. <TR><TD VALIGN=top ALIGN=left>
  78. <TT>Codes</TT> is neither a partial list nor a list</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(list, Codes)</TT></TD></TR>
  79. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  80. <TR><TD VALIGN=top ALIGN=left>
  81. an element <TT>E</TT> of the <TT>Chars</TT> list is neither a
  82. variable nor a character</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(character, E)</TT></TD></TR>
  83. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  84. <TR><TD VALIGN=top ALIGN=left>
  85. an element <TT>E</TT> of the <TT>Codes</TT> list is neither a
  86. variable nor an integer</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(integer, E)</TT></TD></TR>
  87. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  88. <TR><TD VALIGN=top ALIGN=left>
  89. an element <TT>E</TT> of the <TT>Codes</TT> list is an integer but
  90. not a character code</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>representation_error(character_code)</TT></TD></TR>
  91. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  92. </TABLE><P><B>Portability</B></P><P>GNU Prolog predicates.</P><H4 CLASS="subsubsection"><A NAME="toc109"></A><A NAME="htoc143">8.11.3</A>&#XA0;&#XA0;<TT>close_input_atom_stream/1</TT>,
  93. <TT>close_input_chars_stream/1</TT>,<BR>
  94. <TT>close_input_codes_stream/1</TT></H4><P><B>Templates</B></P><DL CLASS="list"><DT CLASS="dt-list">
  95. </DT><DD CLASS="dd-list"><TT>
  96. close_input_atom_stream(+stream_or_alias)<BR>
  97. close_input_chars_stream(+stream_or_alias)<BR>
  98. close_input_codes_stream(+stream_or_alias)</TT></DD></DL><P><B>Description</B></P><P><TT>close_input_atom_stream(SorA)</TT> closes the constant term stream
  99. associated with the stream-term or alias <TT>SorA</TT>. <TT>SorA</TT> must a
  100. stream open with <TT>open_input_atom_stream/2</TT>
  101. (section&#XA0;<A HREF="#Introduction:(Constant-term-streams)">8.11.1</A>).</P><P><TT>close_input_chars_stream(SorA)</TT> acts similarly for a character
  102. list stream.</P><P><TT>close_input_codes_stream(SorA)</TT> acts similarly for a character
  103. code list stream.</P><P><B>Errors</B></P><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  104. <TR><TD VALIGN=top ALIGN=left>
  105. <TT>SorA</TT> is a variable</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD></TR>
  106. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  107. <TR><TD VALIGN=top ALIGN=left>
  108. <TT>SorA</TT> is neither a variable nor a stream-term or alias</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>domain_error(stream_or_alias, SorA)</TT></TD></TR>
  109. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  110. <TR><TD VALIGN=top ALIGN=left>
  111. <TT>SorA</TT> is not associated with an open stream</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>existence_error(stream, SorA)</TT></TD></TR>
  112. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  113. <TR><TD VALIGN=top ALIGN=left>
  114. <TT>SorA</TT> is an output stream</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>permission_error(close, stream, SorA)</TT></TD></TR>
  115. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  116. <TR><TD VALIGN=top ALIGN=left>
  117. <TT>SorA</TT> is a stream-term or alias but does not refer to a
  118. constant term stream.</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>domain_error(term_stream_or_alias, SorA)</TT></TD></TR>
  119. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  120. </TABLE><P><B>Portability</B></P><P>GNU Prolog predicates.</P><H4 CLASS="subsubsection"><A NAME="toc110"></A><A NAME="htoc144">8.11.4</A>&#XA0;&#XA0;<TT>open_output_atom_stream/1</TT>,
  121. <TT>open_output_chars_stream/1</TT>,<BR>
  122. <TT>open_output_codes_stream/1</TT></H4><P>
  123. <A NAME="open-output-atom-stream/1"></A>
  124. </P><P><B>Templates</B></P><DL CLASS="list"><DT CLASS="dt-list">
  125. </DT><DD CLASS="dd-list"><TT>
  126. open_output_atom_stream(-stream)<BR>
  127. open_output_chars_stream(-stream)<BR>
  128. open_output_codes_stream(-stream)</TT></DD></DL><P><B>Description</B></P><P><TT>open_output_atom_stream(Stream)</TT> unifies <TT>Stream</TT> with the
  129. stream-term which is associated with a new output text-stream. All characters
  130. written to this stream are collected and will be returned as an atom when
  131. the stream is closed by <TT>close_output_atom_stream/2</TT>
  132. (section&#XA0;<A HREF="#close-output-atom-stream/2">8.11.5</A>).</P><P><TT>open_output_chars_stream(Stream)</TT> is similar to
  133. <TT>open_output_atom_stream/1</TT> except that the result will be a
  134. character list.</P><P><TT>open_output_codes_stream(Stream)</TT> is similar to
  135. <TT>open_output_atom_stream/1</TT> except that the result will be a
  136. character code list.</P><P><B>Errors</B></P><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  137. <TR><TD VALIGN=top ALIGN=left>
  138. <TT>Stream</TT> is not a variable</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(variable, Stream)</TT></TD></TR>
  139. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  140. </TABLE><P><B>Portability</B></P><P>GNU Prolog predicates.</P><H4 CLASS="subsubsection"><A NAME="toc111"></A><A NAME="htoc145">8.11.5</A>&#XA0;&#XA0;<TT>close_output_atom_stream/2</TT>,
  141. <TT>close_output_chars_stream/2</TT>,<BR>
  142. <TT>close_output_codes_stream/2</TT></H4><P>
  143. <A NAME="close-output-atom-stream/2"></A>
  144. </P><P><B>Templates</B></P><DL CLASS="list"><DT CLASS="dt-list">
  145. </DT><DD CLASS="dd-list"><TT>
  146. close_output_atom_stream(+stream_or_alias, ?atom)<BR>
  147. close_output_chars_stream(+stream_or_alias, ?character_list)<BR>
  148. close_output_codes_stream(+stream_or_alias, ?character_code_list)</TT></DD></DL><P><B>Description</B></P><P><TT>close_output_atom_stream(SorA, Atom)</TT> closes the constant term
  149. stream associated with the stream-term or alias <TT>SorA</TT>. <TT>SorA</TT> must
  150. be associated with a stream open with <TT>open_output_atom_stream/1</TT>
  151. (section&#XA0;<A HREF="#open-output-atom-stream/1">8.11.4</A>). <TT>Atom</TT> is unified with an atom
  152. formed with all characters written on the stream.</P><P><TT>close_output_chars_stream(SorA, Chars)</TT> acts similarly for a
  153. character list stream.</P><P><TT>close_output_codes_stream(SorA, Codes)</TT> acts similarly for a
  154. character code list stream.</P><P><B>Errors</B></P><TABLE CELLSPACING=6 CELLPADDING=0><TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  155. <TR><TD VALIGN=top ALIGN=left>
  156. <TT>SorA</TT> is a variable</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>instantiation_error</TT></TD></TR>
  157. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  158. <TR><TD VALIGN=top ALIGN=left>
  159. <TT>Atom</TT> is neither a variable nor an atom</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(atom, Atom)</TT></TD></TR>
  160. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  161. <TR><TD VALIGN=top ALIGN=left>
  162. <TT>Chars</TT> is neither a partial list nor a list</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(list, Chars)</TT></TD></TR>
  163. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  164. <TR><TD VALIGN=top ALIGN=left>
  165. <TT>Codes</TT> is neither a partial list nor a list</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(list, Codes)</TT></TD></TR>
  166. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  167. <TR><TD VALIGN=top ALIGN=left>
  168. an element <TT>E</TT> of the <TT>Chars</TT> list is neither a
  169. variable nor a character</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(character, E)</TT></TD></TR>
  170. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  171. <TR><TD VALIGN=top ALIGN=left>
  172. an element <TT>E</TT> of the <TT>Codes</TT> list is neither a
  173. variable nor an integer</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>type_error(integer, E)</TT></TD></TR>
  174. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  175. <TR><TD VALIGN=top ALIGN=left>
  176. an element <TT>E</TT> of the <TT>Codes</TT> list is an integer but
  177. not a character code</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>representation_error(character_code)</TT></TD></TR>
  178. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  179. <TR><TD VALIGN=top ALIGN=left>
  180. <TT>SorA</TT> is neither a variable nor a stream-term or alias</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>domain_error(stream_or_alias, SorA)</TT></TD></TR>
  181. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  182. <TR><TD VALIGN=top ALIGN=left>
  183. <TT>SorA</TT> is not associated with an open stream</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>existence_error(stream, SorA)</TT></TD></TR>
  184. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  185. <TR><TD VALIGN=top ALIGN=left>
  186. <TT>SorA</TT> is an input stream</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>permission_error(close, stream, SorA)</TT></TD></TR>
  187. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  188. <TR><TD VALIGN=top ALIGN=left>
  189. <TT>SorA</TT> is a stream-term or alias but does not refer to a
  190. constant term stream</TD><TD VALIGN=top ALIGN=center NOWRAP>&#XA0;&#XA0;</TD><TD VALIGN=top ALIGN=left><TT>domain_error(term_stream_or_alias, SorA)</TT></TD></TR>
  191. <TR><TD CLASS="hbar" COLSPAN=3></TD></TR>
  192. </TABLE><P><B>Portability</B></P><P>GNU Prolog predicates.</P>
  193. <HR SIZE=2>
  194. Copyright (C) 1999-2011 Daniel Diaz
  195. Verbatim copying and distribution of this entire article is permitted in any
  196. medium, provided this notice is preserved. <A HREF="index.html#copyright">More about the copyright</A>
  197. <HR>
  198. <A HREF="gprolog034.html"><IMG SRC="previous_motif.gif" ALT="Previous"></A>
  199. <A HREF="gprolog024.html"><IMG SRC="contents_motif.gif" ALT="Up"></A>
  200. <A HREF="gprolog036.html"><IMG SRC="next_motif.gif" ALT="Next"></A>
  201. </BODY>
  202. </HTML>