<HTML> <HEAD> <!-- Created by texi2html 1.56k + clip patches and <A href="http://www.clip.dia.fi.upm.es/Software">lpdoc</A> from ciao.texi on 28 January 2007 --> <LINK rel="stylesheet" href="ciao.css" type="text/css"> <TITLE>The Ciao Prolog System - Term input</TITLE> </HEAD> <BODY> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_37.html">previous</A>, <A HREF="ciao_39.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. <P><HR><P> <H1><A NAME="SEC200" HREF="ciao_toc.html#TOC200">Term input</A></H1> <P> <A NAME="IDX2793"></A> <P> <STRONG>Author(s):</STRONG> First versions from SICStus 0.6 code; additional changes and documentation by Daniel Cabeza and Manuel Carro. <P> <STRONG>Version:</STRONG> 1.10#7 (2006/4/26, 19:22:13 CEST) <P> <STRONG>Version of last change:</STRONG> 1.9#289 (2004/2/13, 19:46:27 CET) <P> This module provides falicities to read terms in Prolog syntax. This is very convenient in many cases (and not only if you are writing a Prolog compiler), because Prolog terms are easy to write and can convey a lot of information in a human-readable fashion. <UL> <LI><A HREF="ciao_38.html#SEC201">Usage and interface (read)</A> <LI><A HREF="ciao_38.html#SEC202">Documentation on exports (read)</A> <LI><A HREF="ciao_38.html#SEC203">Documentation on multifiles (read)</A> <LI><A HREF="ciao_38.html#SEC204">Documentation on internals (read)</A> <LI><A HREF="ciao_38.html#SEC205">Known bugs and planned improvements (read)</A> </UL> <H2><A NAME="SEC201" HREF="ciao_toc.html#TOC201">Usage and interface (<CODE>read</CODE>)</A></H2> <div class="cartouche"> <UL> <LI><STRONG>Library usage:</STRONG> <CODE>:- use_module(library(read)).</CODE> <LI><STRONG>Exports:</STRONG> <UL> <LI><EM>Predicates:</EM> <A NAME="IDX2794"></A> <CODE>read/1</CODE>, <A NAME="IDX2795"></A> <CODE>read/2</CODE>, <A NAME="IDX2796"></A> <CODE>read_term/2</CODE>, <A NAME="IDX2797"></A> <CODE>read_term/3</CODE>, <A NAME="IDX2798"></A> <CODE>read_top_level/3</CODE>, <A NAME="IDX2799"></A> <CODE>second_prompt/2</CODE>. <LI><EM>Multifiles:</EM> <A NAME="IDX2800"></A> <CODE>define_flag/3</CODE>. </UL> <LI><STRONG>Other modules used:</STRONG> <UL> <LI><EM>System library modules:</EM> <A NAME="IDX2801"></A> <CODE>tokenize</CODE>, <A NAME="IDX2802"></A> <CODE>operators</CODE>, <A NAME="IDX2803"></A> <CODE>lists</CODE>. </UL> </UL> </div class="cartouche"> <H2><A NAME="SEC202" HREF="ciao_toc.html#TOC202">Documentation on exports (<CODE>read</CODE>)</A></H2> <P> <A NAME="IDX2804"></A> <A NAME="IDX2805"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>read/1:</B> <DD><A NAME="IDX2806"></A> <P> <CODE>read(Term)</CODE> <P> Like <CODE>read(Stream,Term)</CODE> with <CODE>Stream</CODE> associated to the current input stream. </DL> <P> <A NAME="IDX2807"></A> <A NAME="IDX2808"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>read/2:</B> <DD><A NAME="IDX2809"></A> <P> <STRONG>Usage:</STRONG> <CODE>read(+Stream, ?Term)</CODE> <KBD> * ISO * </KBD> <UL> <LI><EM>Description:</EM> The next term, delimited by a full-stop (i.e., a <CODE>.</CODE> followed by either a space or a control character), is read from <CODE>Stream</CODE> and is unified with <CODE>Term</CODE>. The syntax of the term must agree with current operator declarations. If the end of <CODE>Stream</CODE> has been reached, <CODE>Term</CODE> is unified with the term <CODE>end_of_file</CODE>. Further calls to <CODE>read/2</CODE> for the same stream will then cause an error, unless the stream is connected to the terminal (in which case a prompt is opened on the terminal). <LI><EM>The following properties hold upon exit:</EM> <CODE>+Stream</CODE> is an open stream. (<CODE>streams_basic:stream/1</CODE>) <CODE>?Term</CODE> is any term. (<CODE>basic_props:term/1</CODE>) </UL> </DL> <P> <A NAME="IDX2810"></A> <A NAME="IDX2811"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>read_term/2:</B> <DD><A NAME="IDX2812"></A> <P> <STRONG>Usage:</STRONG> <CODE>read_term(?Term, +Options)</CODE> <KBD> * ISO * </KBD> <UL> <LI><EM>Description:</EM> Like <A NAME="IDX2813"></A> <CODE>read_term/3</CODE>, but reading from the <A NAME="IDX2814"></A> current input <LI><EM>The following properties hold upon exit:</EM> <CODE>?Term</CODE> is any term. (<CODE>basic_props:term/1</CODE>) <CODE>+Options</CODE> is a list of <CODE>read_option</CODE>s. (<CODE>basic_props:list/2</CODE>) </UL> </DL> <P> <A NAME="IDX2815"></A> <A NAME="IDX2816"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>read_term/3:</B> <DD><A NAME="IDX2817"></A> <P> <STRONG>Usage:</STRONG> <CODE>read_term(+Stream, ?Term, +Options)</CODE> <KBD> * ISO * </KBD> <UL> <LI><EM>Description:</EM> Reads a <CODE>Term</CODE> from <CODE>Stream</CODE> with the ISO-Prolog <CODE>Options</CODE>. These options can control the behavior of read term (see <A NAME="IDX2818"></A> <CODE>read_option/1</CODE>). <LI><EM>The following properties hold upon exit:</EM> <CODE>+Stream</CODE> is an open stream. (<CODE>streams_basic:stream/1</CODE>) <CODE>?Term</CODE> is any term. (<CODE>basic_props:term/1</CODE>) <CODE>+Options</CODE> is a list of <CODE>read_option</CODE>s. (<CODE>basic_props:list/2</CODE>) </UL> </DL> <P> <A NAME="IDX2819"></A> <A NAME="IDX2820"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>read_top_level/3:</B> <DD><A NAME="IDX2821"></A> <P> <CODE>read_top_level(Stream, Data, Variables)</CODE> <P> Predicate used to read in the Top Level. </DL> <P> <A NAME="IDX2822"></A> <A NAME="IDX2823"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>second_prompt/2:</B> <DD><A NAME="IDX2824"></A> <P> <STRONG>Usage:</STRONG> <CODE>second_prompt(?Old, ?New)</CODE> <UL> <LI><EM>Description:</EM> Changes the prompt (the <EM>second prompt</EM>, as oposed to the first one, used by the toplevel) used by <A NAME="IDX2825"></A> <CODE>read/2</CODE> and friends to <CODE>New</CODE>, and returns the current one in <CODE>Old</CODE>. <LI><EM>The following properties should hold upon exit:</EM> <CODE>?Old</CODE> is currently instantiated to an atom. (<CODE>term_typing:atom/1</CODE>) <CODE>?New</CODE> is currently instantiated to an atom. (<CODE>term_typing:atom/1</CODE>) </UL> </DL> <H2><A NAME="SEC203" HREF="ciao_toc.html#TOC203">Documentation on multifiles (<CODE>read</CODE>)</A></H2> <P> <A NAME="IDX2826"></A> <A NAME="IDX2827"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>define_flag/3:</B> <DD><A NAME="IDX2828"></A> <P> Defines flags as follows: <PRE> define_flag(read_hiord,[on,off],off). </PRE> <P> (See section <A HREF="ciao_27.html#SEC163">Changing system behaviour and various flags</A>). <P> If flag is <CODE>on</CODE> (it is <CODE>off</CODE> by default), a variable followed by a parenthesized lists of arguments is read as a <A NAME="IDX2829"></A> <CODE>call/N</CODE> term, except if the variable is anonymous, in which case it is read as an anonymous predicate abstraction head. For example, <CODE>P(X)</CODE> is read as <CODE>call(P,X)</CODE> and <CODE>_(X,Y)</CODE> as <CODE>"(X,Y)</CODE>. <P> The predicate is <EM>multifile</EM>. </DL> <H2><A NAME="SEC204" HREF="ciao_toc.html#TOC204">Documentation on internals (<CODE>read</CODE>)</A></H2> <P> <A NAME="IDX2830"></A> <A NAME="IDX2831"></A> <DL> <DT><span class="define">REGTYPE:</span> <B>read_option/1:</B> <DD><A NAME="IDX2832"></A> <P> <STRONG>Usage:</STRONG> <CODE>read_option(Option)</CODE> <UL> <LI><EM>Description:</EM> <CODE>Option</CODE> is an allowed <A NAME="IDX2833"></A> <CODE>read_term/[2,3]</CODE> option. These options are: <PRE> read_option(variables(_V)). read_option(variable_names(_N)). read_option(singletons(_S)). read_option(lines(_StartLine,_EndLine)). read_option(dictionary(_Dict)). </PRE> They can be used to return the singleton variables in the term, a list of variables, etc. <LI><EM>The following properties should hold upon exit:</EM> <CODE>Option</CODE> is currently instantiated to an atom. (<CODE>term_typing:atom/1</CODE>) </UL> </DL> <H2><A NAME="SEC205" HREF="ciao_toc.html#TOC205">Known bugs and planned improvements (<CODE>read</CODE>)</A></H2> <UL> <LI> The comma cannot be redefined as an operator, it is defined in any case as op(1000, xfy,[',']). </UL> <P><HR><P> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_37.html">previous</A>, <A HREF="ciao_39.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. </BODY> </HTML>