UNPKG

@ciao-lang/ts-ciao-interface

Version:

Simple Ciao interface for node.

38 lines (33 loc) 9.33 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>Symbolic filenames &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="ExtraLibs.html">&#x2191;</a><a class="lpdoc-navbutton" href="file_locks.html">&#x2190;</a><a class="lpdoc-navbutton" href="opendoc.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="ExtraLibs.html">PART VIII - Additional libraries</a> &raquo;<br/> </li><li><a href=""><strong>Symbolic filenames</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 multifiles">Documentation on multifiles</a></li><li><a href="#Documentation on imports">Documentation on imports</a></li><li><a href="#Other information">Other information</a></li></ul></div><div class="lpdoc-main"><div id=""><h1>Symbolic filenames</h1><a class="lpdoc-idx-anchor" href="ciaosearch.html#symfnames"></a> <strong>Author(s):</strong> <a class="lpdoc-idx-anchor" id="Francisco Bueno" href="ciaosearch.html#Francisco Bueno">Francisco Bueno</a>.<p> This module provides a predicate for file opening which can use any term as an alias for the filename (i.e., symbolic filenames) instead of the usual constants which are file system path names of the actual files.<p>The correspondence between an alias and the actual file path is done dynamically, without having to recompile the program. It is possible to define the correspondence via facts for <a class="lpdoc-idx-anchor" id="0" href="factsdb_rt.html#file_alias/2"><tt>file_alias/2</tt></a> in a file declared with <a class="lpdoc-idx-anchor" id="1" href="ciaosearch.html#multifile:alias_file/1"><tt>multifile:alias_file/1</tt></a> in the program: those facts will be dynamically loaded when running the program. Alternatively, the correspondence can be defined via shell environment variables, by defining the value of a variable by the (symbolic) name of the file to be the path of the actual file.<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(symfnames)).</tt><li><strong>Exports:</strong><br/><ul class="lpdoc-itemize-minus"><li><em>Predicates:</em><br/><a class="lpdoc-idx-anchor" id="2" href="stream_basic.html#open/3"><tt>open/3</tt></a>. <li><em>Multifiles:</em><br/><a class="lpdoc-idx-anchor" id="3" href="#alias_file/1"><tt>alias_file/1</tt></a>, <a class="lpdoc-idx-anchor" id="4" href="factsdb_rt.html#file_alias/2"><tt>file_alias/2</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="open/3" href="ciaosearch.html#open/3">open/3</a></div><div class="lpdoc-deftext"><span class="lpdoc-usage-decl"><tt>open(File,Mode,Stream)</tt> </span><p>Open <span class="lpdoc-var">File</span> with mode <span class="lpdoc-var">Mode</span> and return in <span class="lpdoc-var">Stream</span> the stream associated with the file. It is like <a class="lpdoc-idx-anchor" id="5" href="ciaosearch.html#stream_basic:open/3"><tt>stream_basic:open/3</tt></a>, but <span class="lpdoc-var">File</span> is considered a symbolic name: either defined by <a class="lpdoc-idx-anchor" id="6" href="ciaosearch.html#user:file_alias/2"><tt>user:file_alias/2</tt></a> or as an environment variable. Predicate <a class="lpdoc-idx-anchor" id="7" href="ciaosearch.html#user:file_alias/2"><tt>user:file_alias/2</tt></a> is inspected before the environment variables.<p><span class="lpdoc-usage-header">Usage:</span><p></p><ul class="lpdoc-itemize-minus"><li><em>Call and exit should be compatible with:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="8" 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> <li><em>The following properties should hold at call time:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="9" href="basic_props.html#term/1"><tt>basic_props:term/1</tt></a>)</span><span><span class="lpdoc-var">File</span> is any term. </span><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="10" href="stream_basic.html#io_mode/1"><tt>stream_basic:io_mode/1</tt></a>)</span><span><span class="lpdoc-var">Mode</span> is an opening mode (&apos;read&apos;, &apos;write&apos; or &apos;append&apos;). </span> <li><em>The following properties should hold upon exit:</em><br/><span class="lpdoc-on-right"> (<a class="lpdoc-idx-anchor" id="11" 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> </ul></div></div><p> </div><div id="Documentation on multifiles"><h2>Documentation on multifiles</h2><div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="alias_file/1" href="ciaosearch.html#alias_file/1">alias_file/1</a></div><div class="lpdoc-deftext"><span class="lpdoc-usage-decl"><tt>alias_file(File)</tt> </span><p>Declares <span class="lpdoc-var">File</span> to be a file defining symbolic names via <a class="lpdoc-idx-anchor" id="12" href="factsdb_rt.html#file_alias/2"><tt>file_alias/2</tt></a>. Anything else in <span class="lpdoc-var">File</span> is simply ignored. The predicate is <em>multifile</em>.<br/></div></div><p> <div><div class="lpdoc-defname"><span class="lpdoc-predtag">PREDICATE</span><a class="lpdoc-idx-anchor" id="file_alias/2" href="ciaosearch.html#file_alias/2">file_alias/2</a></div><div class="lpdoc-deftext"><span class="lpdoc-usage-decl"><tt>file_alias(Alias,File)</tt> </span><p>Declares <span class="lpdoc-var">Alias</span> as a symbolic name for <span class="lpdoc-var">File</span>, the real name of an actual file (or directory). The predicate is <em>multifile</em>.<br/> The predicate is of type <em>data</em>.<br/></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="13" href="datafacts_rt.html"><tt>datafacts_rt</tt></a>, <a class="lpdoc-idx-anchor" id="14" href="read.html"><tt>read</tt></a>, <a class="lpdoc-idx-anchor" id="15" href="system.html"><tt>system</tt></a>. <li><em>Packages:</em><br/><a class="lpdoc-idx-anchor" id="16" href="ciaosearch.html#prelude"><tt>prelude</tt></a>, <a class="lpdoc-idx-anchor" id="17" href="ciaosearch.html#initial"><tt>initial</tt></a>, <a class="lpdoc-idx-anchor" id="18" href="condcomp_doc.html"><tt>condcomp</tt></a>, <a class="lpdoc-idx-anchor" id="19" href="assertions_doc.html"><tt>assertions</tt></a>, <a class="lpdoc-idx-anchor" id="20" href="ciaosearch.html#assertions/assertions_basic"><tt>assertions/assertions_basic</tt></a>, <a class="lpdoc-idx-anchor" id="21" href="isomodes_doc.html"><tt>isomodes</tt></a>, <a class="lpdoc-idx-anchor" id="22" href="datafacts_doc.html"><tt>datafacts</tt></a>. </ul></div><div id="Other information"><h2>Other information</h2> The example discussed here is included in the distribution files. There is a main application file which uses module <tt>mm</tt>. This module reads a line from a file; the main predicate in the main file then prints this line. The important thing is that the file read is named by a symbolic name &quot;<tt>file</tt>&quot;. The main application file declares another file where the symbolic names are assigned actual file names:<p><pre class="lpdoc-codeblock"> :- use_module(mm). :- multifile alias_file/1. alias_file(myfiles). main :- p(X), display(X), nl. </pre> <p>Now, the file <tt>myfiles.pl</tt> can be used to change the file you want to read from without having to recompile the application. The current assignment is:<p><pre class="lpdoc-codeblock"> %:- use_package([]). file_alias(file,&apos;mm.pl&apos;). </pre> <p>so the execution of the application will show the first line of <tt>mm.pl</tt>. However, you can change to:<p><pre class="lpdoc-codeblock">file_alias(file,&apos;main.pl&apos;). </pre> <p>and then execution of the same executable will show the first line of <tt>main.pl</tt>.<p> <br/></div></div><div class="lpdoc-footer">Generated with LPdoc using Ciao</div></div><div class="lpdoc-clearer"></div></div></body></html>