UNPKG

@ciao-lang/ts-ciao-interface

Version:

Simple Ciao interface for node.

89 lines 20.3 kB
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><meta name="theme-color" content="#273f79"/><link rel="stylesheet" href="lpdoc.css" type="text/css"/><script type="text/javascript" src="lpdoc.js"></script><title>Formatted output &mdash; The Ciao System v1.22</title></head><body><div class="lpdoc-page fixleftbar"><a href="#" id="sidebar-toggle-button" class="lpdoc-navbutton"><span id="sidebar-button-arrow">&#9776;</span></a><div id="sidebar" class="lpdoc-sidebar"><div style="height: 40px; margin-left: auto; margin-right: auto"><img src="ciao-logo_autofig.png" width=auto height=100%></div><div class="lpdoc-nav"><span class="lpdoc-on-right"><a class="lpdoc-navbutton" href="StdLibs.html">&#x2191;</a><a class="lpdoc-navbutton" href="operators.html">&#x2190;</a><a class="lpdoc-navbutton" href="terms_io.html">&#x2192;</a><a class="lpdoc-navbutton" href="ciaosearch.html">&#x1F50D;</a></span><span><a href="ciaofulltoc.html">TOC</a></span></div><hr></hr><ul class="lpdoc-itemize-sectpath"><li><a href="ciao.html">The Ciao System</a> &raquo;<br/> </li><li><a href="StdLibs.html">PART VII - Standard libraries</a> &raquo;<br/> </li><li><a href=""><strong>Formatted output</strong></a></li></ul><hr></hr><em>ON THIS PAGE</em><ul><li><a href="#Usage and interface">Usage and interface</a></li><li><a href="#Documentation on exports">Documentation on exports</a></li><li><a href="#Documentation on imports">Documentation on imports</a></li></ul></div><div class="lpdoc-main"><div id=""><h1>Formatted output</h1><a class="lpdoc-idx-anchor" href="ciaosearch.html#format"></a> <strong>Author(s):</strong> <a class="lpdoc-idx-anchor" id="The Ciao Development Team" href="ciaosearch.html#The Ciao Development Team">The Ciao Development Team</a>.<p> The <tt>format</tt> family of predicates is due to Quintus Prolog. They act as a Prolog interface to the C <tt>stdio</tt> function <tt>printf()</tt>, allowing formatted output.<p>Output is formatted according to an output pattern which can have either a format control sequence or any other character, which will appear verbatim in the output. Control sequences act as place-holders for the actual terms that will be output. Thus <pre class="lpdoc-codeblock"> ?- format(&quot;Hello ~q!&quot;,world). </pre> will print <tt>Hello world!</tt>.<p>If there is only one item to print it may be supplied alone. If there are more they have to be given as a list. If there are none then an empty list should be supplied. There has to be as many items as control characters.<p>The character <tt>~</tt> introduces a control sequence. To print a <tt>~</tt> verbatim just repeat it: <pre class="lpdoc-codeblock"> ?- format(&quot;Hello ~~world!&quot;, []). </pre> will result in <tt>Hello ~world!</tt>.<p>A format may be spread over several lines. The control sequence <tt>\c</tt> followed by a <span class="lpdoc-emacskey">LFD</span> will translate to the empty string: <pre class="lpdoc-codeblock"> ?- format(&quot;Hello \c world!&quot;, []). </pre> will result in <tt>Hello world!</tt>.<br/><div id="Usage and interface"><h2>Usage and interface</h2><div class="lpdoc-cartouche"><ul><li><strong>Library usage:</strong><br/><tt>:- use_module(library(format)).</tt><li><strong>Exports:</strong><br/><ul class="lpdoc-itemize-minus"><li><em>Predicates:</em><br/><a class="lpdoc-idx-anchor" id="0" href="#format/2"><tt>format/2</tt></a>, <a class="lpdoc-idx-anchor" id="1" href="#format/3"><tt>format/3</tt></a>, <a class="lpdoc-idx-anchor" id="2" href="#sformat/3"><tt>sformat/3</tt></a>, <a class="lpdoc-idx-anchor" id="3" href="#format_to_string/3"><tt>format_to_string/3</tt></a>. <li><em>Regular Types:</em><br/><a class="lpdoc-idx-anchor" id="4" href="#format_control/1"><tt>format_control/1</tt></a>. </ul></ul></div></div><div id="Documentation on exports"><h2>Documentation on exports</h2><div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="format/2" href="ciaosearch.html#format/2">format/2</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>format(Format,Arguments)</tt> </span><p>Print <span class="lpdoc-var">Arguments</span> onto current output stream according to format <span class="lpdoc-var">Format</span>.</p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold at call time:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="5" href="#format_control/1"><tt>format:format_control/1</tt></a>)</span><span><span class="lpdoc-var">Format</span> is an atom or string describing how the arguments should be formatted. If it is an atom it will be converted into a string with <tt>name/2</tt>. </span> </ul> <strong>Other properties:</strong> <br/><span class="lpdoc-usage-decl"><tt>format(C,A)</tt> </span><p></p><ul class="lpdoc-itemize-minus"><li><em>The following properties hold globally:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="6" href="basic_props.html#native/2"><tt>basic_props:native/2</tt></a>)</span><span>This predicate is understood natively by CiaoPP as <span class="lpdoc-var">format(C,A)</span>. </span> </ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="format/3" href="ciaosearch.html#format/3">format/3</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>format(Stream,Format,Arguments)</tt> </span><p>Print <span class="lpdoc-var">Arguments</span> onto <span class="lpdoc-var">Stream</span> according to format <span class="lpdoc-var">Format</span>.</p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold at call time:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="7" href="stream_basic.html#stream/1"><tt>stream_basic:stream/1</tt></a>)</span><span><span class="lpdoc-var">Stream</span> is an open stream. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="8" href="#format_control/1"><tt>format:format_control/1</tt></a>)</span><span><span class="lpdoc-var">Format</span> is an atom or string describing how the arguments should be formatted. If it is an atom it will be converted into a string with <tt>name/2</tt>. </span> </ul> <strong>Other properties:</strong> <br/><span class="lpdoc-usage-decl"><tt>format(S,C,A)</tt> </span><p></p><ul class="lpdoc-itemize-minus"><li><em>The following properties hold globally:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="9" href="basic_props.html#native/2"><tt>basic_props:native/2</tt></a>)</span><span>This predicate is understood natively by CiaoPP as <span class="lpdoc-var">format(S,C,A)</span>. </span> </ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="sformat/3" href="ciaosearch.html#sformat/3">sformat/3</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>sformat(String,Format,Arguments)</tt> </span><p>Same as <a class="lpdoc-idx-anchor" id="10" href="ciaosearch.html#format_to_string(<span class="lpdoc-var">Format</span>, <span class="lpdoc-var">Arguments</span>, <span class="lpdoc-var">String</span>)"><tt>format_to_string(<span class="lpdoc-var">Format</span>, <span class="lpdoc-var">Arguments</span>, <span class="lpdoc-var">String</span>)</tt></a> (note the different argument order).</p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold at call time:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="11" href="#format_control/1"><tt>format:format_control/1</tt></a>)</span><span><span class="lpdoc-var">Format</span> is an atom or string describing how the arguments should be formatted. If it is an atom it will be converted into a string with <tt>name/2</tt>. </span> <li><em>The following properties should hold upon exit:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="12" href="basic_props.html#string/1"><tt>basic_props:string/1</tt></a>)</span><span><span class="lpdoc-var">String</span> is a string (a list of character codes). </span> </ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="format_to_string/3" href="ciaosearch.html#format_to_string/3">format_to_string/3</a></div><div class="lpdoc-deftext"><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>format_to_string(Format,Arguments,String)</tt> </span><p>Print <span class="lpdoc-var">Arguments</span> onto current string <span class="lpdoc-var">String</span> according to format <span class="lpdoc-var">Format</span>. This predicate is similar to the format/2, but the result is stored in a string.</p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold at call time:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="13" href="#format_control/1"><tt>format:format_control/1</tt></a>)</span><span><span class="lpdoc-var">Format</span> is an atom or string describing how the arguments should be formatted. If it is an atom it will be converted into a string with <tt>name/2</tt>. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="14" href="basic_props.html#list/1"><tt>basic_props:list/1</tt></a>)</span><span><span class="lpdoc-var">Arguments</span> is a list. </span> <li><em>The following properties should hold upon exit:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="15" href="basic_props.html#string/1"><tt>basic_props:string/1</tt></a>)</span><span><span class="lpdoc-var">String</span> is a string (a list of character codes). </span> </ul></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">REGTYPE</span><a class="lpdoc-idx-anchor" id="format_control/1" href="ciaosearch.html#format_control/1">format_control/1</a></div><div class="lpdoc-deftext"> The general format of a control sequence is <tt>~<span class="lpdoc-var">N</span><span class="lpdoc-var">C</span></tt>. The character <span class="lpdoc-var">C</span> determines the type of the control sequence. <span class="lpdoc-var">N</span> is an optional numeric argument. An alternative form of <span class="lpdoc-var">N</span> is <tt>*</tt>. <tt>*</tt> implies that the next argument in <span class="lpdoc-var">Arguments</span> should be used as a numeric argument in the control sequence. Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello~4cworld!&quot;, [0&apos;x]). </pre> <p>and<p><pre class="lpdoc-codeblock">?- format(&quot;Hello~*cworld!&quot;, [4,0&apos;x]). </pre> <p>both produce<p><pre class="lpdoc-codeblock">Helloxxxxworld! </pre> <p>The following control sequences are available.<p><ul> <p><li>~a The argument is an atom. The atom is printed without quoting.<p><li>~<span class="lpdoc-var">N</span>c (Print character.) The argument is a number that will be interpreted as an ASCII code. <span class="lpdoc-var">N</span> defaults to one and is interpreted as the number of times to print the character.<p><li>~<span class="lpdoc-var">N</span>e <li>~<span class="lpdoc-var">N</span>E <li>~<span class="lpdoc-var">N</span>f <li>~<span class="lpdoc-var">N</span>g <li>~<span class="lpdoc-var">N</span>G (Print float). The argument is a float. The float and <span class="lpdoc-var">N</span> will be passed to the C <tt>printf()</tt> function as<p><pre class="lpdoc-codeblock">printf(&quot;%.<span class="lpdoc-var">N</span>e&quot;, <span class="lpdoc-var">Arg</span>) printf(&quot;%.<span class="lpdoc-var">N</span>E&quot;, <span class="lpdoc-var">Arg</span>) printf(&quot;%.<span class="lpdoc-var">N</span>f&quot;, <span class="lpdoc-var">Arg</span>) printf(&quot;%.<span class="lpdoc-var">N</span>g&quot;, <span class="lpdoc-var">Arg</span>) printf(&quot;%.<span class="lpdoc-var">N</span>G&quot;, <span class="lpdoc-var">Arg</span>) </pre> <p>If <span class="lpdoc-var">N</span> is not supplied the action defaults to<p><pre class="lpdoc-codeblock">printf(&quot;%e&quot;, <span class="lpdoc-var">Arg</span>) printf(&quot;%E&quot;, <span class="lpdoc-var">Arg</span>) printf(&quot;%f&quot;, <span class="lpdoc-var">Arg</span>) printf(&quot;%g&quot;, <span class="lpdoc-var">Arg</span>) printf(&quot;%G&quot;, <span class="lpdoc-var">Arg</span>) </pre> <p><li>~<span class="lpdoc-var">N</span>d (Print decimal.) The argument is an integer. <span class="lpdoc-var">N</span> is interpreted as the number of digits after the decimal point. If <span class="lpdoc-var">N</span> is 0 or missing, no decimal point will be printed. Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~1d world!&quot;, [42]). ?- format(&quot;Hello ~d world!&quot;, [42]). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello 4.2 world! Hello 42 world! </pre> <p>respectively.<p><li>~<span class="lpdoc-var">N</span>D (Print decimal.) The argument is an integer. Identical to <tt>~<span class="lpdoc-var">N</span>d</tt> except that <tt>,</tt> will separate groups of three digits to the left of the decimal point. Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~1D world!&quot;, [12345]). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello 1,234.5 world! </pre> <p><li>~<span class="lpdoc-var">N</span>r (Print radix.) The argument is an integer. <span class="lpdoc-var">N</span> is interpreted as a radix. <span class="lpdoc-var">N</span> should be &gt;= 2 and &lt;= 36. If <span class="lpdoc-var">N</span> is missing the radix defaults to 8. The letters <tt>a-z</tt> will denote digits larger than 9. Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~2r world!&quot;, [15]). ?- format(&quot;Hello ~16r world!&quot;, [15]). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello 1111 world! Hello f world! </pre> <p>respectively.<p><li>~<span class="lpdoc-var">N</span>R (Print radix.) The argument is an integer. Identical to <tt>~<span class="lpdoc-var">N</span>r</tt> except that the letters <tt>A-Z</tt> will denote digits larger than 9. Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~16R world!&quot;, [15]). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello F world! </pre> <p><li>~<span class="lpdoc-var">N</span>s (Print string.) The argument is a list of ASCII codes. Exactly <span class="lpdoc-var">N</span> characters will be printed. <span class="lpdoc-var">N</span> defaults to the length of the string. Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~4s ~4s!&quot;, [&quot;new&quot;,&quot;world&quot;]). ?- format(&quot;Hello ~s world!&quot;, [&quot;new&quot;]). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello new worl! Hello new world! </pre> <p>respectively.<p><li>~i (Ignore argument.) The argument may be of any type. The argument will be ignored. Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~i~s world!&quot;, [&quot;old&quot;,&quot;new&quot;]). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello new world! </pre> <p><li>~k (Print canonical.) The argument may be of any type. The argument will be passed to <tt>write_canonical/2</tt> (<a href="write.html">Term output</a>). Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~k world!&quot;, [[a,b,c]]). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello .(a,.(b,.(c,[]))) world! </pre> <p><li>~p (print.) The argument may be of any type. The argument will be passed to <tt>print/2</tt> (<a href="write.html">Term output</a>). Example:<p>suposing the user has defined the predicate<p><pre class="lpdoc-codeblock">:- multifile portray/1. portray([X|Y]) :- print(cons(X,Y)). </pre> <p>then<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~p world!&quot;, [[a,b,c]]). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello cons(a,cons(b,cons(c,[]))) world! </pre> <p><li>~q (Print quoted.) The argument may be of any type. The argument will be passed to <tt>writeq/2</tt> (<a href="write.html">Term output</a>). Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~q world!&quot;, [[&apos;A&apos;,&apos;B&apos;]]). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello [&apos;A&apos;,&apos;B&apos;] world! </pre> <p><li>~w (write.) The argument may be of any type. The argument will be passed to <tt>write/2</tt> (<a href="write.html">Term output</a>). Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~w world!&quot;, [[&apos;A&apos;,&apos;B&apos;]]). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello [A,B] world! </pre> <p><li>~<span class="lpdoc-var">N</span>n (Print newline.) Print <span class="lpdoc-var">N</span> newlines. <span class="lpdoc-var">N</span> defaults to 1. Example:<p><pre class="lpdoc-codeblock">?- format(&quot;Hello ~n world!&quot;, []). </pre> <p>will print as<p><pre class="lpdoc-codeblock">Hello world! </pre> <p><li>~N (Fresh line.) Print a newline, if not already at the beginning of a line.<p><li>~~ (Print tilde.) Prints <tt>~</tt> <p></ul> <p> The following control sequences are also available for compatibility, but do not perform any useful functions.<p><ul> <li>~<span class="lpdoc-var">N</span>| (Set tab.) Set a tab stop at position <span class="lpdoc-var">N</span>, where <span class="lpdoc-var">N</span> defaults to the current position, and advance the current position there.<p><li>~<span class="lpdoc-var">N</span>+ (Advance tab.) Set a tab stop at <span class="lpdoc-var">N</span> positions past the current position, where <span class="lpdoc-var">N</span> defaults to 8, and advance the current position there.<p><li>~<span class="lpdoc-var">N</span>t (Set fill character.) Set the fill character to be used in the next position movement to <span class="lpdoc-var">N</span>, where <span class="lpdoc-var">N</span> defaults to <span class="lpdoc-emacskey">SPC</span>. </ul> <p><p><span class="lpdoc-usage-header">Usage:</span><span class="lpdoc-usage-decl"><tt>format_control(C)</tt> </span><p><span class="lpdoc-var">C</span> is an atom or string describing how the arguments should be formatted. If it is an atom it will be converted into a string with <tt>name/2</tt>.</p><ul class="lpdoc-itemize-minus"><li><em>The following properties should hold globally:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="16" href="ciaosearch.html#doc_incomplete/1"><tt>doc_props:doc_incomplete/1</tt></a>)</span><span>Documentation is still incomplete: <span class="lpdoc-var">format_control(C)</span> may not conform the functionality documented. </span> </ul></div></div><p> </div><div id="Documentation on imports"><h2>Documentation on imports</h2>This module has the following direct dependencies:<ul class="lpdoc-itemize-minus"><li><em>System library modules:</em><br/><a class="lpdoc-idx-anchor" id="17" href="datafacts_rt.html"><tt>datafacts_rt</tt></a>, <a class="lpdoc-idx-anchor" id="18" href="streams.html"><tt>streams</tt></a>, <a class="lpdoc-idx-anchor" id="19" href="write.html"><tt>write</tt></a>, <a class="lpdoc-idx-anchor" id="20" href="system.html"><tt>system</tt></a>, <a class="lpdoc-idx-anchor" id="21" href="ciaosearch.html#doc_props"><tt>doc_props</tt></a>. <li><em>Packages:</em><br/><a class="lpdoc-idx-anchor" id="22" href="ciaosearch.html#prelude"><tt>prelude</tt></a>, <a class="lpdoc-idx-anchor" id="23" href="ciaosearch.html#initial"><tt>initial</tt></a>, <a class="lpdoc-idx-anchor" id="24" href="condcomp_doc.html"><tt>condcomp</tt></a>, <a class="lpdoc-idx-anchor" id="25" href="dcg_doc.html"><tt>dcg</tt></a>, <a class="lpdoc-idx-anchor" id="26" href="assertions_doc.html"><tt>assertions</tt></a>, <a class="lpdoc-idx-anchor" id="27" href="ciaosearch.html#assertions/assertions_basic"><tt>assertions/assertions_basic</tt></a>, <a class="lpdoc-idx-anchor" id="28" href="isomodes_doc.html"><tt>isomodes</tt></a>, <a class="lpdoc-idx-anchor" id="29" href="datafacts_doc.html"><tt>datafacts</tt></a>. </ul></div></div><div class="lpdoc-footer">Generated with LPdoc using Ciao</div></div><div class="lpdoc-clearer"></div></div></body></html>