

<!DOCTYPE html>
<!-- Server: sfs-forge-5 -->


    

















<html lang="en" class="no-js">
<head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
    <title>
  XSB / Src  (SVN)-old /
  [r2137]
  /trunk/XSB/docs/userman/library.tex
</title>
    

<meta name="viewport" content="width=1100">


<link rel="icon" sizes="180x180" href="https://a.fsdn.com/con/img/sandiego/logo-180x180.png" type="image/png">
<link rel="icon" sizes="any" href="https://a.fsdn.com/con/img/sandiego/svg/originals/sf-icon-orange-no_sf.svg" type="image/svg+xml">
<link rel="apple-touch-icon" sizes="180x180" href="https://a.fsdn.com/con/img/sandiego/logo-180x180.png">
<link rel="mask-icon" href="https://a.fsdn.com/con/img/sandiego/svg/originals/sf-icon-orange-no_sf.svg" color="#FF6600">


<script src="https://a.fsdn.com/allura/nf/1752257864/_ew_/theme/sftheme/js/sftheme/cmp2.js"></script>






    
    
    
    
    
    
    
    
    <link rel="stylesheet" href="https://a.fsdn.com/con/css/lato.css?">


<script>
if (!window.SF) { window.SF = {}; }
SF.sandiego = false;
SF.sandiego_chrome = true;
SF.cdn = "https://a.fsdn.com/con";
SF.fpid = '004685ec-e292-4e54-b751-f89c4f04e79b';
SF.billboard_route = '/software/product/$slug/';
</script>
    
        <!-- ew:head_css -->

    
        <link rel="stylesheet"
                type="text/css"
                href="https://a.fsdn.com/allura/nf/1752257864/_ew_/_slim/css?href=allura%2Fcss%2Fforge%2Fhilite.css%3Ballura%2Fcss%2Fforge%2Ftooltipster.css"
                >
    
        <link rel="stylesheet"
                type="text/css"
                href="https://a.fsdn.com/allura/nf/1752257864/_ew_/allura/css/font-awesome.min.css"
                >
    
        <link rel="stylesheet"
                type="text/css"
                href="https://a.fsdn.com/allura/nf/1752257864/_ew_/theme/sftheme/css/forge.css"
                >
    
        
<!-- /ew:head_css -->

    
    
        <!-- ew:head_js -->

    
        <script type="text/javascript" src="https://a.fsdn.com/allura/nf/1752257864/_ew_/_slim/js?href=allura%2Fjs%2Fjquery-3.6.0.min.js%3Ballura%2Fjs%2Fjquery.cookie-1.4.1.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fshared_head.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Ftypescript%2Fcompliance.js"></script>
    
        
<!-- /ew:head_js -->

    

    
        <style type="text/css">
            /* make URL &amp; Project custom fields in support tickets not get hidden as much */
.project-forge.mountpoint-site-support .view_holder .grid-4:nth-child(5),
.project-forge.mountpoint-site-support .view_holder .grid-4:nth-child(6) {
  overflow: visible;
  font-size: 22px;
  width: 340px;
  line-height: 1;
  margin-bottom: 5px;
}
.project-forge.mountpoint-site-support .view_holder .grid-4:nth-child(5) label, .project-forge.mountpoint-site-support .view_holder .grid-4:nth-child(6) label {
  font-size: 14px;
}
        </style>
    
    
    <link rel="alternate" type="application/rss+xml" title="RSS" href="/p/xsb/src/feed.rss"/>
    <link rel="alternate" type="application/atom+xml" title="Atom" href="/p/xsb/src/feed.atom"/>
    <style type="text/css">
        #access_urls .btn-set {
            
            min-width: 14em;
        }
    </style>

    <style>.XRREJKsKgwPDkcOecOvWOjADnCmzOwoDmi {
        display: none
    }</style>

    
    
    
        <link rel="canonical" href="https://sourceforge.net/p/xsb/src/2137/tree/trunk/XSB/docs/userman/library.tex" />
    


    

<script>
    var data = {hem: null };
    bizx.uids.gatherAndClean(data);
</script>



<script>
    function initPiwik(){
      var _paq = window._paq = window._paq || [];
      _paq.push(['trackPageView', document.title, {
            dimension1: 'xsb',
            dimension2: 'svn'
      }]);
      _paq.push(['enableLinkTracking']);
      
          _paq.push(['enableHeartBeatTimer']);
      
      (function() {
        var u="//analytics.slashdotmedia.com/";
        _paq.push(['setTrackerUrl', u+'sf.php']);
        _paq.push(['setSiteId', 39]);
        
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'sf.js'; s.parentNode.insertBefore(g,s);
      })();
    }
    bizx.cmp.ifConsent({ purposes: ['storage', 'measurement'], vendors: 'sdm'}, initPiwik);
</script>






<!-- Hubspot tracking -->






 <script>
    $(function() {
        bizx.cmp.ifConsent({ purposes: 'all' , vendors: 'narrative'}, function() {
            var current_time = (new Date()).getTime();
            let imageUrl = "https://io.narrative.io/?companyId=2440&id=first_party%3A004685ec-e292-4e54-b751-f89c4f04e79b&id=site_name%3Asourceforge.net&id=url%3A%2Fp%2Fxsb%2Fsrc%2F2137%2Ftree%2Ftrunk%2FXSB%2Fdocs%2Fuserman%2Flibrary.tex&id=pagetitle%3A%24PAGE_TITLE&id=vertical%3AOpen+Source+Software&id=product%3AXSB";
            imageUrl = imageUrl.replace(encodeURIComponent("$PAGE_TITLE"), document.title);  

            imageUrl = URL.parse(imageUrl);
            let hem = bizx.uids.getHem();
            if (hem) {
                imageUrl.searchParams.append('id', 'hem:' + hem);
            }
            imageUrl.searchParams.append('rand', current_time);

            var image = new Image();
            image.src = imageUrl.toString();
            image.style.display = "none";
            image.style.height = 0;
            image.style.width = 0;
            document.body.appendChild(image);
        });
    });
</script>



</head>

<body class="
body_class sandiego_chrome  legacy_chrome  l-allow-natural-width 
" id="forge">

    
        <!-- ew:body_top_js -->

    
        
<!-- /ew:body_top_js -->

    





<div class="off-canvas position-right" id="offCanvas" data-off-canvas>
    <!-- Menu -->
    <ul class="header-nav-menulist">
        <li class="highlight search">
            
            
                
            
            
    <form method="get" action="/directory/" class="m-search-form">
    
        <input type="text" placeholder="Search for software or solutions" autocomplete="off" name="q" >
        
        <label >
            <input type="submit" class="bt" value="">
            


<svg  data-name="search" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1216 832q0-185-131.5-316.5t-316.5-131.5-316.5 131.5-131.5 316.5 131.5 316.5 316.5 131.5 316.5-131.5 131.5-316.5zm512 832q0 52-38 90t-90 38q-54 0-90-38l-343-342q-179 124-399 124-143 0-273.5-55.5t-225-150-150-225-55.5-273.5 55.5-273.5 150-225 225-150 273.5-55.5 273.5 55.5 225 150 150 225 55.5 273.5q0 220-124 399l343 343q37 37 37 90z"/></svg>
        </label>
    </form>
        </li>
        
        <li class="highlight"><a href="/auth/">Join/Login</a></li>
        
        <li><a href="/software/">Business Software</a></li>
        <li><a href="/directory/">Open Source Software</a></li>
        <li><a  href="/software/vendors/" title="For Vendors">For Vendors</a></li>
        <li><a href="/blog/" title="Blog">Blog</a></li>
        <li><a href="/about">About</a></li>
        <li><a id="header-nav-more" data-toggle="header-nav-more header-nav-more-content" data-toggler=".toggled">More</a></li>
        <li>
            <ul id="header-nav-more-content" class="toggled" data-toggler=".toggled">
                
    

    
    
        <li><a href="/articles/">Articles</a></li>
    
    

    
 
                
                <li><a href="/create">Create</a></li>
                
                <li><a href="https://sourceforge.net/articles/category/sourceforge-podcast/">SourceForge Podcast</a></li>
                
                    <li><a href="https://sourceforge.net/p/forge/documentation/Docs%20Home/">Site Documentation</a></li>
                
                <li><a href="/user/newsletters">Subscribe to our Newsletter</a></li>
                <li><a href="/support">Support Request</a></li>
            </ul>
        </li>
    </ul>
</div>
<div class="off-canvas-content" data-off-canvas-content>

    




<script>
    SF.linkout_icon = '<svg  data-name="sf-linkout-icon" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 300 300" style="enable-background:new 0 0 300 300;" xml:space="preserve"><polygon class="st0" points="243.2,243.2 56.8,243.2 56.8,56.8 123,56.8 123,9 9,9 9,291 291,291 291,179.4 243.2,179 "/><polygon class="st0" points="128.5,213 155,186.5 176,165.5 206.7,196.3 235.5,132.5 248.9,102.6 290.6,9.8 291,9 290.6,9.2 197.4,51.1 169.1,63.8 103.7,93.3 137,126.5 115.9,147.5 89.5,174 "/></svg>';
</script>


<div class="l-header-nav  sandiego">

    <section class="sandiego l-header-nav-top show-for-large">
        <div class="row">
            <a href="/" title="Home" class="sf-logo">
                
    
    <img src="https://a.fsdn.com/con/images/sandiego/sf-logo-full.svg"  alt="SourceForge logo" class="sf-logo-full"/>
            </a>
            <nav class="links">
                
                    <a href="/user/newsletters" title="Subscribe to our newsletter"><span class="newsletter-icon">


<svg  data-name="mmSF_11mail" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 42 42" enable-background="new 0 0 42 42" xml:space="preserve"><path fill="#FFFFFF" d="M0,6v30h42V6H0z M24.2,21.2c-0.8,0.8-2.3,2-3.2,2c-0.9,0-2.4-1.2-3.2-2L5.8,9.7h30.3L24.2,21.2z M13.7,21l-9.9,9.4V11.6L13.7,21z M15.7,23L15.7,23c0.5,0.5,2.9,2.9,5.3,2.9c2.4,0,4.8-2.4,5.2-2.8l0.1-0.1l9.8,9.4H5.8L15.7,23z M28.3,21l9.9-9.5v18.9L28.3,21z"/></svg></span></a>
                
                <a href="/software/vendors/" title="For Vendors">For Vendors</a>
                
                
                    <a href="/support" title="Help">Help</a>
                    <a href="/create/" title="Create">Create</a>
                

                
                <a href="/user/registration" title="Join" >Join</a>
                <a href="/auth/" title="Login">Login</a>
                
            </nav>
        </div>
    </section>

    <section class="sandiego l-header-nav-top hide-for-large">
        <div class="row">
            <a href="/" title="Home" class="sf-logo">
                
    
    <img src="https://a.fsdn.com/con/images/sandiego/sf-logo-full.svg"  alt="SourceForge logo" class="sf-logo-full"/>
            </a>
            <div class="title-bar-right">
                <button type="button" aria-label="Toggle Main Menu" class="menu-icon" data-toggle="offCanvas"></button>
            </div>
        </div>
    </section>
    <section class="sandiego l-header-nav-bottom">
        <nav class="row">
            <a href="/" title="Home" class="sf-logo">
                
    
    <img src="https://a.fsdn.com/con/images/sandiego/sf-logo-full.svg"  alt="SourceForge logo" class="sf-logo-full"/>
            </a>
            <div class="links">
                
    
        <div class="nav-dropdown">
            <a href="/software/">Business Software</a>
            
        </div>
        <div class="nav-dropdown">
            <a href="/directory/" title="Browse">Open Source Software</a>
            
        </div>
        <div class="nav-dropdown">
            <a href="https://sourceforge.net/articles/category/sourceforge-podcast/">SourceForge Podcast</a>
        </div>
        <div class="nav-dropdown">
            <a>Resources</a>
            <ul class="nav-dropdown-menu">
                  <li><a href="/articles/">Articles</a></li>
                  
                  <li><a href="/software/case-studies/">Case Studies</a></li>
                  
                  <li><a href="/blog/">Blog</a></li>
            </ul>
        </div>
    

                <div class="dev-menu-when-stuck">
                    Menu
                    <ul class="dev-menu-dropdown header-nav-menulist">
                        <li><a href="/support">Help</a></li>
                        <li><a href="/create">Create</a></li>
                        <li><a href="/user/registration/" title="Join" >Join</a></li>
                        <li><a href="/auth/" title="Login">Login</a></li>
                    </ul>
                </div>
                <div class="search-toggle-when-stuck">
                    <a class="search-toggle">
                        


<svg  data-name="search" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1216 832q0-185-131.5-316.5t-316.5-131.5-316.5 131.5-131.5 316.5 131.5 316.5 316.5 131.5 316.5-131.5 131.5-316.5zm512 832q0 52-38 90t-90 38q-54 0-90-38l-343-342q-179 124-399 124-143 0-273.5-55.5t-225-150-150-225-55.5-273.5 55.5-273.5 150-225 225-150 273.5-55.5 273.5 55.5 225 150 150 225 55.5 273.5q0 220-124 399l343 343q37 37 37 90z"/></svg>
                    </a>
                </div>
            </div>

            <div class="search">
                
                
    
    
        <div class="main-nav-link">
            
            
            <a href="https://www.avast.com/lp-free-av?full_trSrc=mmm_srf_dlp_008_406_a&amp;utm_medium=referral&amp;utm_source=sourceforge&amp;utm_campaign=srf_dlp_008_406_a:site_banner" rel="nofollow" target="_blank" id="main-nav-badge-link" data-label="avastjuly">
                <img src="https://a.fsdn.com/con/assets/maxnav/sourceforge/ai-protection-32-75dd98b2.png"  srcset="https://a.fsdn.com/con/assets/maxnav/sourceforge/ai-protection-75de80f6.png 2x"  alt="" id="main-nav-image"/>
            </a>
        </div>
    


                
                    
                
                
                
                
    <form method="get" action="/directory/" class="m-search-form">
    
    <div class="typeahead__container">
      <div class="typeahead__field">
        <div class="typeahead__query">
        
        <input type="text" placeholder="Search for software or solutions" autocomplete="off" name="q" >
        
        </div>
        
        <label >
            <input type="submit" class="bt" value="">
            


<svg  data-name="search" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1216 832q0-185-131.5-316.5t-316.5-131.5-316.5 131.5-131.5 316.5 131.5 316.5 316.5 131.5 316.5-131.5 131.5-316.5zm512 832q0 52-38 90t-90 38q-54 0-90-38l-343-342q-179 124-399 124-143 0-273.5-55.5t-225-150-150-225-55.5-273.5 55.5-273.5 150-225 225-150 273.5-55.5 273.5 55.5 225 150 150 225 55.5 273.5q0 220-124 399l343 343q37 37 37 90z"/></svg>
        </label>
      </div>
    </div>
    
    </form>
                
            </div>
        </nav>
        
    </section>
    
</div>
    
    
    <div class="notification-on-project-page">
    
        
    
    
    
    </div>
    
    


    <section id="page-body" class=" neighborhood-Projects project-xsb mountpoint-src 

">
        <div id="nav_menu_holder">
            
                
                    
    <div class="sandiego"> 
            
            
            
            
<section class="project-masthead"> 
    
    

    
<div class="backdrop" style="box-sizing: content-box; padding-bottom: 24px"></div>

    <div class="content">
    
        
    <nav id="breadcrumbs" class="breadcrumbs rtl">
        <ul itemscope itemtype="http://schema.org/BreadcrumbList">
            <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
                <a itemprop="item" href="/"><span itemprop="name">Home</span></a>
                <meta itemprop="position" content="1"/>
            </li>
            <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
                <a itemprop="item" href="/directory/"><span itemprop="name">Browse</span></a>
                <meta itemprop="position" content="2"/>
            </li>
            
            
                
                
            
            
                
            
            
                <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
                    <a itemprop="item" href="/p/xsb/"><span itemprop="name">XSB</span></a>
                <meta itemprop="position" content="3"/>
                </li>
            
                <li itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem">
                    <span itemprop="name">Src  (SVN)-old</span>
                <meta itemprop="position" content="4"/>
                </li>
            
        </ul>
    </nav>
    
    
    
        
                
                
<div class="overview">
    


<div class="project-icon   " >
    
    
    <img itemprop="image" alt="XSB" title="XSB" 
    
    
    src="https://a.fsdn.com/allura/p/xsb/icon?1368563712"
    /></div>


    
    <div class="title "> 

        <meta itemprop="name" content="XSB"/>
        <h1  >XSB Src  (SVN)-old
        </h1>
        
            
            
          
        
            
            
            <div class="as-h3 brought-by">
                
                Brought to you by:
                
                    <a href="/u/carlandersen/profile/">carlandersen</a>,
                    
                
                    <a href="/u/dwarren/profile/">dwarren</a>,
                    
                
                    <a href="/u/evansbj/profile/">evansbj</a>,
                    
                
                    <a href="/u/kifer/profile/">kifer</a>,
                    
                
                    
                        and <a href="/p/xsb/_members/">3 others</a>
                    
                
            </div>
            
        

        

        
    </div>


    

</div>

                
                
    
  
            
            
        
    </div>
</section>

        </div>
    

                
            
        </div>
        <div id="top_nav" class="">
            
                
<div id="top_nav_admin">
<ul class="dropdown">
  
  
    <li class="">
        <a href="/projects/xsb/" class="tool-summary-32" >
            Summary
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/projects/xsb/files/" class="tool-files-sf-32" >
            Files
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/projects/xsb/reviews/" class="tool-reviews-32" >
            Reviews
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/projects/xsb/support" class="tool-support-32" >
            Support
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/p/xsb/mailman/" class="tool-mailman-32" >
            Mail Lists
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/p/xsb/_list/tickets" class="tool-tickets-32" >
            Tickets ▾
        </a>
        
        
            <ul>
                
                    <li class=""><a href="/p/xsb/bugs/" >Bugs</a></li>
                
                    <li class=""><a href="/p/xsb/feature-requests/" >Feature Requests</a></li>
                
                    <li class=""><a href="/p/xsb/support-requests/" >Support Requests</a></li>
                
                    <li class=""><a href="/p/xsb/patches/" >Patches</a></li>
                
            </ul>
        
    </li>
  
    <li class="">
        <a href="/p/xsb/news/" class="tool-blog-32" >
            News
        </a>
        
        
    </li>
  
    <li class="">
        <a href="/p/xsb/code/" class="tool-git-32" >
            Sources (GIT)
        </a>
        
        
    </li>
  
    <li class="selected">
        <a href="/p/xsb/src/" class="tool-svn-32" >
            Src  (SVN)-old
        </a>
        
        
    </li>
  
  
</ul>
</div>


            
        </div>
        <div id="content_base">
            

    
                
                    
<a id="sidebar-activate" href="#">
    <span class="btn-label">Menu</span>
    <span class="btn-arrow-down">▾</span>
    <span class="btn-arrow-up">▴</span>
</a>

                        


<div id="sidebar">
  
    <div class="placeholder-no-searchbox">&nbsp;</div>
  
    
    
      
      
        
    
      <ul class="sidebarmenu">
      
    
  <li>
      
        <a class="icon" href="/p/xsb/src/commit_browser" rel="nofollow" title="Browse Commits"><i class="fa fa-list"></i>
      
      <span>Browse Commits</span>
      </a>
  </li>
  
      
        
    
  <li>
      
        <a href="/p/xsb/src/"  rel="nofollow" >
      
      <span>Browse Files</span>
      </a>
  </li>
  
      
    
    
      </ul>
      
    
    
</div>



<script>
$('#sidebar-admin-header').on('click', function(e){
    $("#sidebar-admin-menu").toggleClass("hidden");
    $(this).toggleClass("expanded");
    e.preventDefault();
});
</script>

                    

                    
                
                
                    
                
                <div class="grid-20 pad">
                    <h2 class="dark title">
                        <span>
<a href="/p/xsb/src/2137/" rel="nofollow">[r2137]</a>:

  
      <a href="./../../../../" rel="nofollow"><b class="fa fa-folder-open-o" title="Root directory"></b></a> /
  
  
    <a href="./../../../" rel="nofollow">trunk</a> /
  
    <a href="./../../" rel="nofollow">XSB</a> /
  
    <a href="./../" rel="nofollow">docs</a> /
  
    <a href="./" rel="nofollow">userman</a> /
  
 library.tex
</span>
                        <!-- actions -->
                        <small>
                            

    
    <a class="icon" href="#" id="maximize-content" title="Maximize"><i class="fa fa-expand"></i>&nbsp;Maximize</a>
    <a class="icon" href="#" id="restore-content" title="Restore"><i class="fa fa-compress"></i>&nbsp;Restore</a>
<a class="icon" href="/p/xsb/src/2137/log/?path=/trunk/XSB/docs/userman/library.tex" rel="nofollow" title="History"><i class="fa fa-calendar"></i>&nbsp;History</a>

                        </small>
                        <!-- /actions -->
                    </h2>
                    
                    <div>
                        
  

                        
  
    <p><a rel="nofollow" href="?format=raw">Download this file</a></p>
    <div class="clip grid-19 codebrowser">
      <h3>
        2437 lines (2062 with data), 105.6 kB
      </h3>
      
        <div class="codehilite"><table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">   1</span>
<span class="normal">   2</span>
<span class="normal">   3</span>
<span class="normal">   4</span>
<span class="normal">   5</span>
<span class="normal">   6</span>
<span class="normal">   7</span>
<span class="normal">   8</span>
<span class="normal">   9</span>
<span class="normal">  10</span>
<span class="normal">  11</span>
<span class="normal">  12</span>
<span class="normal">  13</span>
<span class="normal">  14</span>
<span class="normal">  15</span>
<span class="normal">  16</span>
<span class="normal">  17</span>
<span class="normal">  18</span>
<span class="normal">  19</span>
<span class="normal">  20</span>
<span class="normal">  21</span>
<span class="normal">  22</span>
<span class="normal">  23</span>
<span class="normal">  24</span>
<span class="normal">  25</span>
<span class="normal">  26</span>
<span class="normal">  27</span>
<span class="normal">  28</span>
<span class="normal">  29</span>
<span class="normal">  30</span>
<span class="normal">  31</span>
<span class="normal">  32</span>
<span class="normal">  33</span>
<span class="normal">  34</span>
<span class="normal">  35</span>
<span class="normal">  36</span>
<span class="normal">  37</span>
<span class="normal">  38</span>
<span class="normal">  39</span>
<span class="normal">  40</span>
<span class="normal">  41</span>
<span class="normal">  42</span>
<span class="normal">  43</span>
<span class="normal">  44</span>
<span class="normal">  45</span>
<span class="normal">  46</span>
<span class="normal">  47</span>
<span class="normal">  48</span>
<span class="normal">  49</span>
<span class="normal">  50</span>
<span class="normal">  51</span>
<span class="normal">  52</span>
<span class="normal">  53</span>
<span class="normal">  54</span>
<span class="normal">  55</span>
<span class="normal">  56</span>
<span class="normal">  57</span>
<span class="normal">  58</span>
<span class="normal">  59</span>
<span class="normal">  60</span>
<span class="normal">  61</span>
<span class="normal">  62</span>
<span class="normal">  63</span>
<span class="normal">  64</span>
<span class="normal">  65</span>
<span class="normal">  66</span>
<span class="normal">  67</span>
<span class="normal">  68</span>
<span class="normal">  69</span>
<span class="normal">  70</span>
<span class="normal">  71</span>
<span class="normal">  72</span>
<span class="normal">  73</span>
<span class="normal">  74</span>
<span class="normal">  75</span>
<span class="normal">  76</span>
<span class="normal">  77</span>
<span class="normal">  78</span>
<span class="normal">  79</span>
<span class="normal">  80</span>
<span class="normal">  81</span>
<span class="normal">  82</span>
<span class="normal">  83</span>
<span class="normal">  84</span>
<span class="normal">  85</span>
<span class="normal">  86</span>
<span class="normal">  87</span>
<span class="normal">  88</span>
<span class="normal">  89</span>
<span class="normal">  90</span>
<span class="normal">  91</span>
<span class="normal">  92</span>
<span class="normal">  93</span>
<span class="normal">  94</span>
<span class="normal">  95</span>
<span class="normal">  96</span>
<span class="normal">  97</span>
<span class="normal">  98</span>
<span class="normal">  99</span>
<span class="normal"> 100</span>
<span class="normal"> 101</span>
<span class="normal"> 102</span>
<span class="normal"> 103</span>
<span class="normal"> 104</span>
<span class="normal"> 105</span>
<span class="normal"> 106</span>
<span class="normal"> 107</span>
<span class="normal"> 108</span>
<span class="normal"> 109</span>
<span class="normal"> 110</span>
<span class="normal"> 111</span>
<span class="normal"> 112</span>
<span class="normal"> 113</span>
<span class="normal"> 114</span>
<span class="normal"> 115</span>
<span class="normal"> 116</span>
<span class="normal"> 117</span>
<span class="normal"> 118</span>
<span class="normal"> 119</span>
<span class="normal"> 120</span>
<span class="normal"> 121</span>
<span class="normal"> 122</span>
<span class="normal"> 123</span>
<span class="normal"> 124</span>
<span class="normal"> 125</span>
<span class="normal"> 126</span>
<span class="normal"> 127</span>
<span class="normal"> 128</span>
<span class="normal"> 129</span>
<span class="normal"> 130</span>
<span class="normal"> 131</span>
<span class="normal"> 132</span>
<span class="normal"> 133</span>
<span class="normal"> 134</span>
<span class="normal"> 135</span>
<span class="normal"> 136</span>
<span class="normal"> 137</span>
<span class="normal"> 138</span>
<span class="normal"> 139</span>
<span class="normal"> 140</span>
<span class="normal"> 141</span>
<span class="normal"> 142</span>
<span class="normal"> 143</span>
<span class="normal"> 144</span>
<span class="normal"> 145</span>
<span class="normal"> 146</span>
<span class="normal"> 147</span>
<span class="normal"> 148</span>
<span class="normal"> 149</span>
<span class="normal"> 150</span>
<span class="normal"> 151</span>
<span class="normal"> 152</span>
<span class="normal"> 153</span>
<span class="normal"> 154</span>
<span class="normal"> 155</span>
<span class="normal"> 156</span>
<span class="normal"> 157</span>
<span class="normal"> 158</span>
<span class="normal"> 159</span>
<span class="normal"> 160</span>
<span class="normal"> 161</span>
<span class="normal"> 162</span>
<span class="normal"> 163</span>
<span class="normal"> 164</span>
<span class="normal"> 165</span>
<span class="normal"> 166</span>
<span class="normal"> 167</span>
<span class="normal"> 168</span>
<span class="normal"> 169</span>
<span class="normal"> 170</span>
<span class="normal"> 171</span>
<span class="normal"> 172</span>
<span class="normal"> 173</span>
<span class="normal"> 174</span>
<span class="normal"> 175</span>
<span class="normal"> 176</span>
<span class="normal"> 177</span>
<span class="normal"> 178</span>
<span class="normal"> 179</span>
<span class="normal"> 180</span>
<span class="normal"> 181</span>
<span class="normal"> 182</span>
<span class="normal"> 183</span>
<span class="normal"> 184</span>
<span class="normal"> 185</span>
<span class="normal"> 186</span>
<span class="normal"> 187</span>
<span class="normal"> 188</span>
<span class="normal"> 189</span>
<span class="normal"> 190</span>
<span class="normal"> 191</span>
<span class="normal"> 192</span>
<span class="normal"> 193</span>
<span class="normal"> 194</span>
<span class="normal"> 195</span>
<span class="normal"> 196</span>
<span class="normal"> 197</span>
<span class="normal"> 198</span>
<span class="normal"> 199</span>
<span class="normal"> 200</span>
<span class="normal"> 201</span>
<span class="normal"> 202</span>
<span class="normal"> 203</span>
<span class="normal"> 204</span>
<span class="normal"> 205</span>
<span class="normal"> 206</span>
<span class="normal"> 207</span>
<span class="normal"> 208</span>
<span class="normal"> 209</span>
<span class="normal"> 210</span>
<span class="normal"> 211</span>
<span class="normal"> 212</span>
<span class="normal"> 213</span>
<span class="normal"> 214</span>
<span class="normal"> 215</span>
<span class="normal"> 216</span>
<span class="normal"> 217</span>
<span class="normal"> 218</span>
<span class="normal"> 219</span>
<span class="normal"> 220</span>
<span class="normal"> 221</span>
<span class="normal"> 222</span>
<span class="normal"> 223</span>
<span class="normal"> 224</span>
<span class="normal"> 225</span>
<span class="normal"> 226</span>
<span class="normal"> 227</span>
<span class="normal"> 228</span>
<span class="normal"> 229</span>
<span class="normal"> 230</span>
<span class="normal"> 231</span>
<span class="normal"> 232</span>
<span class="normal"> 233</span>
<span class="normal"> 234</span>
<span class="normal"> 235</span>
<span class="normal"> 236</span>
<span class="normal"> 237</span>
<span class="normal"> 238</span>
<span class="normal"> 239</span>
<span class="normal"> 240</span>
<span class="normal"> 241</span>
<span class="normal"> 242</span>
<span class="normal"> 243</span>
<span class="normal"> 244</span>
<span class="normal"> 245</span>
<span class="normal"> 246</span>
<span class="normal"> 247</span>
<span class="normal"> 248</span>
<span class="normal"> 249</span>
<span class="normal"> 250</span>
<span class="normal"> 251</span>
<span class="normal"> 252</span>
<span class="normal"> 253</span>
<span class="normal"> 254</span>
<span class="normal"> 255</span>
<span class="normal"> 256</span>
<span class="normal"> 257</span>
<span class="normal"> 258</span>
<span class="normal"> 259</span>
<span class="normal"> 260</span>
<span class="normal"> 261</span>
<span class="normal"> 262</span>
<span class="normal"> 263</span>
<span class="normal"> 264</span>
<span class="normal"> 265</span>
<span class="normal"> 266</span>
<span class="normal"> 267</span>
<span class="normal"> 268</span>
<span class="normal"> 269</span>
<span class="normal"> 270</span>
<span class="normal"> 271</span>
<span class="normal"> 272</span>
<span class="normal"> 273</span>
<span class="normal"> 274</span>
<span class="normal"> 275</span>
<span class="normal"> 276</span>
<span class="normal"> 277</span>
<span class="normal"> 278</span>
<span class="normal"> 279</span>
<span class="normal"> 280</span>
<span class="normal"> 281</span>
<span class="normal"> 282</span>
<span class="normal"> 283</span>
<span class="normal"> 284</span>
<span class="normal"> 285</span>
<span class="normal"> 286</span>
<span class="normal"> 287</span>
<span class="normal"> 288</span>
<span class="normal"> 289</span>
<span class="normal"> 290</span>
<span class="normal"> 291</span>
<span class="normal"> 292</span>
<span class="normal"> 293</span>
<span class="normal"> 294</span>
<span class="normal"> 295</span>
<span class="normal"> 296</span>
<span class="normal"> 297</span>
<span class="normal"> 298</span>
<span class="normal"> 299</span>
<span class="normal"> 300</span>
<span class="normal"> 301</span>
<span class="normal"> 302</span>
<span class="normal"> 303</span>
<span class="normal"> 304</span>
<span class="normal"> 305</span>
<span class="normal"> 306</span>
<span class="normal"> 307</span>
<span class="normal"> 308</span>
<span class="normal"> 309</span>
<span class="normal"> 310</span>
<span class="normal"> 311</span>
<span class="normal"> 312</span>
<span class="normal"> 313</span>
<span class="normal"> 314</span>
<span class="normal"> 315</span>
<span class="normal"> 316</span>
<span class="normal"> 317</span>
<span class="normal"> 318</span>
<span class="normal"> 319</span>
<span class="normal"> 320</span>
<span class="normal"> 321</span>
<span class="normal"> 322</span>
<span class="normal"> 323</span>
<span class="normal"> 324</span>
<span class="normal"> 325</span>
<span class="normal"> 326</span>
<span class="normal"> 327</span>
<span class="normal"> 328</span>
<span class="normal"> 329</span>
<span class="normal"> 330</span>
<span class="normal"> 331</span>
<span class="normal"> 332</span>
<span class="normal"> 333</span>
<span class="normal"> 334</span>
<span class="normal"> 335</span>
<span class="normal"> 336</span>
<span class="normal"> 337</span>
<span class="normal"> 338</span>
<span class="normal"> 339</span>
<span class="normal"> 340</span>
<span class="normal"> 341</span>
<span class="normal"> 342</span>
<span class="normal"> 343</span>
<span class="normal"> 344</span>
<span class="normal"> 345</span>
<span class="normal"> 346</span>
<span class="normal"> 347</span>
<span class="normal"> 348</span>
<span class="normal"> 349</span>
<span class="normal"> 350</span>
<span class="normal"> 351</span>
<span class="normal"> 352</span>
<span class="normal"> 353</span>
<span class="normal"> 354</span>
<span class="normal"> 355</span>
<span class="normal"> 356</span>
<span class="normal"> 357</span>
<span class="normal"> 358</span>
<span class="normal"> 359</span>
<span class="normal"> 360</span>
<span class="normal"> 361</span>
<span class="normal"> 362</span>
<span class="normal"> 363</span>
<span class="normal"> 364</span>
<span class="normal"> 365</span>
<span class="normal"> 366</span>
<span class="normal"> 367</span>
<span class="normal"> 368</span>
<span class="normal"> 369</span>
<span class="normal"> 370</span>
<span class="normal"> 371</span>
<span class="normal"> 372</span>
<span class="normal"> 373</span>
<span class="normal"> 374</span>
<span class="normal"> 375</span>
<span class="normal"> 376</span>
<span class="normal"> 377</span>
<span class="normal"> 378</span>
<span class="normal"> 379</span>
<span class="normal"> 380</span>
<span class="normal"> 381</span>
<span class="normal"> 382</span>
<span class="normal"> 383</span>
<span class="normal"> 384</span>
<span class="normal"> 385</span>
<span class="normal"> 386</span>
<span class="normal"> 387</span>
<span class="normal"> 388</span>
<span class="normal"> 389</span>
<span class="normal"> 390</span>
<span class="normal"> 391</span>
<span class="normal"> 392</span>
<span class="normal"> 393</span>
<span class="normal"> 394</span>
<span class="normal"> 395</span>
<span class="normal"> 396</span>
<span class="normal"> 397</span>
<span class="normal"> 398</span>
<span class="normal"> 399</span>
<span class="normal"> 400</span>
<span class="normal"> 401</span>
<span class="normal"> 402</span>
<span class="normal"> 403</span>
<span class="normal"> 404</span>
<span class="normal"> 405</span>
<span class="normal"> 406</span>
<span class="normal"> 407</span>
<span class="normal"> 408</span>
<span class="normal"> 409</span>
<span class="normal"> 410</span>
<span class="normal"> 411</span>
<span class="normal"> 412</span>
<span class="normal"> 413</span>
<span class="normal"> 414</span>
<span class="normal"> 415</span>
<span class="normal"> 416</span>
<span class="normal"> 417</span>
<span class="normal"> 418</span>
<span class="normal"> 419</span>
<span class="normal"> 420</span>
<span class="normal"> 421</span>
<span class="normal"> 422</span>
<span class="normal"> 423</span>
<span class="normal"> 424</span>
<span class="normal"> 425</span>
<span class="normal"> 426</span>
<span class="normal"> 427</span>
<span class="normal"> 428</span>
<span class="normal"> 429</span>
<span class="normal"> 430</span>
<span class="normal"> 431</span>
<span class="normal"> 432</span>
<span class="normal"> 433</span>
<span class="normal"> 434</span>
<span class="normal"> 435</span>
<span class="normal"> 436</span>
<span class="normal"> 437</span>
<span class="normal"> 438</span>
<span class="normal"> 439</span>
<span class="normal"> 440</span>
<span class="normal"> 441</span>
<span class="normal"> 442</span>
<span class="normal"> 443</span>
<span class="normal"> 444</span>
<span class="normal"> 445</span>
<span class="normal"> 446</span>
<span class="normal"> 447</span>
<span class="normal"> 448</span>
<span class="normal"> 449</span>
<span class="normal"> 450</span>
<span class="normal"> 451</span>
<span class="normal"> 452</span>
<span class="normal"> 453</span>
<span class="normal"> 454</span>
<span class="normal"> 455</span>
<span class="normal"> 456</span>
<span class="normal"> 457</span>
<span class="normal"> 458</span>
<span class="normal"> 459</span>
<span class="normal"> 460</span>
<span class="normal"> 461</span>
<span class="normal"> 462</span>
<span class="normal"> 463</span>
<span class="normal"> 464</span>
<span class="normal"> 465</span>
<span class="normal"> 466</span>
<span class="normal"> 467</span>
<span class="normal"> 468</span>
<span class="normal"> 469</span>
<span class="normal"> 470</span>
<span class="normal"> 471</span>
<span class="normal"> 472</span>
<span class="normal"> 473</span>
<span class="normal"> 474</span>
<span class="normal"> 475</span>
<span class="normal"> 476</span>
<span class="normal"> 477</span>
<span class="normal"> 478</span>
<span class="normal"> 479</span>
<span class="normal"> 480</span>
<span class="normal"> 481</span>
<span class="normal"> 482</span>
<span class="normal"> 483</span>
<span class="normal"> 484</span>
<span class="normal"> 485</span>
<span class="normal"> 486</span>
<span class="normal"> 487</span>
<span class="normal"> 488</span>
<span class="normal"> 489</span>
<span class="normal"> 490</span>
<span class="normal"> 491</span>
<span class="normal"> 492</span>
<span class="normal"> 493</span>
<span class="normal"> 494</span>
<span class="normal"> 495</span>
<span class="normal"> 496</span>
<span class="normal"> 497</span>
<span class="normal"> 498</span>
<span class="normal"> 499</span>
<span class="normal"> 500</span>
<span class="normal"> 501</span>
<span class="normal"> 502</span>
<span class="normal"> 503</span>
<span class="normal"> 504</span>
<span class="normal"> 505</span>
<span class="normal"> 506</span>
<span class="normal"> 507</span>
<span class="normal"> 508</span>
<span class="normal"> 509</span>
<span class="normal"> 510</span>
<span class="normal"> 511</span>
<span class="normal"> 512</span>
<span class="normal"> 513</span>
<span class="normal"> 514</span>
<span class="normal"> 515</span>
<span class="normal"> 516</span>
<span class="normal"> 517</span>
<span class="normal"> 518</span>
<span class="normal"> 519</span>
<span class="normal"> 520</span>
<span class="normal"> 521</span>
<span class="normal"> 522</span>
<span class="normal"> 523</span>
<span class="normal"> 524</span>
<span class="normal"> 525</span>
<span class="normal"> 526</span>
<span class="normal"> 527</span>
<span class="normal"> 528</span>
<span class="normal"> 529</span>
<span class="normal"> 530</span>
<span class="normal"> 531</span>
<span class="normal"> 532</span>
<span class="normal"> 533</span>
<span class="normal"> 534</span>
<span class="normal"> 535</span>
<span class="normal"> 536</span>
<span class="normal"> 537</span>
<span class="normal"> 538</span>
<span class="normal"> 539</span>
<span class="normal"> 540</span>
<span class="normal"> 541</span>
<span class="normal"> 542</span>
<span class="normal"> 543</span>
<span class="normal"> 544</span>
<span class="normal"> 545</span>
<span class="normal"> 546</span>
<span class="normal"> 547</span>
<span class="normal"> 548</span>
<span class="normal"> 549</span>
<span class="normal"> 550</span>
<span class="normal"> 551</span>
<span class="normal"> 552</span>
<span class="normal"> 553</span>
<span class="normal"> 554</span>
<span class="normal"> 555</span>
<span class="normal"> 556</span>
<span class="normal"> 557</span>
<span class="normal"> 558</span>
<span class="normal"> 559</span>
<span class="normal"> 560</span>
<span class="normal"> 561</span>
<span class="normal"> 562</span>
<span class="normal"> 563</span>
<span class="normal"> 564</span>
<span class="normal"> 565</span>
<span class="normal"> 566</span>
<span class="normal"> 567</span>
<span class="normal"> 568</span>
<span class="normal"> 569</span>
<span class="normal"> 570</span>
<span class="normal"> 571</span>
<span class="normal"> 572</span>
<span class="normal"> 573</span>
<span class="normal"> 574</span>
<span class="normal"> 575</span>
<span class="normal"> 576</span>
<span class="normal"> 577</span>
<span class="normal"> 578</span>
<span class="normal"> 579</span>
<span class="normal"> 580</span>
<span class="normal"> 581</span>
<span class="normal"> 582</span>
<span class="normal"> 583</span>
<span class="normal"> 584</span>
<span class="normal"> 585</span>
<span class="normal"> 586</span>
<span class="normal"> 587</span>
<span class="normal"> 588</span>
<span class="normal"> 589</span>
<span class="normal"> 590</span>
<span class="normal"> 591</span>
<span class="normal"> 592</span>
<span class="normal"> 593</span>
<span class="normal"> 594</span>
<span class="normal"> 595</span>
<span class="normal"> 596</span>
<span class="normal"> 597</span>
<span class="normal"> 598</span>
<span class="normal"> 599</span>
<span class="normal"> 600</span>
<span class="normal"> 601</span>
<span class="normal"> 602</span>
<span class="normal"> 603</span>
<span class="normal"> 604</span>
<span class="normal"> 605</span>
<span class="normal"> 606</span>
<span class="normal"> 607</span>
<span class="normal"> 608</span>
<span class="normal"> 609</span>
<span class="normal"> 610</span>
<span class="normal"> 611</span>
<span class="normal"> 612</span>
<span class="normal"> 613</span>
<span class="normal"> 614</span>
<span class="normal"> 615</span>
<span class="normal"> 616</span>
<span class="normal"> 617</span>
<span class="normal"> 618</span>
<span class="normal"> 619</span>
<span class="normal"> 620</span>
<span class="normal"> 621</span>
<span class="normal"> 622</span>
<span class="normal"> 623</span>
<span class="normal"> 624</span>
<span class="normal"> 625</span>
<span class="normal"> 626</span>
<span class="normal"> 627</span>
<span class="normal"> 628</span>
<span class="normal"> 629</span>
<span class="normal"> 630</span>
<span class="normal"> 631</span>
<span class="normal"> 632</span>
<span class="normal"> 633</span>
<span class="normal"> 634</span>
<span class="normal"> 635</span>
<span class="normal"> 636</span>
<span class="normal"> 637</span>
<span class="normal"> 638</span>
<span class="normal"> 639</span>
<span class="normal"> 640</span>
<span class="normal"> 641</span>
<span class="normal"> 642</span>
<span class="normal"> 643</span>
<span class="normal"> 644</span>
<span class="normal"> 645</span>
<span class="normal"> 646</span>
<span class="normal"> 647</span>
<span class="normal"> 648</span>
<span class="normal"> 649</span>
<span class="normal"> 650</span>
<span class="normal"> 651</span>
<span class="normal"> 652</span>
<span class="normal"> 653</span>
<span class="normal"> 654</span>
<span class="normal"> 655</span>
<span class="normal"> 656</span>
<span class="normal"> 657</span>
<span class="normal"> 658</span>
<span class="normal"> 659</span>
<span class="normal"> 660</span>
<span class="normal"> 661</span>
<span class="normal"> 662</span>
<span class="normal"> 663</span>
<span class="normal"> 664</span>
<span class="normal"> 665</span>
<span class="normal"> 666</span>
<span class="normal"> 667</span>
<span class="normal"> 668</span>
<span class="normal"> 669</span>
<span class="normal"> 670</span>
<span class="normal"> 671</span>
<span class="normal"> 672</span>
<span class="normal"> 673</span>
<span class="normal"> 674</span>
<span class="normal"> 675</span>
<span class="normal"> 676</span>
<span class="normal"> 677</span>
<span class="normal"> 678</span>
<span class="normal"> 679</span>
<span class="normal"> 680</span>
<span class="normal"> 681</span>
<span class="normal"> 682</span>
<span class="normal"> 683</span>
<span class="normal"> 684</span>
<span class="normal"> 685</span>
<span class="normal"> 686</span>
<span class="normal"> 687</span>
<span class="normal"> 688</span>
<span class="normal"> 689</span>
<span class="normal"> 690</span>
<span class="normal"> 691</span>
<span class="normal"> 692</span>
<span class="normal"> 693</span>
<span class="normal"> 694</span>
<span class="normal"> 695</span>
<span class="normal"> 696</span>
<span class="normal"> 697</span>
<span class="normal"> 698</span>
<span class="normal"> 699</span>
<span class="normal"> 700</span>
<span class="normal"> 701</span>
<span class="normal"> 702</span>
<span class="normal"> 703</span>
<span class="normal"> 704</span>
<span class="normal"> 705</span>
<span class="normal"> 706</span>
<span class="normal"> 707</span>
<span class="normal"> 708</span>
<span class="normal"> 709</span>
<span class="normal"> 710</span>
<span class="normal"> 711</span>
<span class="normal"> 712</span>
<span class="normal"> 713</span>
<span class="normal"> 714</span>
<span class="normal"> 715</span>
<span class="normal"> 716</span>
<span class="normal"> 717</span>
<span class="normal"> 718</span>
<span class="normal"> 719</span>
<span class="normal"> 720</span>
<span class="normal"> 721</span>
<span class="normal"> 722</span>
<span class="normal"> 723</span>
<span class="normal"> 724</span>
<span class="normal"> 725</span>
<span class="normal"> 726</span>
<span class="normal"> 727</span>
<span class="normal"> 728</span>
<span class="normal"> 729</span>
<span class="normal"> 730</span>
<span class="normal"> 731</span>
<span class="normal"> 732</span>
<span class="normal"> 733</span>
<span class="normal"> 734</span>
<span class="normal"> 735</span>
<span class="normal"> 736</span>
<span class="normal"> 737</span>
<span class="normal"> 738</span>
<span class="normal"> 739</span>
<span class="normal"> 740</span>
<span class="normal"> 741</span>
<span class="normal"> 742</span>
<span class="normal"> 743</span>
<span class="normal"> 744</span>
<span class="normal"> 745</span>
<span class="normal"> 746</span>
<span class="normal"> 747</span>
<span class="normal"> 748</span>
<span class="normal"> 749</span>
<span class="normal"> 750</span>
<span class="normal"> 751</span>
<span class="normal"> 752</span>
<span class="normal"> 753</span>
<span class="normal"> 754</span>
<span class="normal"> 755</span>
<span class="normal"> 756</span>
<span class="normal"> 757</span>
<span class="normal"> 758</span>
<span class="normal"> 759</span>
<span class="normal"> 760</span>
<span class="normal"> 761</span>
<span class="normal"> 762</span>
<span class="normal"> 763</span>
<span class="normal"> 764</span>
<span class="normal"> 765</span>
<span class="normal"> 766</span>
<span class="normal"> 767</span>
<span class="normal"> 768</span>
<span class="normal"> 769</span>
<span class="normal"> 770</span>
<span class="normal"> 771</span>
<span class="normal"> 772</span>
<span class="normal"> 773</span>
<span class="normal"> 774</span>
<span class="normal"> 775</span>
<span class="normal"> 776</span>
<span class="normal"> 777</span>
<span class="normal"> 778</span>
<span class="normal"> 779</span>
<span class="normal"> 780</span>
<span class="normal"> 781</span>
<span class="normal"> 782</span>
<span class="normal"> 783</span>
<span class="normal"> 784</span>
<span class="normal"> 785</span>
<span class="normal"> 786</span>
<span class="normal"> 787</span>
<span class="normal"> 788</span>
<span class="normal"> 789</span>
<span class="normal"> 790</span>
<span class="normal"> 791</span>
<span class="normal"> 792</span>
<span class="normal"> 793</span>
<span class="normal"> 794</span>
<span class="normal"> 795</span>
<span class="normal"> 796</span>
<span class="normal"> 797</span>
<span class="normal"> 798</span>
<span class="normal"> 799</span>
<span class="normal"> 800</span>
<span class="normal"> 801</span>
<span class="normal"> 802</span>
<span class="normal"> 803</span>
<span class="normal"> 804</span>
<span class="normal"> 805</span>
<span class="normal"> 806</span>
<span class="normal"> 807</span>
<span class="normal"> 808</span>
<span class="normal"> 809</span>
<span class="normal"> 810</span>
<span class="normal"> 811</span>
<span class="normal"> 812</span>
<span class="normal"> 813</span>
<span class="normal"> 814</span>
<span class="normal"> 815</span>
<span class="normal"> 816</span>
<span class="normal"> 817</span>
<span class="normal"> 818</span>
<span class="normal"> 819</span>
<span class="normal"> 820</span>
<span class="normal"> 821</span>
<span class="normal"> 822</span>
<span class="normal"> 823</span>
<span class="normal"> 824</span>
<span class="normal"> 825</span>
<span class="normal"> 826</span>
<span class="normal"> 827</span>
<span class="normal"> 828</span>
<span class="normal"> 829</span>
<span class="normal"> 830</span>
<span class="normal"> 831</span>
<span class="normal"> 832</span>
<span class="normal"> 833</span>
<span class="normal"> 834</span>
<span class="normal"> 835</span>
<span class="normal"> 836</span>
<span class="normal"> 837</span>
<span class="normal"> 838</span>
<span class="normal"> 839</span>
<span class="normal"> 840</span>
<span class="normal"> 841</span>
<span class="normal"> 842</span>
<span class="normal"> 843</span>
<span class="normal"> 844</span>
<span class="normal"> 845</span>
<span class="normal"> 846</span>
<span class="normal"> 847</span>
<span class="normal"> 848</span>
<span class="normal"> 849</span>
<span class="normal"> 850</span>
<span class="normal"> 851</span>
<span class="normal"> 852</span>
<span class="normal"> 853</span>
<span class="normal"> 854</span>
<span class="normal"> 855</span>
<span class="normal"> 856</span>
<span class="normal"> 857</span>
<span class="normal"> 858</span>
<span class="normal"> 859</span>
<span class="normal"> 860</span>
<span class="normal"> 861</span>
<span class="normal"> 862</span>
<span class="normal"> 863</span>
<span class="normal"> 864</span>
<span class="normal"> 865</span>
<span class="normal"> 866</span>
<span class="normal"> 867</span>
<span class="normal"> 868</span>
<span class="normal"> 869</span>
<span class="normal"> 870</span>
<span class="normal"> 871</span>
<span class="normal"> 872</span>
<span class="normal"> 873</span>
<span class="normal"> 874</span>
<span class="normal"> 875</span>
<span class="normal"> 876</span>
<span class="normal"> 877</span>
<span class="normal"> 878</span>
<span class="normal"> 879</span>
<span class="normal"> 880</span>
<span class="normal"> 881</span>
<span class="normal"> 882</span>
<span class="normal"> 883</span>
<span class="normal"> 884</span>
<span class="normal"> 885</span>
<span class="normal"> 886</span>
<span class="normal"> 887</span>
<span class="normal"> 888</span>
<span class="normal"> 889</span>
<span class="normal"> 890</span>
<span class="normal"> 891</span>
<span class="normal"> 892</span>
<span class="normal"> 893</span>
<span class="normal"> 894</span>
<span class="normal"> 895</span>
<span class="normal"> 896</span>
<span class="normal"> 897</span>
<span class="normal"> 898</span>
<span class="normal"> 899</span>
<span class="normal"> 900</span>
<span class="normal"> 901</span>
<span class="normal"> 902</span>
<span class="normal"> 903</span>
<span class="normal"> 904</span>
<span class="normal"> 905</span>
<span class="normal"> 906</span>
<span class="normal"> 907</span>
<span class="normal"> 908</span>
<span class="normal"> 909</span>
<span class="normal"> 910</span>
<span class="normal"> 911</span>
<span class="normal"> 912</span>
<span class="normal"> 913</span>
<span class="normal"> 914</span>
<span class="normal"> 915</span>
<span class="normal"> 916</span>
<span class="normal"> 917</span>
<span class="normal"> 918</span>
<span class="normal"> 919</span>
<span class="normal"> 920</span>
<span class="normal"> 921</span>
<span class="normal"> 922</span>
<span class="normal"> 923</span>
<span class="normal"> 924</span>
<span class="normal"> 925</span>
<span class="normal"> 926</span>
<span class="normal"> 927</span>
<span class="normal"> 928</span>
<span class="normal"> 929</span>
<span class="normal"> 930</span>
<span class="normal"> 931</span>
<span class="normal"> 932</span>
<span class="normal"> 933</span>
<span class="normal"> 934</span>
<span class="normal"> 935</span>
<span class="normal"> 936</span>
<span class="normal"> 937</span>
<span class="normal"> 938</span>
<span class="normal"> 939</span>
<span class="normal"> 940</span>
<span class="normal"> 941</span>
<span class="normal"> 942</span>
<span class="normal"> 943</span>
<span class="normal"> 944</span>
<span class="normal"> 945</span>
<span class="normal"> 946</span>
<span class="normal"> 947</span>
<span class="normal"> 948</span>
<span class="normal"> 949</span>
<span class="normal"> 950</span>
<span class="normal"> 951</span>
<span class="normal"> 952</span>
<span class="normal"> 953</span>
<span class="normal"> 954</span>
<span class="normal"> 955</span>
<span class="normal"> 956</span>
<span class="normal"> 957</span>
<span class="normal"> 958</span>
<span class="normal"> 959</span>
<span class="normal"> 960</span>
<span class="normal"> 961</span>
<span class="normal"> 962</span>
<span class="normal"> 963</span>
<span class="normal"> 964</span>
<span class="normal"> 965</span>
<span class="normal"> 966</span>
<span class="normal"> 967</span>
<span class="normal"> 968</span>
<span class="normal"> 969</span>
<span class="normal"> 970</span>
<span class="normal"> 971</span>
<span class="normal"> 972</span>
<span class="normal"> 973</span>
<span class="normal"> 974</span>
<span class="normal"> 975</span>
<span class="normal"> 976</span>
<span class="normal"> 977</span>
<span class="normal"> 978</span>
<span class="normal"> 979</span>
<span class="normal"> 980</span>
<span class="normal"> 981</span>
<span class="normal"> 982</span>
<span class="normal"> 983</span>
<span class="normal"> 984</span>
<span class="normal"> 985</span>
<span class="normal"> 986</span>
<span class="normal"> 987</span>
<span class="normal"> 988</span>
<span class="normal"> 989</span>
<span class="normal"> 990</span>
<span class="normal"> 991</span>
<span class="normal"> 992</span>
<span class="normal"> 993</span>
<span class="normal"> 994</span>
<span class="normal"> 995</span>
<span class="normal"> 996</span>
<span class="normal"> 997</span>
<span class="normal"> 998</span>
<span class="normal"> 999</span>
<span class="normal">1000</span>
<span class="normal">1001</span>
<span class="normal">1002</span>
<span class="normal">1003</span>
<span class="normal">1004</span>
<span class="normal">1005</span>
<span class="normal">1006</span>
<span class="normal">1007</span>
<span class="normal">1008</span>
<span class="normal">1009</span>
<span class="normal">1010</span>
<span class="normal">1011</span>
<span class="normal">1012</span>
<span class="normal">1013</span>
<span class="normal">1014</span>
<span class="normal">1015</span>
<span class="normal">1016</span>
<span class="normal">1017</span>
<span class="normal">1018</span>
<span class="normal">1019</span>
<span class="normal">1020</span>
<span class="normal">1021</span>
<span class="normal">1022</span>
<span class="normal">1023</span>
<span class="normal">1024</span>
<span class="normal">1025</span>
<span class="normal">1026</span>
<span class="normal">1027</span>
<span class="normal">1028</span>
<span class="normal">1029</span>
<span class="normal">1030</span>
<span class="normal">1031</span>
<span class="normal">1032</span>
<span class="normal">1033</span>
<span class="normal">1034</span>
<span class="normal">1035</span>
<span class="normal">1036</span>
<span class="normal">1037</span>
<span class="normal">1038</span>
<span class="normal">1039</span>
<span class="normal">1040</span>
<span class="normal">1041</span>
<span class="normal">1042</span>
<span class="normal">1043</span>
<span class="normal">1044</span>
<span class="normal">1045</span>
<span class="normal">1046</span>
<span class="normal">1047</span>
<span class="normal">1048</span>
<span class="normal">1049</span>
<span class="normal">1050</span>
<span class="normal">1051</span>
<span class="normal">1052</span>
<span class="normal">1053</span>
<span class="normal">1054</span>
<span class="normal">1055</span>
<span class="normal">1056</span>
<span class="normal">1057</span>
<span class="normal">1058</span>
<span class="normal">1059</span>
<span class="normal">1060</span>
<span class="normal">1061</span>
<span class="normal">1062</span>
<span class="normal">1063</span>
<span class="normal">1064</span>
<span class="normal">1065</span>
<span class="normal">1066</span>
<span class="normal">1067</span>
<span class="normal">1068</span>
<span class="normal">1069</span>
<span class="normal">1070</span>
<span class="normal">1071</span>
<span class="normal">1072</span>
<span class="normal">1073</span>
<span class="normal">1074</span>
<span class="normal">1075</span>
<span class="normal">1076</span>
<span class="normal">1077</span>
<span class="normal">1078</span>
<span class="normal">1079</span>
<span class="normal">1080</span>
<span class="normal">1081</span>
<span class="normal">1082</span>
<span class="normal">1083</span>
<span class="normal">1084</span>
<span class="normal">1085</span>
<span class="normal">1086</span>
<span class="normal">1087</span>
<span class="normal">1088</span>
<span class="normal">1089</span>
<span class="normal">1090</span>
<span class="normal">1091</span>
<span class="normal">1092</span>
<span class="normal">1093</span>
<span class="normal">1094</span>
<span class="normal">1095</span>
<span class="normal">1096</span>
<span class="normal">1097</span>
<span class="normal">1098</span>
<span class="normal">1099</span>
<span class="normal">1100</span>
<span class="normal">1101</span>
<span class="normal">1102</span>
<span class="normal">1103</span>
<span class="normal">1104</span>
<span class="normal">1105</span>
<span class="normal">1106</span>
<span class="normal">1107</span>
<span class="normal">1108</span>
<span class="normal">1109</span>
<span class="normal">1110</span>
<span class="normal">1111</span>
<span class="normal">1112</span>
<span class="normal">1113</span>
<span class="normal">1114</span>
<span class="normal">1115</span>
<span class="normal">1116</span>
<span class="normal">1117</span>
<span class="normal">1118</span>
<span class="normal">1119</span>
<span class="normal">1120</span>
<span class="normal">1121</span>
<span class="normal">1122</span>
<span class="normal">1123</span>
<span class="normal">1124</span>
<span class="normal">1125</span>
<span class="normal">1126</span>
<span class="normal">1127</span>
<span class="normal">1128</span>
<span class="normal">1129</span>
<span class="normal">1130</span>
<span class="normal">1131</span>
<span class="normal">1132</span>
<span class="normal">1133</span>
<span class="normal">1134</span>
<span class="normal">1135</span>
<span class="normal">1136</span>
<span class="normal">1137</span>
<span class="normal">1138</span>
<span class="normal">1139</span>
<span class="normal">1140</span>
<span class="normal">1141</span>
<span class="normal">1142</span>
<span class="normal">1143</span>
<span class="normal">1144</span>
<span class="normal">1145</span>
<span class="normal">1146</span>
<span class="normal">1147</span>
<span class="normal">1148</span>
<span class="normal">1149</span>
<span class="normal">1150</span>
<span class="normal">1151</span>
<span class="normal">1152</span>
<span class="normal">1153</span>
<span class="normal">1154</span>
<span class="normal">1155</span>
<span class="normal">1156</span>
<span class="normal">1157</span>
<span class="normal">1158</span>
<span class="normal">1159</span>
<span class="normal">1160</span>
<span class="normal">1161</span>
<span class="normal">1162</span>
<span class="normal">1163</span>
<span class="normal">1164</span>
<span class="normal">1165</span>
<span class="normal">1166</span>
<span class="normal">1167</span>
<span class="normal">1168</span>
<span class="normal">1169</span>
<span class="normal">1170</span>
<span class="normal">1171</span>
<span class="normal">1172</span>
<span class="normal">1173</span>
<span class="normal">1174</span>
<span class="normal">1175</span>
<span class="normal">1176</span>
<span class="normal">1177</span>
<span class="normal">1178</span>
<span class="normal">1179</span>
<span class="normal">1180</span>
<span class="normal">1181</span>
<span class="normal">1182</span>
<span class="normal">1183</span>
<span class="normal">1184</span>
<span class="normal">1185</span>
<span class="normal">1186</span>
<span class="normal">1187</span>
<span class="normal">1188</span>
<span class="normal">1189</span>
<span class="normal">1190</span>
<span class="normal">1191</span>
<span class="normal">1192</span>
<span class="normal">1193</span>
<span class="normal">1194</span>
<span class="normal">1195</span>
<span class="normal">1196</span>
<span class="normal">1197</span>
<span class="normal">1198</span>
<span class="normal">1199</span>
<span class="normal">1200</span>
<span class="normal">1201</span>
<span class="normal">1202</span>
<span class="normal">1203</span>
<span class="normal">1204</span>
<span class="normal">1205</span>
<span class="normal">1206</span>
<span class="normal">1207</span>
<span class="normal">1208</span>
<span class="normal">1209</span>
<span class="normal">1210</span>
<span class="normal">1211</span>
<span class="normal">1212</span>
<span class="normal">1213</span>
<span class="normal">1214</span>
<span class="normal">1215</span>
<span class="normal">1216</span>
<span class="normal">1217</span>
<span class="normal">1218</span>
<span class="normal">1219</span>
<span class="normal">1220</span>
<span class="normal">1221</span>
<span class="normal">1222</span>
<span class="normal">1223</span>
<span class="normal">1224</span>
<span class="normal">1225</span>
<span class="normal">1226</span>
<span class="normal">1227</span>
<span class="normal">1228</span>
<span class="normal">1229</span>
<span class="normal">1230</span>
<span class="normal">1231</span>
<span class="normal">1232</span>
<span class="normal">1233</span>
<span class="normal">1234</span>
<span class="normal">1235</span>
<span class="normal">1236</span>
<span class="normal">1237</span>
<span class="normal">1238</span>
<span class="normal">1239</span>
<span class="normal">1240</span>
<span class="normal">1241</span>
<span class="normal">1242</span>
<span class="normal">1243</span>
<span class="normal">1244</span>
<span class="normal">1245</span>
<span class="normal">1246</span>
<span class="normal">1247</span>
<span class="normal">1248</span>
<span class="normal">1249</span>
<span class="normal">1250</span>
<span class="normal">1251</span>
<span class="normal">1252</span>
<span class="normal">1253</span>
<span class="normal">1254</span>
<span class="normal">1255</span>
<span class="normal">1256</span>
<span class="normal">1257</span>
<span class="normal">1258</span>
<span class="normal">1259</span>
<span class="normal">1260</span>
<span class="normal">1261</span>
<span class="normal">1262</span>
<span class="normal">1263</span>
<span class="normal">1264</span>
<span class="normal">1265</span>
<span class="normal">1266</span>
<span class="normal">1267</span>
<span class="normal">1268</span>
<span class="normal">1269</span>
<span class="normal">1270</span>
<span class="normal">1271</span>
<span class="normal">1272</span>
<span class="normal">1273</span>
<span class="normal">1274</span>
<span class="normal">1275</span>
<span class="normal">1276</span>
<span class="normal">1277</span>
<span class="normal">1278</span>
<span class="normal">1279</span>
<span class="normal">1280</span>
<span class="normal">1281</span>
<span class="normal">1282</span>
<span class="normal">1283</span>
<span class="normal">1284</span>
<span class="normal">1285</span>
<span class="normal">1286</span>
<span class="normal">1287</span>
<span class="normal">1288</span>
<span class="normal">1289</span>
<span class="normal">1290</span>
<span class="normal">1291</span>
<span class="normal">1292</span>
<span class="normal">1293</span>
<span class="normal">1294</span>
<span class="normal">1295</span>
<span class="normal">1296</span>
<span class="normal">1297</span>
<span class="normal">1298</span>
<span class="normal">1299</span>
<span class="normal">1300</span>
<span class="normal">1301</span>
<span class="normal">1302</span>
<span class="normal">1303</span>
<span class="normal">1304</span>
<span class="normal">1305</span>
<span class="normal">1306</span>
<span class="normal">1307</span>
<span class="normal">1308</span>
<span class="normal">1309</span>
<span class="normal">1310</span>
<span class="normal">1311</span>
<span class="normal">1312</span>
<span class="normal">1313</span>
<span class="normal">1314</span>
<span class="normal">1315</span>
<span class="normal">1316</span>
<span class="normal">1317</span>
<span class="normal">1318</span>
<span class="normal">1319</span>
<span class="normal">1320</span>
<span class="normal">1321</span>
<span class="normal">1322</span>
<span class="normal">1323</span>
<span class="normal">1324</span>
<span class="normal">1325</span>
<span class="normal">1326</span>
<span class="normal">1327</span>
<span class="normal">1328</span>
<span class="normal">1329</span>
<span class="normal">1330</span>
<span class="normal">1331</span>
<span class="normal">1332</span>
<span class="normal">1333</span>
<span class="normal">1334</span>
<span class="normal">1335</span>
<span class="normal">1336</span>
<span class="normal">1337</span>
<span class="normal">1338</span>
<span class="normal">1339</span>
<span class="normal">1340</span>
<span class="normal">1341</span>
<span class="normal">1342</span>
<span class="normal">1343</span>
<span class="normal">1344</span>
<span class="normal">1345</span>
<span class="normal">1346</span>
<span class="normal">1347</span>
<span class="normal">1348</span>
<span class="normal">1349</span>
<span class="normal">1350</span>
<span class="normal">1351</span>
<span class="normal">1352</span>
<span class="normal">1353</span>
<span class="normal">1354</span>
<span class="normal">1355</span>
<span class="normal">1356</span>
<span class="normal">1357</span>
<span class="normal">1358</span>
<span class="normal">1359</span>
<span class="normal">1360</span>
<span class="normal">1361</span>
<span class="normal">1362</span>
<span class="normal">1363</span>
<span class="normal">1364</span>
<span class="normal">1365</span>
<span class="normal">1366</span>
<span class="normal">1367</span>
<span class="normal">1368</span>
<span class="normal">1369</span>
<span class="normal">1370</span>
<span class="normal">1371</span>
<span class="normal">1372</span>
<span class="normal">1373</span>
<span class="normal">1374</span>
<span class="normal">1375</span>
<span class="normal">1376</span>
<span class="normal">1377</span>
<span class="normal">1378</span>
<span class="normal">1379</span>
<span class="normal">1380</span>
<span class="normal">1381</span>
<span class="normal">1382</span>
<span class="normal">1383</span>
<span class="normal">1384</span>
<span class="normal">1385</span>
<span class="normal">1386</span>
<span class="normal">1387</span>
<span class="normal">1388</span>
<span class="normal">1389</span>
<span class="normal">1390</span>
<span class="normal">1391</span>
<span class="normal">1392</span>
<span class="normal">1393</span>
<span class="normal">1394</span>
<span class="normal">1395</span>
<span class="normal">1396</span>
<span class="normal">1397</span>
<span class="normal">1398</span>
<span class="normal">1399</span>
<span class="normal">1400</span>
<span class="normal">1401</span>
<span class="normal">1402</span>
<span class="normal">1403</span>
<span class="normal">1404</span>
<span class="normal">1405</span>
<span class="normal">1406</span>
<span class="normal">1407</span>
<span class="normal">1408</span>
<span class="normal">1409</span>
<span class="normal">1410</span>
<span class="normal">1411</span>
<span class="normal">1412</span>
<span class="normal">1413</span>
<span class="normal">1414</span>
<span class="normal">1415</span>
<span class="normal">1416</span>
<span class="normal">1417</span>
<span class="normal">1418</span>
<span class="normal">1419</span>
<span class="normal">1420</span>
<span class="normal">1421</span>
<span class="normal">1422</span>
<span class="normal">1423</span>
<span class="normal">1424</span>
<span class="normal">1425</span>
<span class="normal">1426</span>
<span class="normal">1427</span>
<span class="normal">1428</span>
<span class="normal">1429</span>
<span class="normal">1430</span>
<span class="normal">1431</span>
<span class="normal">1432</span>
<span class="normal">1433</span>
<span class="normal">1434</span>
<span class="normal">1435</span>
<span class="normal">1436</span>
<span class="normal">1437</span>
<span class="normal">1438</span>
<span class="normal">1439</span>
<span class="normal">1440</span>
<span class="normal">1441</span>
<span class="normal">1442</span>
<span class="normal">1443</span>
<span class="normal">1444</span>
<span class="normal">1445</span>
<span class="normal">1446</span>
<span class="normal">1447</span>
<span class="normal">1448</span>
<span class="normal">1449</span>
<span class="normal">1450</span>
<span class="normal">1451</span>
<span class="normal">1452</span>
<span class="normal">1453</span>
<span class="normal">1454</span>
<span class="normal">1455</span>
<span class="normal">1456</span>
<span class="normal">1457</span>
<span class="normal">1458</span>
<span class="normal">1459</span>
<span class="normal">1460</span>
<span class="normal">1461</span>
<span class="normal">1462</span>
<span class="normal">1463</span>
<span class="normal">1464</span>
<span class="normal">1465</span>
<span class="normal">1466</span>
<span class="normal">1467</span>
<span class="normal">1468</span>
<span class="normal">1469</span>
<span class="normal">1470</span>
<span class="normal">1471</span>
<span class="normal">1472</span>
<span class="normal">1473</span>
<span class="normal">1474</span>
<span class="normal">1475</span>
<span class="normal">1476</span>
<span class="normal">1477</span>
<span class="normal">1478</span>
<span class="normal">1479</span>
<span class="normal">1480</span>
<span class="normal">1481</span>
<span class="normal">1482</span>
<span class="normal">1483</span>
<span class="normal">1484</span>
<span class="normal">1485</span>
<span class="normal">1486</span>
<span class="normal">1487</span>
<span class="normal">1488</span>
<span class="normal">1489</span>
<span class="normal">1490</span>
<span class="normal">1491</span>
<span class="normal">1492</span>
<span class="normal">1493</span>
<span class="normal">1494</span>
<span class="normal">1495</span>
<span class="normal">1496</span>
<span class="normal">1497</span>
<span class="normal">1498</span>
<span class="normal">1499</span>
<span class="normal">1500</span>
<span class="normal">1501</span>
<span class="normal">1502</span>
<span class="normal">1503</span>
<span class="normal">1504</span>
<span class="normal">1505</span>
<span class="normal">1506</span>
<span class="normal">1507</span>
<span class="normal">1508</span>
<span class="normal">1509</span>
<span class="normal">1510</span>
<span class="normal">1511</span>
<span class="normal">1512</span>
<span class="normal">1513</span>
<span class="normal">1514</span>
<span class="normal">1515</span>
<span class="normal">1516</span>
<span class="normal">1517</span>
<span class="normal">1518</span>
<span class="normal">1519</span>
<span class="normal">1520</span>
<span class="normal">1521</span>
<span class="normal">1522</span>
<span class="normal">1523</span>
<span class="normal">1524</span>
<span class="normal">1525</span>
<span class="normal">1526</span>
<span class="normal">1527</span>
<span class="normal">1528</span>
<span class="normal">1529</span>
<span class="normal">1530</span>
<span class="normal">1531</span>
<span class="normal">1532</span>
<span class="normal">1533</span>
<span class="normal">1534</span>
<span class="normal">1535</span>
<span class="normal">1536</span>
<span class="normal">1537</span>
<span class="normal">1538</span>
<span class="normal">1539</span>
<span class="normal">1540</span>
<span class="normal">1541</span>
<span class="normal">1542</span>
<span class="normal">1543</span>
<span class="normal">1544</span>
<span class="normal">1545</span>
<span class="normal">1546</span>
<span class="normal">1547</span>
<span class="normal">1548</span>
<span class="normal">1549</span>
<span class="normal">1550</span>
<span class="normal">1551</span>
<span class="normal">1552</span>
<span class="normal">1553</span>
<span class="normal">1554</span>
<span class="normal">1555</span>
<span class="normal">1556</span>
<span class="normal">1557</span>
<span class="normal">1558</span>
<span class="normal">1559</span>
<span class="normal">1560</span>
<span class="normal">1561</span>
<span class="normal">1562</span>
<span class="normal">1563</span>
<span class="normal">1564</span>
<span class="normal">1565</span>
<span class="normal">1566</span>
<span class="normal">1567</span>
<span class="normal">1568</span>
<span class="normal">1569</span>
<span class="normal">1570</span>
<span class="normal">1571</span>
<span class="normal">1572</span>
<span class="normal">1573</span>
<span class="normal">1574</span>
<span class="normal">1575</span>
<span class="normal">1576</span>
<span class="normal">1577</span>
<span class="normal">1578</span>
<span class="normal">1579</span>
<span class="normal">1580</span>
<span class="normal">1581</span>
<span class="normal">1582</span>
<span class="normal">1583</span>
<span class="normal">1584</span>
<span class="normal">1585</span>
<span class="normal">1586</span>
<span class="normal">1587</span>
<span class="normal">1588</span>
<span class="normal">1589</span>
<span class="normal">1590</span>
<span class="normal">1591</span>
<span class="normal">1592</span>
<span class="normal">1593</span>
<span class="normal">1594</span>
<span class="normal">1595</span>
<span class="normal">1596</span>
<span class="normal">1597</span>
<span class="normal">1598</span>
<span class="normal">1599</span>
<span class="normal">1600</span>
<span class="normal">1601</span>
<span class="normal">1602</span>
<span class="normal">1603</span>
<span class="normal">1604</span>
<span class="normal">1605</span>
<span class="normal">1606</span>
<span class="normal">1607</span>
<span class="normal">1608</span>
<span class="normal">1609</span>
<span class="normal">1610</span>
<span class="normal">1611</span>
<span class="normal">1612</span>
<span class="normal">1613</span>
<span class="normal">1614</span>
<span class="normal">1615</span>
<span class="normal">1616</span>
<span class="normal">1617</span>
<span class="normal">1618</span>
<span class="normal">1619</span>
<span class="normal">1620</span>
<span class="normal">1621</span>
<span class="normal">1622</span>
<span class="normal">1623</span>
<span class="normal">1624</span>
<span class="normal">1625</span>
<span class="normal">1626</span>
<span class="normal">1627</span>
<span class="normal">1628</span>
<span class="normal">1629</span>
<span class="normal">1630</span>
<span class="normal">1631</span>
<span class="normal">1632</span>
<span class="normal">1633</span>
<span class="normal">1634</span>
<span class="normal">1635</span>
<span class="normal">1636</span>
<span class="normal">1637</span>
<span class="normal">1638</span>
<span class="normal">1639</span>
<span class="normal">1640</span>
<span class="normal">1641</span>
<span class="normal">1642</span>
<span class="normal">1643</span>
<span class="normal">1644</span>
<span class="normal">1645</span>
<span class="normal">1646</span>
<span class="normal">1647</span>
<span class="normal">1648</span>
<span class="normal">1649</span>
<span class="normal">1650</span>
<span class="normal">1651</span>
<span class="normal">1652</span>
<span class="normal">1653</span>
<span class="normal">1654</span>
<span class="normal">1655</span>
<span class="normal">1656</span>
<span class="normal">1657</span>
<span class="normal">1658</span>
<span class="normal">1659</span>
<span class="normal">1660</span>
<span class="normal">1661</span>
<span class="normal">1662</span>
<span class="normal">1663</span>
<span class="normal">1664</span>
<span class="normal">1665</span>
<span class="normal">1666</span>
<span class="normal">1667</span>
<span class="normal">1668</span>
<span class="normal">1669</span>
<span class="normal">1670</span>
<span class="normal">1671</span>
<span class="normal">1672</span>
<span class="normal">1673</span>
<span class="normal">1674</span>
<span class="normal">1675</span>
<span class="normal">1676</span>
<span class="normal">1677</span>
<span class="normal">1678</span>
<span class="normal">1679</span>
<span class="normal">1680</span>
<span class="normal">1681</span>
<span class="normal">1682</span>
<span class="normal">1683</span>
<span class="normal">1684</span>
<span class="normal">1685</span>
<span class="normal">1686</span>
<span class="normal">1687</span>
<span class="normal">1688</span>
<span class="normal">1689</span>
<span class="normal">1690</span>
<span class="normal">1691</span>
<span class="normal">1692</span>
<span class="normal">1693</span>
<span class="normal">1694</span>
<span class="normal">1695</span>
<span class="normal">1696</span>
<span class="normal">1697</span>
<span class="normal">1698</span>
<span class="normal">1699</span>
<span class="normal">1700</span>
<span class="normal">1701</span>
<span class="normal">1702</span>
<span class="normal">1703</span>
<span class="normal">1704</span>
<span class="normal">1705</span>
<span class="normal">1706</span>
<span class="normal">1707</span>
<span class="normal">1708</span>
<span class="normal">1709</span>
<span class="normal">1710</span>
<span class="normal">1711</span>
<span class="normal">1712</span>
<span class="normal">1713</span>
<span class="normal">1714</span>
<span class="normal">1715</span>
<span class="normal">1716</span>
<span class="normal">1717</span>
<span class="normal">1718</span>
<span class="normal">1719</span>
<span class="normal">1720</span>
<span class="normal">1721</span>
<span class="normal">1722</span>
<span class="normal">1723</span>
<span class="normal">1724</span>
<span class="normal">1725</span>
<span class="normal">1726</span>
<span class="normal">1727</span>
<span class="normal">1728</span>
<span class="normal">1729</span>
<span class="normal">1730</span>
<span class="normal">1731</span>
<span class="normal">1732</span>
<span class="normal">1733</span>
<span class="normal">1734</span>
<span class="normal">1735</span>
<span class="normal">1736</span>
<span class="normal">1737</span>
<span class="normal">1738</span>
<span class="normal">1739</span>
<span class="normal">1740</span>
<span class="normal">1741</span>
<span class="normal">1742</span>
<span class="normal">1743</span>
<span class="normal">1744</span>
<span class="normal">1745</span>
<span class="normal">1746</span>
<span class="normal">1747</span>
<span class="normal">1748</span>
<span class="normal">1749</span>
<span class="normal">1750</span>
<span class="normal">1751</span>
<span class="normal">1752</span>
<span class="normal">1753</span>
<span class="normal">1754</span>
<span class="normal">1755</span>
<span class="normal">1756</span>
<span class="normal">1757</span>
<span class="normal">1758</span>
<span class="normal">1759</span>
<span class="normal">1760</span>
<span class="normal">1761</span>
<span class="normal">1762</span>
<span class="normal">1763</span>
<span class="normal">1764</span>
<span class="normal">1765</span>
<span class="normal">1766</span>
<span class="normal">1767</span>
<span class="normal">1768</span>
<span class="normal">1769</span>
<span class="normal">1770</span>
<span class="normal">1771</span>
<span class="normal">1772</span>
<span class="normal">1773</span>
<span class="normal">1774</span>
<span class="normal">1775</span>
<span class="normal">1776</span>
<span class="normal">1777</span>
<span class="normal">1778</span>
<span class="normal">1779</span>
<span class="normal">1780</span>
<span class="normal">1781</span>
<span class="normal">1782</span>
<span class="normal">1783</span>
<span class="normal">1784</span>
<span class="normal">1785</span>
<span class="normal">1786</span>
<span class="normal">1787</span>
<span class="normal">1788</span>
<span class="normal">1789</span>
<span class="normal">1790</span>
<span class="normal">1791</span>
<span class="normal">1792</span>
<span class="normal">1793</span>
<span class="normal">1794</span>
<span class="normal">1795</span>
<span class="normal">1796</span>
<span class="normal">1797</span>
<span class="normal">1798</span>
<span class="normal">1799</span>
<span class="normal">1800</span>
<span class="normal">1801</span>
<span class="normal">1802</span>
<span class="normal">1803</span>
<span class="normal">1804</span>
<span class="normal">1805</span>
<span class="normal">1806</span>
<span class="normal">1807</span>
<span class="normal">1808</span>
<span class="normal">1809</span>
<span class="normal">1810</span>
<span class="normal">1811</span>
<span class="normal">1812</span>
<span class="normal">1813</span>
<span class="normal">1814</span>
<span class="normal">1815</span>
<span class="normal">1816</span>
<span class="normal">1817</span>
<span class="normal">1818</span>
<span class="normal">1819</span>
<span class="normal">1820</span>
<span class="normal">1821</span>
<span class="normal">1822</span>
<span class="normal">1823</span>
<span class="normal">1824</span>
<span class="normal">1825</span>
<span class="normal">1826</span>
<span class="normal">1827</span>
<span class="normal">1828</span>
<span class="normal">1829</span>
<span class="normal">1830</span>
<span class="normal">1831</span>
<span class="normal">1832</span>
<span class="normal">1833</span>
<span class="normal">1834</span>
<span class="normal">1835</span>
<span class="normal">1836</span>
<span class="normal">1837</span>
<span class="normal">1838</span>
<span class="normal">1839</span>
<span class="normal">1840</span>
<span class="normal">1841</span>
<span class="normal">1842</span>
<span class="normal">1843</span>
<span class="normal">1844</span>
<span class="normal">1845</span>
<span class="normal">1846</span>
<span class="normal">1847</span>
<span class="normal">1848</span>
<span class="normal">1849</span>
<span class="normal">1850</span>
<span class="normal">1851</span>
<span class="normal">1852</span>
<span class="normal">1853</span>
<span class="normal">1854</span>
<span class="normal">1855</span>
<span class="normal">1856</span>
<span class="normal">1857</span>
<span class="normal">1858</span>
<span class="normal">1859</span>
<span class="normal">1860</span>
<span class="normal">1861</span>
<span class="normal">1862</span>
<span class="normal">1863</span>
<span class="normal">1864</span>
<span class="normal">1865</span>
<span class="normal">1866</span>
<span class="normal">1867</span>
<span class="normal">1868</span>
<span class="normal">1869</span>
<span class="normal">1870</span>
<span class="normal">1871</span>
<span class="normal">1872</span>
<span class="normal">1873</span>
<span class="normal">1874</span>
<span class="normal">1875</span>
<span class="normal">1876</span>
<span class="normal">1877</span>
<span class="normal">1878</span>
<span class="normal">1879</span>
<span class="normal">1880</span>
<span class="normal">1881</span>
<span class="normal">1882</span>
<span class="normal">1883</span>
<span class="normal">1884</span>
<span class="normal">1885</span>
<span class="normal">1886</span>
<span class="normal">1887</span>
<span class="normal">1888</span>
<span class="normal">1889</span>
<span class="normal">1890</span>
<span class="normal">1891</span>
<span class="normal">1892</span>
<span class="normal">1893</span>
<span class="normal">1894</span>
<span class="normal">1895</span>
<span class="normal">1896</span>
<span class="normal">1897</span>
<span class="normal">1898</span>
<span class="normal">1899</span>
<span class="normal">1900</span>
<span class="normal">1901</span>
<span class="normal">1902</span>
<span class="normal">1903</span>
<span class="normal">1904</span>
<span class="normal">1905</span>
<span class="normal">1906</span>
<span class="normal">1907</span>
<span class="normal">1908</span>
<span class="normal">1909</span>
<span class="normal">1910</span>
<span class="normal">1911</span>
<span class="normal">1912</span>
<span class="normal">1913</span>
<span class="normal">1914</span>
<span class="normal">1915</span>
<span class="normal">1916</span>
<span class="normal">1917</span>
<span class="normal">1918</span>
<span class="normal">1919</span>
<span class="normal">1920</span>
<span class="normal">1921</span>
<span class="normal">1922</span>
<span class="normal">1923</span>
<span class="normal">1924</span>
<span class="normal">1925</span>
<span class="normal">1926</span>
<span class="normal">1927</span>
<span class="normal">1928</span>
<span class="normal">1929</span>
<span class="normal">1930</span>
<span class="normal">1931</span>
<span class="normal">1932</span>
<span class="normal">1933</span>
<span class="normal">1934</span>
<span class="normal">1935</span>
<span class="normal">1936</span>
<span class="normal">1937</span>
<span class="normal">1938</span>
<span class="normal">1939</span>
<span class="normal">1940</span>
<span class="normal">1941</span>
<span class="normal">1942</span>
<span class="normal">1943</span>
<span class="normal">1944</span>
<span class="normal">1945</span>
<span class="normal">1946</span>
<span class="normal">1947</span>
<span class="normal">1948</span>
<span class="normal">1949</span>
<span class="normal">1950</span>
<span class="normal">1951</span>
<span class="normal">1952</span>
<span class="normal">1953</span>
<span class="normal">1954</span>
<span class="normal">1955</span>
<span class="normal">1956</span>
<span class="normal">1957</span>
<span class="normal">1958</span>
<span class="normal">1959</span>
<span class="normal">1960</span>
<span class="normal">1961</span>
<span class="normal">1962</span>
<span class="normal">1963</span>
<span class="normal">1964</span>
<span class="normal">1965</span>
<span class="normal">1966</span>
<span class="normal">1967</span>
<span class="normal">1968</span>
<span class="normal">1969</span>
<span class="normal">1970</span>
<span class="normal">1971</span>
<span class="normal">1972</span>
<span class="normal">1973</span>
<span class="normal">1974</span>
<span class="normal">1975</span>
<span class="normal">1976</span>
<span class="normal">1977</span>
<span class="normal">1978</span>
<span class="normal">1979</span>
<span class="normal">1980</span>
<span class="normal">1981</span>
<span class="normal">1982</span>
<span class="normal">1983</span>
<span class="normal">1984</span>
<span class="normal">1985</span>
<span class="normal">1986</span>
<span class="normal">1987</span>
<span class="normal">1988</span>
<span class="normal">1989</span>
<span class="normal">1990</span>
<span class="normal">1991</span>
<span class="normal">1992</span>
<span class="normal">1993</span>
<span class="normal">1994</span>
<span class="normal">1995</span>
<span class="normal">1996</span>
<span class="normal">1997</span>
<span class="normal">1998</span>
<span class="normal">1999</span>
<span class="normal">2000</span>
<span class="normal">2001</span>
<span class="normal">2002</span>
<span class="normal">2003</span>
<span class="normal">2004</span>
<span class="normal">2005</span>
<span class="normal">2006</span>
<span class="normal">2007</span>
<span class="normal">2008</span>
<span class="normal">2009</span>
<span class="normal">2010</span>
<span class="normal">2011</span>
<span class="normal">2012</span>
<span class="normal">2013</span>
<span class="normal">2014</span>
<span class="normal">2015</span>
<span class="normal">2016</span>
<span class="normal">2017</span>
<span class="normal">2018</span>
<span class="normal">2019</span>
<span class="normal">2020</span>
<span class="normal">2021</span>
<span class="normal">2022</span>
<span class="normal">2023</span>
<span class="normal">2024</span>
<span class="normal">2025</span>
<span class="normal">2026</span>
<span class="normal">2027</span>
<span class="normal">2028</span>
<span class="normal">2029</span>
<span class="normal">2030</span>
<span class="normal">2031</span>
<span class="normal">2032</span>
<span class="normal">2033</span>
<span class="normal">2034</span>
<span class="normal">2035</span>
<span class="normal">2036</span>
<span class="normal">2037</span>
<span class="normal">2038</span>
<span class="normal">2039</span>
<span class="normal">2040</span>
<span class="normal">2041</span>
<span class="normal">2042</span>
<span class="normal">2043</span>
<span class="normal">2044</span>
<span class="normal">2045</span>
<span class="normal">2046</span>
<span class="normal">2047</span>
<span class="normal">2048</span>
<span class="normal">2049</span>
<span class="normal">2050</span>
<span class="normal">2051</span>
<span class="normal">2052</span>
<span class="normal">2053</span>
<span class="normal">2054</span>
<span class="normal">2055</span>
<span class="normal">2056</span>
<span class="normal">2057</span>
<span class="normal">2058</span>
<span class="normal">2059</span>
<span class="normal">2060</span>
<span class="normal">2061</span>
<span class="normal">2062</span>
<span class="normal">2063</span>
<span class="normal">2064</span>
<span class="normal">2065</span>
<span class="normal">2066</span>
<span class="normal">2067</span>
<span class="normal">2068</span>
<span class="normal">2069</span>
<span class="normal">2070</span>
<span class="normal">2071</span>
<span class="normal">2072</span>
<span class="normal">2073</span>
<span class="normal">2074</span>
<span class="normal">2075</span>
<span class="normal">2076</span>
<span class="normal">2077</span>
<span class="normal">2078</span>
<span class="normal">2079</span>
<span class="normal">2080</span>
<span class="normal">2081</span>
<span class="normal">2082</span>
<span class="normal">2083</span>
<span class="normal">2084</span>
<span class="normal">2085</span>
<span class="normal">2086</span>
<span class="normal">2087</span>
<span class="normal">2088</span>
<span class="normal">2089</span>
<span class="normal">2090</span>
<span class="normal">2091</span>
<span class="normal">2092</span>
<span class="normal">2093</span>
<span class="normal">2094</span>
<span class="normal">2095</span>
<span class="normal">2096</span>
<span class="normal">2097</span>
<span class="normal">2098</span>
<span class="normal">2099</span>
<span class="normal">2100</span>
<span class="normal">2101</span>
<span class="normal">2102</span>
<span class="normal">2103</span>
<span class="normal">2104</span>
<span class="normal">2105</span>
<span class="normal">2106</span>
<span class="normal">2107</span>
<span class="normal">2108</span>
<span class="normal">2109</span>
<span class="normal">2110</span>
<span class="normal">2111</span>
<span class="normal">2112</span>
<span class="normal">2113</span>
<span class="normal">2114</span>
<span class="normal">2115</span>
<span class="normal">2116</span>
<span class="normal">2117</span>
<span class="normal">2118</span>
<span class="normal">2119</span>
<span class="normal">2120</span>
<span class="normal">2121</span>
<span class="normal">2122</span>
<span class="normal">2123</span>
<span class="normal">2124</span>
<span class="normal">2125</span>
<span class="normal">2126</span>
<span class="normal">2127</span>
<span class="normal">2128</span>
<span class="normal">2129</span>
<span class="normal">2130</span>
<span class="normal">2131</span>
<span class="normal">2132</span>
<span class="normal">2133</span>
<span class="normal">2134</span>
<span class="normal">2135</span>
<span class="normal">2136</span>
<span class="normal">2137</span>
<span class="normal">2138</span>
<span class="normal">2139</span>
<span class="normal">2140</span>
<span class="normal">2141</span>
<span class="normal">2142</span>
<span class="normal">2143</span>
<span class="normal">2144</span>
<span class="normal">2145</span>
<span class="normal">2146</span>
<span class="normal">2147</span>
<span class="normal">2148</span>
<span class="normal">2149</span>
<span class="normal">2150</span>
<span class="normal">2151</span>
<span class="normal">2152</span>
<span class="normal">2153</span>
<span class="normal">2154</span>
<span class="normal">2155</span>
<span class="normal">2156</span>
<span class="normal">2157</span>
<span class="normal">2158</span>
<span class="normal">2159</span>
<span class="normal">2160</span>
<span class="normal">2161</span>
<span class="normal">2162</span>
<span class="normal">2163</span>
<span class="normal">2164</span>
<span class="normal">2165</span>
<span class="normal">2166</span>
<span class="normal">2167</span>
<span class="normal">2168</span>
<span class="normal">2169</span>
<span class="normal">2170</span>
<span class="normal">2171</span>
<span class="normal">2172</span>
<span class="normal">2173</span>
<span class="normal">2174</span>
<span class="normal">2175</span>
<span class="normal">2176</span>
<span class="normal">2177</span>
<span class="normal">2178</span>
<span class="normal">2179</span>
<span class="normal">2180</span>
<span class="normal">2181</span>
<span class="normal">2182</span>
<span class="normal">2183</span>
<span class="normal">2184</span>
<span class="normal">2185</span>
<span class="normal">2186</span>
<span class="normal">2187</span>
<span class="normal">2188</span>
<span class="normal">2189</span>
<span class="normal">2190</span>
<span class="normal">2191</span>
<span class="normal">2192</span>
<span class="normal">2193</span>
<span class="normal">2194</span>
<span class="normal">2195</span>
<span class="normal">2196</span>
<span class="normal">2197</span>
<span class="normal">2198</span>
<span class="normal">2199</span>
<span class="normal">2200</span>
<span class="normal">2201</span>
<span class="normal">2202</span>
<span class="normal">2203</span>
<span class="normal">2204</span>
<span class="normal">2205</span>
<span class="normal">2206</span>
<span class="normal">2207</span>
<span class="normal">2208</span>
<span class="normal">2209</span>
<span class="normal">2210</span>
<span class="normal">2211</span>
<span class="normal">2212</span>
<span class="normal">2213</span>
<span class="normal">2214</span>
<span class="normal">2215</span>
<span class="normal">2216</span>
<span class="normal">2217</span>
<span class="normal">2218</span>
<span class="normal">2219</span>
<span class="normal">2220</span>
<span class="normal">2221</span>
<span class="normal">2222</span>
<span class="normal">2223</span>
<span class="normal">2224</span>
<span class="normal">2225</span>
<span class="normal">2226</span>
<span class="normal">2227</span>
<span class="normal">2228</span>
<span class="normal">2229</span>
<span class="normal">2230</span>
<span class="normal">2231</span>
<span class="normal">2232</span>
<span class="normal">2233</span>
<span class="normal">2234</span>
<span class="normal">2235</span>
<span class="normal">2236</span>
<span class="normal">2237</span>
<span class="normal">2238</span>
<span class="normal">2239</span>
<span class="normal">2240</span>
<span class="normal">2241</span>
<span class="normal">2242</span>
<span class="normal">2243</span>
<span class="normal">2244</span>
<span class="normal">2245</span>
<span class="normal">2246</span>
<span class="normal">2247</span>
<span class="normal">2248</span>
<span class="normal">2249</span>
<span class="normal">2250</span>
<span class="normal">2251</span>
<span class="normal">2252</span>
<span class="normal">2253</span>
<span class="normal">2254</span>
<span class="normal">2255</span>
<span class="normal">2256</span>
<span class="normal">2257</span>
<span class="normal">2258</span>
<span class="normal">2259</span>
<span class="normal">2260</span>
<span class="normal">2261</span>
<span class="normal">2262</span>
<span class="normal">2263</span>
<span class="normal">2264</span>
<span class="normal">2265</span>
<span class="normal">2266</span>
<span class="normal">2267</span>
<span class="normal">2268</span>
<span class="normal">2269</span>
<span class="normal">2270</span>
<span class="normal">2271</span>
<span class="normal">2272</span>
<span class="normal">2273</span>
<span class="normal">2274</span>
<span class="normal">2275</span>
<span class="normal">2276</span>
<span class="normal">2277</span>
<span class="normal">2278</span>
<span class="normal">2279</span>
<span class="normal">2280</span>
<span class="normal">2281</span>
<span class="normal">2282</span>
<span class="normal">2283</span>
<span class="normal">2284</span>
<span class="normal">2285</span>
<span class="normal">2286</span>
<span class="normal">2287</span>
<span class="normal">2288</span>
<span class="normal">2289</span>
<span class="normal">2290</span>
<span class="normal">2291</span>
<span class="normal">2292</span>
<span class="normal">2293</span>
<span class="normal">2294</span>
<span class="normal">2295</span>
<span class="normal">2296</span>
<span class="normal">2297</span>
<span class="normal">2298</span>
<span class="normal">2299</span>
<span class="normal">2300</span>
<span class="normal">2301</span>
<span class="normal">2302</span>
<span class="normal">2303</span>
<span class="normal">2304</span>
<span class="normal">2305</span>
<span class="normal">2306</span>
<span class="normal">2307</span>
<span class="normal">2308</span>
<span class="normal">2309</span>
<span class="normal">2310</span>
<span class="normal">2311</span>
<span class="normal">2312</span>
<span class="normal">2313</span>
<span class="normal">2314</span>
<span class="normal">2315</span>
<span class="normal">2316</span>
<span class="normal">2317</span>
<span class="normal">2318</span>
<span class="normal">2319</span>
<span class="normal">2320</span>
<span class="normal">2321</span>
<span class="normal">2322</span>
<span class="normal">2323</span>
<span class="normal">2324</span>
<span class="normal">2325</span>
<span class="normal">2326</span>
<span class="normal">2327</span>
<span class="normal">2328</span>
<span class="normal">2329</span>
<span class="normal">2330</span>
<span class="normal">2331</span>
<span class="normal">2332</span>
<span class="normal">2333</span>
<span class="normal">2334</span>
<span class="normal">2335</span>
<span class="normal">2336</span>
<span class="normal">2337</span>
<span class="normal">2338</span>
<span class="normal">2339</span>
<span class="normal">2340</span>
<span class="normal">2341</span>
<span class="normal">2342</span>
<span class="normal">2343</span>
<span class="normal">2344</span>
<span class="normal">2345</span>
<span class="normal">2346</span>
<span class="normal">2347</span>
<span class="normal">2348</span>
<span class="normal">2349</span>
<span class="normal">2350</span>
<span class="normal">2351</span>
<span class="normal">2352</span>
<span class="normal">2353</span>
<span class="normal">2354</span>
<span class="normal">2355</span>
<span class="normal">2356</span>
<span class="normal">2357</span>
<span class="normal">2358</span>
<span class="normal">2359</span>
<span class="normal">2360</span>
<span class="normal">2361</span>
<span class="normal">2362</span>
<span class="normal">2363</span>
<span class="normal">2364</span>
<span class="normal">2365</span>
<span class="normal">2366</span>
<span class="normal">2367</span>
<span class="normal">2368</span>
<span class="normal">2369</span>
<span class="normal">2370</span>
<span class="normal">2371</span>
<span class="normal">2372</span>
<span class="normal">2373</span>
<span class="normal">2374</span>
<span class="normal">2375</span>
<span class="normal">2376</span>
<span class="normal">2377</span>
<span class="normal">2378</span>
<span class="normal">2379</span>
<span class="normal">2380</span>
<span class="normal">2381</span>
<span class="normal">2382</span>
<span class="normal">2383</span>
<span class="normal">2384</span>
<span class="normal">2385</span>
<span class="normal">2386</span>
<span class="normal">2387</span>
<span class="normal">2388</span>
<span class="normal">2389</span>
<span class="normal">2390</span>
<span class="normal">2391</span>
<span class="normal">2392</span>
<span class="normal">2393</span>
<span class="normal">2394</span>
<span class="normal">2395</span>
<span class="normal">2396</span>
<span class="normal">2397</span>
<span class="normal">2398</span>
<span class="normal">2399</span>
<span class="normal">2400</span>
<span class="normal">2401</span>
<span class="normal">2402</span>
<span class="normal">2403</span>
<span class="normal">2404</span>
<span class="normal">2405</span>
<span class="normal">2406</span>
<span class="normal">2407</span>
<span class="normal">2408</span>
<span class="normal">2409</span>
<span class="normal">2410</span>
<span class="normal">2411</span>
<span class="normal">2412</span>
<span class="normal">2413</span>
<span class="normal">2414</span>
<span class="normal">2415</span>
<span class="normal">2416</span>
<span class="normal">2417</span>
<span class="normal">2418</span>
<span class="normal">2419</span>
<span class="normal">2420</span>
<span class="normal">2421</span>
<span class="normal">2422</span>
<span class="normal">2423</span>
<span class="normal">2424</span>
<span class="normal">2425</span>
<span class="normal">2426</span>
<span class="normal">2427</span>
<span class="normal">2428</span>
<span class="normal">2429</span>
<span class="normal">2430</span>
<span class="normal">2431</span>
<span class="normal">2432</span>
<span class="normal">2433</span>
<span class="normal">2434</span>
<span class="normal">2435</span>
<span class="normal">2436</span></pre></div></td><td class="code"><div><pre><div id="l1" class="code_block"><span class="k">\chapter</span><span class="nb">{</span>Library Utilities<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>library<span class="nb">_</span>utilities<span class="nb">}</span>
</div><div id="l2" class="code_block"><span class="c">%====================================================</span>
</div><div id="l3" class="code_block">
</div><div id="l4" class="code_block">In this chapter we introduce some useful predicates that are supplied
</div><div id="l5" class="code_block">with the system. These predicates are available only when imported
</div><div id="l6" class="code_block">them from (or explicitly consult) the corresponding modules.
</div><div id="l7" class="code_block">
</div><div id="l8" class="code_block">
</div><div id="l9" class="code_block"><span class="k">\section</span><span class="nb">{</span>List Processing<span class="nb">}</span>
</div><div id="l10" class="code_block"><span class="c">%========================</span>
</div><div id="l11" class="code_block">The XSB library contains various list utilities, some of which 
</div><div id="l12" class="code_block">are listed below.  These predicates should be explicitly imported from
</div><div id="l13" class="code_block">the module specified after the skeletal specification of each predicate.
</div><div id="l14" class="code_block">There are a lot more useful list processing predicates in various modules
</div><div id="l15" class="code_block">of the XSB system, and the interested user can find them by 
</div><div id="l16" class="code_block">looking at the sources.
</div><div id="l17" class="code_block">
</div><div id="l18" class="code_block"><span class="k">\begin</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l19" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>append(?List1, ?List2, ?List3)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> append/3<span class="nb">}}</span>
</div><div id="l20" class="code_block"><span class="c">%\predindex{append/3~(L)}</span>
</div><div id="l21" class="code_block">    Succeeds if list <span class="nb">{</span><span class="k">\tt</span> List3<span class="nb">}</span> is the concatenation of lists 
</div><div id="l22" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> List1<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> List2<span class="nb">}</span>.
</div><div id="l23" class="code_block">
</div><div id="l24" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>member(?Element, ?List)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> member/2<span class="nb">}}</span>
</div><div id="l25" class="code_block"><span class="c">%\predindex{member/2~(L)}</span>
</div><div id="l26" class="code_block">    Checks whether <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span> unifies with any element of list 
</div><div id="l27" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span>, succeeding more than once if there are multiple 
</div><div id="l28" class="code_block">    such elements.
</div><div id="l29" class="code_block">
</div><div id="l30" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>memberchk(?Element, ?List)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> memberchk/2<span class="nb">}}</span>
</div><div id="l31" class="code_block"><span class="c">%\predindex{memberchk/2~(L)}</span>
</div><div id="l32" class="code_block">    Similar to <span class="nb">{</span><span class="k">\tt</span> member<span class="nb">}</span>/2, except that <span class="nb">{</span><span class="k">\tt</span> memberchk<span class="nb">}</span>/2 is
</div><div id="l33" class="code_block">    deterministic, i.e.<span class="k">\</span> does not succeed more than once for any call.
</div><div id="l34" class="code_block">
</div><div id="l35" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>ith(?Index, ?List, ?Element)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> ith/3<span class="nb">}}</span>
</div><div id="l36" class="code_block"><span class="c">%\predindex{ith/3~(L)}</span>
</div><div id="l37" class="code_block">    Succeeds if the <span class="s">$</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Index^{th}}</span><span class="s">$</span> element of the list <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span> 
</div><div id="l38" class="code_block">    unifies with <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span>.  Fails if <span class="nb">{</span><span class="k">\tt</span> Index<span class="nb">}</span> is not a positive
</div><div id="l39" class="code_block">    integer or greater than the length of <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span>.
</div><div id="l40" class="code_block">    Either <span class="nb">{</span><span class="k">\tt</span> Index<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span>, or <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span>, 
</div><div id="l41" class="code_block">    should be instantiated (but not necessarily ground) at the time of 
</div><div id="l42" class="code_block">    the call.
</div><div id="l43" class="code_block">
</div><div id="l44" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>log<span class="k">\_ith</span>(?Index, ?Tree, ?Element)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> log<span class="k">\_ith</span>/3<span class="nb">}}</span>
</div><div id="l45" class="code_block"><span class="c">%\predindex{log\_ith/3~(L)}</span>
</div><div id="l46" class="code_block">    Succeeds if the <span class="s">$</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Index^{th}}</span><span class="s">$</span> element of the Tree <span class="nb">{</span><span class="k">\tt</span> Tree<span class="nb">}</span>
</div><div id="l47" class="code_block">    unifies with <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span>.  Fails if <span class="nb">{</span><span class="k">\tt</span> Index<span class="nb">}</span> is not a
</div><div id="l48" class="code_block">    positive integer or greater than the number of elements that can
</div><div id="l49" class="code_block">    be in <span class="nb">{</span><span class="k">\tt</span> Tree<span class="nb">}</span>.  Either <span class="nb">{</span><span class="k">\tt</span> Index<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> Tree<span class="nb">}</span>, or <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l50" class="code_block">    Tree<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span>, should be instantiated (but not
</div><div id="l51" class="code_block">    necessarily ground) at the time of the call.  Tree is a list of
</div><div id="l52" class="code_block">    full binary trees, the first being of depth 0, and each one being
</div><div id="l53" class="code_block">    of depth one greater than its predecessor.  So <span class="nb">{</span><span class="k">\tt</span> log<span class="k">\_ith</span>/3<span class="nb">}</span> is
</div><div id="l54" class="code_block">    very similar to <span class="nb">{</span><span class="k">\tt</span> ith/3<span class="nb">}</span> except it uses a tree instead of a
</div><div id="l55" class="code_block">    list to obtain log-time access to its elements.
</div><div id="l56" class="code_block">
</div><div id="l57" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>log<span class="k">\_ith\_bound</span>(?Index, ?Tree, ?Element)<span class="nb">}{</span>basics<span class="nb">}</span>
</div><div id="l58" class="code_block">        <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> log<span class="k">\_ith\_bound</span>/3<span class="nb">}}</span>
</div><div id="l59" class="code_block"><span class="c">%\predindex{log\_ith\_bound/3~(L)}</span>
</div><div id="l60" class="code_block">    is like <span class="nb">{</span><span class="k">\tt</span> log<span class="k">\_ith</span>/3<span class="nb">}</span>, but only if the <span class="s">$</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Index^{th}}</span><span class="s">$</span> element
</div><div id="l61" class="code_block">    of <span class="nb">{</span><span class="k">\tt</span> Tree<span class="nb">}</span> is nonvariable and equal to Element.  This predicate
</div><div id="l62" class="code_block">    can be used in both directions, and is most useful with Index
</div><div id="l63" class="code_block">    unbound, since it will then bind <span class="nb">{</span><span class="k">\tt</span> Index<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span> for
</div><div id="l64" class="code_block">    each nonvariable element in <span class="nb">{</span><span class="k">\tt</span> Tree<span class="nb">}</span> (in time proportional to
</div><div id="l65" class="code_block">    <span class="s">$</span><span class="nb">N</span><span class="o">*</span><span class="nb">logN</span><span class="s">$</span>, for <span class="s">$</span><span class="nb">N</span><span class="s">$</span> the number of nonvariable entries in <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l66" class="code_block">    Tree<span class="nb">}</span>.)
</div><div id="l67" class="code_block">
</div><div id="l68" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>length(?List, ?Length)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> length/2<span class="nb">}}</span>
</div><div id="l69" class="code_block"><span class="c">%\predindex{length/2~(L)}</span>
</div><div id="l70" class="code_block">    Succeeds if the length of the list <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span> is <span class="nb">{</span><span class="k">\tt</span> Length<span class="nb">}</span>.
</div><div id="l71" class="code_block">    This predicate is deterministic if <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span> is instantiated 
</div><div id="l72" class="code_block">    to a list of definite length, but is nondeterministic if 
</div><div id="l73" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span> is a variable or has a variable tail.  If <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span>
</div><div id="l74" class="code_block">    is uninstantiated, it is unified with a list of length <span class="nb">{</span><span class="k">\tt</span> Length<span class="nb">}</span>
</div><div id="l75" class="code_block">    that contains variables.
</div><div id="l76" class="code_block">
</div><div id="l77" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>same<span class="k">\_length</span>(?List1, ?List2)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> same<span class="k">\_length</span>/2<span class="nb">}}</span>
</div><div id="l78" class="code_block"><span class="c">%\predindex{same\_length/2~(L)}</span>
</div><div id="l79" class="code_block">    Succeeds if list <span class="nb">{</span><span class="k">\tt</span> List1<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> List2<span class="nb">}</span> are both lists of
</div><div id="l80" class="code_block">    the same number of elements.  No relation between the types or
</div><div id="l81" class="code_block">    values of their elements is implied.  This predicate may be used
</div><div id="l82" class="code_block">    to generate either list (containing variables as elements) given
</div><div id="l83" class="code_block">    the other, or to generate two lists of the same length, in which
</div><div id="l84" class="code_block">    case the arguments will be bound to lists of length <span class="s">$</span><span class="m">0</span><span class="nb">,</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="nv">\ldots</span><span class="s">$</span>.
</div><div id="l85" class="code_block">
</div><div id="l86" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>select(?Element, ?L1, ?L2)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> select/3<span class="nb">}}</span>
</div><div id="l87" class="code_block"><span class="c">%\predindex{select/3~(L)}</span>
</div><div id="l88" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> List2<span class="nb">}</span> derives from <span class="nb">{</span><span class="k">\tt</span> List1<span class="nb">}</span> by selecting (removing) an 
</div><div id="l89" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span> non-deterministically.
</div><div id="l90" class="code_block">
</div><div id="l91" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>reverse(+List, ?ReversedList)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> reverse/2<span class="nb">}}</span>
</div><div id="l92" class="code_block"><span class="c">%\predindex{reverse/2~(L)}</span>
</div><div id="l93" class="code_block">    Succeeds if <span class="nb">{</span><span class="k">\tt</span> ReversedList<span class="nb">}</span> is the reverse of list <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span>.
</div><div id="l94" class="code_block">    If <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span> is not a proper list, <span class="nb">{</span><span class="k">\tt</span> reverse/2<span class="nb">}</span> can succeed
</div><div id="l95" class="code_block">    arbitrarily many times.  It works only one way.
</div><div id="l96" class="code_block">
</div><div id="l97" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>perm(+List, ?Perm)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> perm/2<span class="nb">}}</span>
</div><div id="l98" class="code_block"><span class="c">%\predindex{perm/2~(L)}</span>
</div><div id="l99" class="code_block">    Succeeds when <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> Perm<span class="nb">}</span> are permutations of each
</div><div id="l100" class="code_block">    other.  The main use of <span class="nb">{</span><span class="k">\tt</span> perm/2<span class="nb">}</span> is to generate permutations
</div><div id="l101" class="code_block">    of a given list.  <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span> must be a proper list.
</div><div id="l102" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> Perm<span class="nb">}</span> may be partly instantiated.
</div><div id="l103" class="code_block">
</div><div id="l104" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>subseq(?Sequence, ?SubSequence, ?Complement)<span class="nb">}{</span>basics<span class="nb">}</span>
</div><div id="l105" class="code_block"><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> subseq/3<span class="nb">}}</span>
</div><div id="l106" class="code_block"><span class="c">%\predindex{subseq/3(L)}</span>
</div><div id="l107" class="code_block">    Succeeds when <span class="nb">{</span><span class="k">\tt</span> SubSequence<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> Complement<span class="nb">}</span> are both
</div><div id="l108" class="code_block">    subsequences of the list <span class="nb">{</span><span class="k">\tt</span> Sequence<span class="nb">}</span> (the order of corresponding
</div><div id="l109" class="code_block">    elements being preserved) and every element of <span class="nb">{</span><span class="k">\tt</span> Sequence<span class="nb">}</span> which
</div><div id="l110" class="code_block">    is not in <span class="nb">{</span><span class="k">\tt</span> SubSequence<span class="nb">}</span> is in the <span class="nb">{</span><span class="k">\tt</span> Complement<span class="nb">}</span> and vice
</div><div id="l111" class="code_block">    versa.  That is,
</div><div id="l112" class="code_block">    <span class="sb">\[</span><span class="nb"> length</span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Sequence}</span><span class="o">)</span><span class="nb"> </span><span class="o">=</span>
</div><div id="l113" class="code_block"><span class="nb">                length</span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> SubSequence}</span><span class="o">)+</span><span class="nb">length</span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Complement}</span><span class="o">)</span><span class="nb"> </span><span class="s">\]</span>
</div><div id="l114" class="code_block">    for example, <span class="nb">{</span><span class="k">\tt</span> subseq([1,2,3,4], [1,3], [2,4]).<span class="nb">}</span>
</div><div id="l115" class="code_block">    The main use of <span class="nb">{</span><span class="k">\tt</span> subseq/3<span class="nb">}</span> is to generate subsets and their
</div><div id="l116" class="code_block">    complements together, but can also be used to interleave two lists
</div><div id="l117" class="code_block">    in all possible ways.
</div><div id="l118" class="code_block">
</div><div id="l119" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>merge(+List1, +List2, ?List3)<span class="nb">}{</span>listutil<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> merge/3<span class="nb">}}</span>
</div><div id="l120" class="code_block"><span class="c">%\predindex{merge/3~(L)}</span>
</div><div id="l121" class="code_block">    Succeeds if <span class="nb">{</span><span class="k">\tt</span> List3<span class="nb">}</span> is the list resulting from ``merging&#39;&#39; lists 
</div><div id="l122" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> List1<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> List2<span class="nb">}</span>,
</div><div id="l123" class="code_block">    i.e.<span class="k">\</span> the elements of <span class="nb">{</span><span class="k">\tt</span> List1<span class="nb">}</span> together with any element of 
</div><div id="l124" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> List2<span class="nb">}</span> not occurring in <span class="nb">{</span><span class="k">\tt</span> List1<span class="nb">}</span>.
</div><div id="l125" class="code_block">    If~<span class="nb">{</span><span class="k">\tt</span> List1<span class="nb">}</span> or~<span class="nb">{</span><span class="k">\tt</span> List2<span class="nb">}</span> contain duplicates, <span class="nb">{</span><span class="k">\tt</span> List3<span class="nb">}</span> may 
</div><div id="l126" class="code_block">    also contain duplicates.
</div><div id="l127" class="code_block">
</div><div id="l128" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>absmerge(+List1, +List2, ?List3)<span class="nb">}{</span>listutil<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> absmerge/3<span class="nb">}}</span>
</div><div id="l129" class="code_block"><span class="c">%\predindex{absmerge/3~(L)}</span>
</div><div id="l130" class="code_block">    Predicate <span class="nb">{</span><span class="k">\tt</span> absmerge/3<span class="nb">}</span> is similar to <span class="nb">{</span><span class="k">\tt</span> merge/3<span class="nb">}</span>, except that 
</div><div id="l131" class="code_block">    it uses predicate <span class="nb">{</span><span class="k">\tt</span> absmember/2<span class="nb">}</span> described below rather than 
</div><div id="l132" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> member/2<span class="nb">}</span>.
</div><div id="l133" class="code_block">
</div><div id="l134" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>absmember(+Element, +List)<span class="nb">}{</span>listutil<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> absmember/2<span class="nb">}}</span>
</div><div id="l135" class="code_block"><span class="c">%\predindex{absmember/2~(L)}</span>
</div><div id="l136" class="code_block">    Similar to <span class="nb">{</span><span class="k">\tt</span> member<span class="nb">}</span>/2, except that it checks for identity
</div><div id="l137" class="code_block">    (through the use of predicate <span class="nb">{</span><span class="k">\tt</span> &#39;==&#39;/2<span class="nb">}</span>) rather than unifiability 
</div><div id="l138" class="code_block">    (through <span class="nb">{</span><span class="k">\tt</span> &#39;=&#39;/2<span class="nb">}</span>) of <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span> with elements of <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span>.
</div><div id="l139" class="code_block">
</div><div id="l140" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>member2(?Element, ?List)<span class="nb">}{</span>listutil<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> member2/2<span class="nb">}}</span>
</div><div id="l141" class="code_block"><span class="c">%\predindex{member2/2~(L)}</span>
</div><div id="l142" class="code_block">    Checks whether <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span> unifies with any of the actual elements 
</div><div id="l143" class="code_block">    of <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span>.  The only difference between this predicate and 
</div><div id="l144" class="code_block">    predicate <span class="nb">{</span><span class="k">\tt</span> member/2<span class="nb">}</span> is on lists having a variable tail, 
</div><div id="l145" class="code_block">    e.g.<span class="k">\</span> <span class="k">\verb</span>&#39;[a, b, c | <span class="nb">_</span> ]&#39;: while <span class="nb">{</span><span class="k">\tt</span> member/2<span class="nb">}</span> would insert 
</div><div id="l146" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span> at the end of such a list if it did not find it, 
</div><div id="l147" class="code_block">    Predicate <span class="nb">{</span><span class="k">\tt</span> member2/2<span class="nb">}</span> only checks for membership but does not 
</div><div id="l148" class="code_block">    insert the <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span> into the list if it is not there.
</div><div id="l149" class="code_block">
</div><div id="l150" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>delete<span class="k">\_ith</span>(+Index, +List, ?Element, ?RestList)<span class="nb">}{</span>listutil<span class="nb">}</span>
</div><div id="l151" class="code_block"><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> delete<span class="k">\_ith</span>/4<span class="nb">}}</span>
</div><div id="l152" class="code_block"><span class="c">%\predindex{delete\_ith/4~(L)}</span>
</div><div id="l153" class="code_block">    Succeeds if the <span class="s">$</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Index^{th}}</span><span class="s">$</span> element of the list <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span>
</div><div id="l154" class="code_block">    unifies with <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span>, and <span class="nb">{</span><span class="k">\tt</span> RestList<span class="nb">}</span> is <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span> with
</div><div id="l155" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> Element<span class="nb">}</span> removed.  Fails if <span class="nb">{</span><span class="k">\tt</span> Index<span class="nb">}</span> is not a positive
</div><div id="l156" class="code_block">    integer or greater than the length of <span class="nb">{</span><span class="k">\tt</span> List<span class="nb">}</span>.
</div><div id="l157" class="code_block">
</div><div id="l158" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>closetail(?List)<span class="nb">}{</span>listutil<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> closetail/1<span class="nb">}}</span>
</div><div id="l159" class="code_block"><span class="c">%\predindex{closetail/1~(L)}</span>
</div><div id="l160" class="code_block">    Predicate <span class="nb">{</span><span class="k">\tt</span> closetail/1<span class="nb">}</span> closes the tail of an open-ended list.
</div><div id="l161" class="code_block">    It succeeds only once.
</div><div id="l162" class="code_block">
</div><div id="l163" class="code_block"><span class="k">\end</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l164" class="code_block">
</div><div id="l165" class="code_block">
</div><div id="l166" class="code_block"><span class="k">\section</span><span class="nb">{</span>Attributed Variables<span class="nb">}</span>
</div><div id="l167" class="code_block"><span class="c">%=============================</span>
</div><div id="l168" class="code_block">
</div><div id="l169" class="code_block">Attributed variables are a special data type that associates variables
</div><div id="l170" class="code_block">with arbitrary attributes as well as supports extensible unification.
</div><div id="l171" class="code_block">Attributed variables have proven to be a flexible and powerful mechanism
</div><div id="l172" class="code_block">to extend a classic logic programming system with the ability of
</div><div id="l173" class="code_block">constraint solving.  They have been implemented in SICStus <span class="k">\footnote</span><span class="nb">{</span>In
</div><div id="l174" class="code_block">  XSB, we try to keep the implementation of attributed variables to be
</div><div id="l175" class="code_block">  compatible with SICStus.<span class="nb">}</span> <span class="k">\cite</span><span class="nb">{</span>sicstus-manual<span class="nb">}</span> and ECL<span class="s">$</span><span class="nb">^i</span><span class="s">$</span>PS<span class="s">$</span><span class="nb">^e</span><span class="s">$</span>
</div><div id="l176" class="code_block"><span class="k">\cite</span><span class="nb">{</span>eclipse-manual<span class="nb">}</span>.
</div><div id="l177" class="code_block">
</div><div id="l178" class="code_block">Attributes of variables are compound terms whose arguments are the
</div><div id="l179" class="code_block">actual attribute values.  They are defined with a declaration
</div><div id="l180" class="code_block">
</div><div id="l181" class="code_block"><span class="k">\demo</span><span class="nb">{</span>:- attribute <span class="s">$</span><span class="nb">AttributeSpec, </span><span class="nv">\ldots</span><span class="nb">, AttributeSpec</span><span class="s">$</span>.<span class="nb">}</span>
</div><div id="l182" class="code_block">
</div><div id="l183" class="code_block"><span class="k">\noindent</span> where each <span class="s">$</span><span class="nb">Attributes</span><span class="s">$</span> has the form <span class="s">$</span><span class="nb">Functor</span><span class="o">/</span><span class="nb">Arity</span><span class="s">$</span>.  Each
</div><div id="l184" class="code_block">file can have at most one such declaration.
</div><div id="l185" class="code_block">
</div><div id="l186" class="code_block">Having declared some attribute names, these attributes can be added,
</div><div id="l187" class="code_block">updated and deleted from unbound variables using the following two
</div><div id="l188" class="code_block">predicates (<span class="k">\texttt</span><span class="nb">{</span>get<span class="k">\_atts</span>/2<span class="nb">}</span> and <span class="k">\texttt</span><span class="nb">{</span>put<span class="k">\_atts</span>/2<span class="nb">}</span>) defined in
</div><div id="l189" class="code_block">the module <span class="k">\texttt</span><span class="nb">{</span>atts<span class="nb">}</span>.  For each declared attribute name, any
</div><div id="l190" class="code_block">variable can have at most one such attribute (initially it has none).
</div><div id="l191" class="code_block">
</div><div id="l192" class="code_block"><span class="k">\begin</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l193" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>get<span class="k">\_atts</span>(-Var, ?AccessSpec)<span class="nb">}{</span>atts<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> get<span class="k">\_atts</span>/2<span class="nb">}}</span>
</div><div id="l194" class="code_block">    Gets the attributes of <span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span> according to
</div><div id="l195" class="code_block">    <span class="k">\texttt</span><span class="nb">{</span>AccessSpec<span class="nb">}</span>. If <span class="k">\texttt</span><span class="nb">{</span>AccessSpec<span class="nb">}</span> is unbound, it will be
</div><div id="l196" class="code_block">    bound to a list of all set attributes of <span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span>.  Non-variable
</div><div id="l197" class="code_block">    terms in <span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span> cause a type error.  <span class="k">\texttt</span><span class="nb">{</span>AccessSpec<span class="nb">}</span> is
</div><div id="l198" class="code_block">    either <span class="k">\texttt</span><span class="nb">{</span>+(Attribute)<span class="nb">}</span>, <span class="k">\texttt</span><span class="nb">{</span>-(Attribute)<span class="nb">}</span>, or a list of
</div><div id="l199" class="code_block">    such (prefix <span class="k">\texttt</span><span class="nb">{</span>+<span class="nb">}</span> may be dropped for convenience).  The
</div><div id="l200" class="code_block">    prefixes in the <span class="k">\texttt</span><span class="nb">{</span>AccessSpec<span class="nb">}</span> have the following meaning:
</div><div id="l201" class="code_block">
</div><div id="l202" class="code_block">    <span class="k">\begin</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l203" class="code_block">    <span class="k">\item</span><span class="na">[\texttt{+(Attribute)}:]</span>
</div><div id="l204" class="code_block">      The corresponding actual attribute must be present and is unified
</div><div id="l205" class="code_block">      with <span class="k">\texttt</span><span class="nb">{</span>Attribute<span class="nb">}</span>.
</div><div id="l206" class="code_block">
</div><div id="l207" class="code_block">    <span class="k">\item</span><span class="na">[\texttt{-(Attribute)}:]</span>
</div><div id="l208" class="code_block">      The corresponding actual attribute must be absent.  The arguments
</div><div id="l209" class="code_block">      of <span class="k">\texttt</span><span class="nb">{</span>Attribute<span class="nb">}</span> are ignored, only the name and arity are
</div><div id="l210" class="code_block">      relevant.
</div><div id="l211" class="code_block">    <span class="k">\end</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l212" class="code_block">
</div><div id="l213" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>put<span class="k">\_atts</span>(-Var, +AccessSpec)<span class="nb">}{</span>atts<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> put<span class="k">\_atts</span>/2<span class="nb">}}</span>
</div><div id="l214" class="code_block">    Sets the attributes of <span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span> according to
</div><div id="l215" class="code_block">    <span class="k">\texttt</span><span class="nb">{</span>AccessSpec<span class="nb">}</span>.  Non-variable terms in <span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span> cause a
</div><div id="l216" class="code_block">    type error.  The effect of <span class="k">\texttt</span><span class="nb">{</span>put<span class="k">\_atts</span>/2<span class="nb">}</span> are undone on
</div><div id="l217" class="code_block">    backtracking.  The prefixes of <span class="k">\texttt</span><span class="nb">{</span>AccessSpec<span class="nb">}</span> have the
</div><div id="l218" class="code_block">    following meaning:
</div><div id="l219" class="code_block">
</div><div id="l220" class="code_block">    <span class="k">\begin</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l221" class="code_block">    <span class="k">\item</span><span class="na">[\texttt{+(Attribute)}:]</span>
</div><div id="l222" class="code_block">      The corresponding actual attribute is set to <span class="k">\texttt</span><span class="nb">{</span>Attribute<span class="nb">}</span>.
</div><div id="l223" class="code_block">      If the actual attribute was already present, it is simply
</div><div id="l224" class="code_block">      replaced.
</div><div id="l225" class="code_block">
</div><div id="l226" class="code_block">    <span class="k">\item</span><span class="na">[\texttt{-(Attribute)}:]</span>
</div><div id="l227" class="code_block">      The corresponding actual attribute is removed.  If the actual
</div><div id="l228" class="code_block">      attribute is already absent, nothing happens.
</div><div id="l229" class="code_block">
</div><div id="l230" class="code_block">    <span class="k">\end</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l231" class="code_block">
</div><div id="l232" class="code_block"><span class="k">\end</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l233" class="code_block">
</div><div id="l234" class="code_block">In a file that contains an attribute declaration, one has an opportunity
</div><div id="l235" class="code_block">to extend the default unification algorithm by defining the following
</div><div id="l236" class="code_block">predicate:
</div><div id="l237" class="code_block">
</div><div id="l238" class="code_block"><span class="k">\demo</span><span class="nb">{</span>verify<span class="k">\_attributes</span>(-Var, +Value)<span class="nb">}</span>
</div><div id="l239" class="code_block">
</div><div id="l240" class="code_block">This predicate is called whenever an attributed variable <span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span>
</div><div id="l241" class="code_block">(which has at least one attribute) is about to be bound to
</div><div id="l242" class="code_block"><span class="k">\texttt</span><span class="nb">{</span>Value<span class="nb">}</span> (a non-variable term or another attributed variable).
</div><div id="l243" class="code_block">When <span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span> is to be bound to <span class="k">\texttt</span><span class="nb">{</span>Value<span class="nb">}</span>, a special interrupt
</div><div id="l244" class="code_block">called <span class="k">\emph</span><span class="nb">{</span>attributed variable interrupt<span class="nb">}</span> is triggered, and then XSB&#39;s
</div><div id="l245" class="code_block">interrupt handler (written in Prolog) calls
</div><div id="l246" class="code_block"><span class="k">\texttt</span><span class="nb">{</span>verify<span class="k">\_attributes</span>/2<span class="nb">}</span>.  If it fails, the unification is deemed
</div><div id="l247" class="code_block">to have failed.  It may succeed non-deterministically, in which case the
</div><div id="l248" class="code_block">unification might backtrack to give another answer.
</div><div id="l249" class="code_block">
</div><div id="l250" class="code_block">If <span class="k">\texttt</span><span class="nb">{</span>Value<span class="nb">}</span> is a non-variable term, <span class="k">\texttt</span><span class="nb">{</span>verify<span class="k">\_attributes</span>/2<span class="nb">}</span>
</div><div id="l251" class="code_block">usually inspects the attributes of <span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span> and check whether they
</div><div id="l252" class="code_block">are compatible with <span class="k">\texttt</span><span class="nb">{</span>Value<span class="nb">}</span> and fail otherwise.  If
</div><div id="l253" class="code_block"><span class="k">\texttt</span><span class="nb">{</span>Value<span class="nb">}</span> is another attributed variable,
</div><div id="l254" class="code_block"><span class="k">\texttt</span><span class="nb">{</span>verify<span class="k">\_attributes</span>/2<span class="nb">}</span> will typically merge the attributes of
</div><div id="l255" class="code_block"><span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span> and <span class="k">\texttt</span><span class="nb">{</span>Value<span class="nb">}</span>, bind <span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span> to <span class="k">\texttt</span><span class="nb">{</span>Value<span class="nb">}</span>,
</div><div id="l256" class="code_block">and then update their attributes.  In either case,
</div><div id="l257" class="code_block"><span class="k">\texttt</span><span class="nb">{</span>verify<span class="k">\_attributes</span>/2<span class="nb">}</span> may determine the attributes of
</div><div id="l258" class="code_block"><span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span> (or <span class="k">\texttt</span><span class="nb">{</span>Value<span class="nb">}</span>) by calling <span class="k">\texttt</span><span class="nb">{</span>get<span class="k">\_atts</span>/2<span class="nb">}</span>.
</div><div id="l259" class="code_block">
</div><div id="l260" class="code_block">The predicate <span class="k">\texttt</span><span class="nb">{</span>verify<span class="k">\_attributes</span>/2<span class="nb">}</span> is also called
</div><div id="l261" class="code_block"><span class="k">\emph</span><span class="nb">{</span>user-defined unification handler<span class="nb">}</span>.  To help users define this
</div><div id="l262" class="code_block">handler, the following predicate is provided in module <span class="k">\texttt</span><span class="nb">{</span>machine<span class="nb">}</span>,
</div><div id="l263" class="code_block">which can be used to bind an attributed variable to an arbitrary term
</div><div id="l264" class="code_block">(might be another attributed variable) without triggering attributed
</div><div id="l265" class="code_block">variable interrupt and thus another level call of
</div><div id="l266" class="code_block"><span class="k">\texttt</span><span class="nb">{</span>verify<span class="k">\_attributes</span>/2<span class="nb">}</span>:
</div><div id="l267" class="code_block">
</div><div id="l268" class="code_block"><span class="k">\begin</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l269" class="code_block">
</div><div id="l270" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>attv<span class="k">\_unify</span>(-Var, +Value)<span class="nb">}{</span>machine<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span>
</div><div id="l271" class="code_block">    attv<span class="k">\_unify</span>/2<span class="nb">}}</span>
</div><div id="l272" class="code_block">This is an internal built-in predicate which is supposed to be used only
</div><div id="l273" class="code_block">in the definition of <span class="k">\texttt</span><span class="nb">{</span>verify<span class="k">\_attributes</span>/2<span class="nb">}</span>.  It binds the
</div><div id="l274" class="code_block">attributed variable <span class="k">\texttt</span><span class="nb">{</span>Var<span class="nb">}</span> to <span class="k">\texttt</span><span class="nb">{</span>Value<span class="nb">}</span> without triggering
</div><div id="l275" class="code_block">attributed variable interrupt.  <span class="k">\texttt</span><span class="nb">{</span>Value<span class="nb">}</span> is a non-variable term or
</div><div id="l276" class="code_block">another attributed variable.
</div><div id="l277" class="code_block">
</div><div id="l278" class="code_block"><span class="k">\end</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l279" class="code_block">
</div><div id="l280" class="code_block">Here, by giving the implementation of a simple finite domain constraint
</div><div id="l281" class="code_block">solver (see the file <span class="k">\texttt</span><span class="nb">{</span>fd.P<span class="nb">}</span> below), we show how these predicates
</div><div id="l282" class="code_block">for attributed variables can be used.  In this example, only one
</div><div id="l283" class="code_block">attribute is declared: <span class="k">\texttt</span><span class="nb">{</span>dom/1<span class="nb">}</span>, and the value of this attribute
</div><div id="l284" class="code_block">is a list of terms.
</div><div id="l285" class="code_block">
</div><div id="l286" class="code_block"><span class="k">\begin</span><span class="nb">{</span>small<span class="nb">}</span>
</div><div id="l287" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l288" class="code_block"><span class="c">%% File: fd.P</span>
</div><div id="l289" class="code_block"><span class="c">%%</span>
</div><div id="l290" class="code_block"><span class="c">%% A simple finite domain constrait solver implemented using attributed</span>
</div><div id="l291" class="code_block"><span class="c">%% variables.  </span>
</div><div id="l292" class="code_block">
</div><div id="l293" class="code_block">:- import put<span class="nb">_</span>atts/2, get<span class="nb">_</span>atts/2 from atts.
</div><div id="l294" class="code_block">:- import attv<span class="nb">_</span>unify/2 from machine.
</div><div id="l295" class="code_block">:- import member/2 from basics.
</div><div id="l296" class="code_block">
</div><div id="l297" class="code_block">:- attribute dom/1.
</div><div id="l298" class="code_block">
</div><div id="l299" class="code_block">verify<span class="nb">_</span>attributes(Var, Value) :-
</div><div id="l300" class="code_block">        get<span class="nb">_</span>atts(Var, dom(Da)),
</div><div id="l301" class="code_block">        (var(Value)                          <span class="c">% Value is an attributed variable</span>
</div><div id="l302" class="code_block">         -&gt; get<span class="nb">_</span>atts(Value, dom(Db)),        <span class="c">% has a domain</span>
</div><div id="l303" class="code_block">            intersection(Da, Db, [E|Es]),    <span class="c">% intersection not empty</span>
</div><div id="l304" class="code_block">            (Es = []                         <span class="c">% exactly one element</span>
</div><div id="l305" class="code_block">             -&gt; attv<span class="nb">_</span>unify(Var, Value),      <span class="c">% bind Var to Value</span>
</div><div id="l306" class="code_block">                attv<span class="nb">_</span>unify(Var, E)           <span class="c">% bind Var (and Value) to E</span>
</div><div id="l307" class="code_block">             ;  attv<span class="nb">_</span>unify(Var, Value),      <span class="c">% bind Var to Value</span>
</div><div id="l308" class="code_block">                put<span class="nb">_</span>atts(Value, dom([E|Es])) <span class="c">% update Var&#39;s (and Value&#39;s)</span>
</div><div id="l309" class="code_block">                                             <span class="c">% attributes</span>
</div><div id="l310" class="code_block">            )
</div><div id="l311" class="code_block">         ;  member(Value, Da),               <span class="c">% is Value a member of Da?</span>
</div><div id="l312" class="code_block">            attv<span class="nb">_</span>unify(Var, Value)           <span class="c">% bind Var to Value</span>
</div><div id="l313" class="code_block">        ).
</div><div id="l314" class="code_block">
</div><div id="l315" class="code_block">intersection([], <span class="nb">_</span>, []).
</div><div id="l316" class="code_block">intersection([H|T], L2, [H|L3]) :-
</div><div id="l317" class="code_block">        member(H, L2), !,
</div><div id="l318" class="code_block">        intersection(T, L2, L3).
</div><div id="l319" class="code_block">intersection([<span class="nb">_</span>|T], L2, L3) :-
</div><div id="l320" class="code_block">        intersection(T, L2, L3).
</div><div id="l321" class="code_block">
</div><div id="l322" class="code_block">domain(X, Dom) :- 
</div><div id="l323" class="code_block">        var(Dom), !, 
</div><div id="l324" class="code_block">        get<span class="nb">_</span>atts(X, dom(Dom)). 
</div><div id="l325" class="code_block">domain(X, List) :- 
</div><div id="l326" class="code_block">        List = [El|Els],                     <span class="c">% at least one element </span>
</div><div id="l327" class="code_block">        (Els = []                            <span class="c">% exactly one element</span>
</div><div id="l328" class="code_block">         -&gt; X = El                           <span class="c">% implied binding </span>
</div><div id="l329" class="code_block">         ;  put<span class="nb">_</span>atts(Fresh, dom(List)),      <span class="c">% create a new attributed variable</span>
</div><div id="l330" class="code_block">            X = Fresh                        <span class="c">% may call verify_attributes/2</span>
</div><div id="l331" class="code_block">        ).
</div><div id="l332" class="code_block">
</div><div id="l333" class="code_block">show<span class="nb">_</span>domain(X) :-                            <span class="c">% print out the domain of X</span>
</div><div id="l334" class="code_block">        var(X),                              <span class="c">% X must be a variable</span>
</div><div id="l335" class="code_block">        get<span class="nb">_</span>atts(X, dom(D)),
</div><div id="l336" class="code_block">        write(&#39;Domain of &#39;), write(X),
</div><div id="l337" class="code_block">        write(&#39; is &#39;), writeln(D).
</div><div id="l338" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l339" class="code_block"><span class="k">\end</span><span class="nb">{</span>small<span class="nb">}</span>
</div><div id="l340" class="code_block">
</div><div id="l341" class="code_block">The output of some example queries are listed below, from which we can
</div><div id="l342" class="code_block">see how attributed variables are unified using
</div><div id="l343" class="code_block"><span class="k">\texttt</span><span class="nb">{</span>verify<span class="k">\_attributes</span>/2<span class="nb">}</span>:
</div><div id="l344" class="code_block">
</div><div id="l345" class="code_block"><span class="k">\begin</span><span class="nb">{</span>small<span class="nb">}</span>
</div><div id="l346" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l347" class="code_block">    | ?- [fd].
</div><div id="l348" class="code_block">    [fd loaded]
</div><div id="l349" class="code_block">    
</div><div id="l350" class="code_block">    yes
</div><div id="l351" class="code_block">    | ?- domain(X,[5,6,7,1]), domain(Y,[3,4,5,6]), domain(Z,[1,6,7,8]),
</div><div id="l352" class="code_block">         show<span class="nb">_</span>domain(X), show<span class="nb">_</span>domain(Y), show<span class="nb">_</span>domain(Z).
</div><div id="l353" class="code_block">    Domain of <span class="nb">_</span>h474 is [5,6,7,1]
</div><div id="l354" class="code_block">    Domain of <span class="nb">_</span>h503 is [3,4,5,6]
</div><div id="l355" class="code_block">    Domain of <span class="nb">_</span>h532 is [1,6,7,8]
</div><div id="l356" class="code_block">    
</div><div id="l357" class="code_block">    X = <span class="nb">_</span>h474
</div><div id="l358" class="code_block">    Y = <span class="nb">_</span>h503
</div><div id="l359" class="code_block">    Z = <span class="nb">_</span>h532
</div><div id="l360" class="code_block">    
</div><div id="l361" class="code_block">    yes
</div><div id="l362" class="code_block">    | ?- domain(X,[5,6,7,1]), domain(Y,[3,4,5,6]), domain(Z,[1,6,7,8]),
</div><div id="l363" class="code_block">         X = Y, show<span class="nb">_</span>domain(X), show<span class="nb">_</span>domain(Y), show<span class="nb">_</span>domain(Z).
</div><div id="l364" class="code_block">    Domain of <span class="nb">_</span>h640 is [5,6]
</div><div id="l365" class="code_block">    Domain of <span class="nb">_</span>h640 is [5,6]
</div><div id="l366" class="code_block">    Domain of <span class="nb">_</span>h569 is [1,6,7,8]
</div><div id="l367" class="code_block">    
</div><div id="l368" class="code_block">    X = <span class="nb">_</span>h640
</div><div id="l369" class="code_block">    Y = <span class="nb">_</span>h640
</div><div id="l370" class="code_block">    Z = <span class="nb">_</span>h569
</div><div id="l371" class="code_block">    
</div><div id="l372" class="code_block">    yes
</div><div id="l373" class="code_block">    | ?- domain(X,[5,6,7,1]), domain(Y,[3,4,5,6]), domain(Z,[1,6,7,8]),
</div><div id="l374" class="code_block">         X = Y, Y = Z.
</div><div id="l375" class="code_block">    
</div><div id="l376" class="code_block">    X = 6
</div><div id="l377" class="code_block">    Y = 6
</div><div id="l378" class="code_block">    Z = 6
</div><div id="l379" class="code_block">    
</div><div id="l380" class="code_block">    yes
</div><div id="l381" class="code_block">    | ?- 
</div><div id="l382" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l383" class="code_block"><span class="k">\end</span><span class="nb">{</span>small<span class="nb">}</span>
</div><div id="l384" class="code_block">
</div><div id="l385" class="code_block">
</div><div id="l386" class="code_block"><span class="k">\section</span><span class="nb">{</span>Asserting Dynamic Code<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>LoadDyn<span class="nb">}</span>
</div><div id="l387" class="code_block"><span class="c">%===============================================</span>
</div><div id="l388" class="code_block">
</div><div id="l389" class="code_block">The module <span class="nb">{</span><span class="k">\tt</span> consult<span class="nb">}</span> in directory <span class="nb">{</span><span class="k">\tt</span> lib<span class="nb">}</span> provides several handy
</div><div id="l390" class="code_block">library predicates that can assert the contents of a file into XSB&#39;s
</div><div id="l391" class="code_block">database.  The use of these predicates may be necessary when the code
</div><div id="l392" class="code_block">needs to be <span class="nb">{</span><span class="k">\tt</span> dynamic<span class="nb">}</span> (so that it is retractable), or when it
</div><div id="l393" class="code_block">contains atoms whose length is more than 255 that cannot be handled by
</div><div id="l394" class="code_block">the XSB compiler.
</div><div id="l395" class="code_block">
</div><div id="l396" class="code_block"><span class="k">\begin</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l397" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>load<span class="k">\_dyn</span>(+FileName)<span class="nb">}{</span>consult<span class="nb">}</span>
</div><div id="l398" class="code_block"><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> load<span class="k">\_dyn</span>/1<span class="nb">}}</span><span class="k">\label</span><span class="nb">{</span>load<span class="nb">_</span>dyn/1<span class="nb">}</span>
</div><div id="l399" class="code_block"><span class="c">%\predindex{load\_dyn/1~(L)}</span>
</div><div id="l400" class="code_block">    Asserts the contents of file <span class="nb">{</span><span class="k">\tt</span> FileName<span class="nb">}</span> into the database.
</div><div id="l401" class="code_block">    All existing clauses of the predicates in the file that already
</div><div id="l402" class="code_block">    appear in the database, are retracted, unless there is a <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l403" class="code_block">    multifile/1<span class="nb">}</span> declaration for them.  Clauses in the file must be
</div><div id="l404" class="code_block">    in a format that <span class="nb">{</span><span class="k">\tt</span> read/1<span class="nb">}</span> will process.  So, for example,
</div><div id="l405" class="code_block">    operators are permitted.  As usual, clauses of predicates are not
</div><div id="l406" class="code_block">    retracted if they are compiled instead of dynamically asserted.
</div><div id="l407" class="code_block">    All predicates are loaded into <span class="nb">{</span><span class="k">\tt</span> usermod<span class="nb">}</span>.  Module declarations
</div><div id="l408" class="code_block">    such as <span class="nb">{</span><span class="k">\tt</span> :- export<span class="nb">}</span> are ignored and a warning is issued.
</div><div id="l409" class="code_block">
</div><div id="l410" class="code_block">    Dynamically loaded files can be filtered through the XSB preprocessor.
</div><div id="l411" class="code_block">    To do this, put the following in the source file: 
</div><div id="l412" class="code_block">    <span class="c">%%</span>
</div><div id="l413" class="code_block">    <span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l414" class="code_block">    :- compiler<span class="nb">_</span>options([xpp<span class="nb">_</span>on]).      
</div><div id="l415" class="code_block">    <span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l416" class="code_block">    <span class="c">%%</span>
</div><div id="l417" class="code_block">    Of course, the name <span class="k">\verb</span>|compiler<span class="nb">_</span>options| might seem like a misnomer
</div><div id="l418" class="code_block">    here (since the file is not being compiled), but it is convenient to
</div><div id="l419" class="code_block">    use the same directive both for compiling and loading, in case the same
</div><div id="l420" class="code_block">    source file is used both ways.
</div><div id="l421" class="code_block">
</div><div id="l422" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>ensure<span class="k">\_dyn\_loaded</span>(+FileName)<span class="nb">}{</span>consult<span class="nb">}</span>
</div><div id="l423" class="code_block"><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> ensure<span class="k">\_dyn\_loaded</span>/1<span class="nb">}}</span>
</div><div id="l424" class="code_block">    Is similar to <span class="nb">{</span><span class="k">\tt</span> load<span class="k">\_dyn</span>/1<span class="nb">}</span> except that it does nothing if the
</div><div id="l425" class="code_block">    file has previously been loaded and the file has not been changed
</div><div id="l426" class="code_block">    since.  However the file will be reloaded if the index declaration of
</div><div id="l427" class="code_block">    any predicate in that file has changed to require more indexing, or a
</div><div id="l428" class="code_block">    larger hash table.
</div><div id="l429" class="code_block">
</div><div id="l430" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>load<span class="k">\_dync</span>(+FileName)<span class="nb">}{</span>consult<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> load<span class="k">\_dync</span>/1<span class="nb">}}</span>
</div><div id="l431" class="code_block"><span class="c">%\predindex{load\_dync/1~(L)}</span>
</div><div id="l432" class="code_block">    Asserts the contents of file <span class="nb">{</span><span class="k">\tt</span> FileName<span class="nb">}</span> into the database.
</div><div id="l433" class="code_block">    All existing clauses of the predicates in the file that already appear
</div><div id="l434" class="code_block">    in the database, are retracted unless there is a <span class="nb">{</span><span class="k">\tt</span> multifile/1<span class="nb">}</span>
</div><div id="l435" class="code_block">    directive for them.  The terms in the file <span class="nb">{</span><span class="k">\tt</span> FileName<span class="nb">}</span> must be in
</div><div id="l436" class="code_block">    ``canonical&#39;&#39; format; that is, they must not use any operators (or
</div><div id="l437" class="code_block">    list notation.) This is the format produced by the predicate <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l438" class="code_block">    write<span class="k">\_canonical</span>/1<span class="nb">}</span>. (See <span class="nb">{</span><span class="k">\tt</span> cvt<span class="k">\_canonical</span>/2<span class="nb">}</span> to convert a file from
</div><div id="l439" class="code_block">    the usual <span class="nb">{</span><span class="k">\tt</span> read/1<span class="nb">}</span> format to <span class="nb">{</span><span class="k">\tt</span> read<span class="k">\_canonical</span><span class="nb">}</span> format.)  As
</div><div id="l440" class="code_block">    usual, clauses of predicates are not retracted if they are compiled
</div><div id="l441" class="code_block">    instead of dynamically asserted. All predicates are loaded into <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l442" class="code_block">    usermod<span class="nb">}</span>.  <span class="nb">{</span><span class="k">\tt</span> :- export<span class="nb">}</span> declarations are ignored and a warning is
</div><div id="l443" class="code_block">    issued.
</div><div id="l444" class="code_block">
</div><div id="l445" class="code_block">    Notice that this predicate can be used to load files of Datalog facts
</div><div id="l446" class="code_block">    (since they will be in canonical format).  This predicate is
</div><div id="l447" class="code_block">    significantly faster than <span class="nb">{</span><span class="k">\tt</span> load<span class="k">\_dyn</span>/1<span class="nb">}</span> and should be used when
</div><div id="l448" class="code_block">    speed is important.  A file that is to be dynamically loaded often but
</div><div id="l449" class="code_block">    not often modified by hand should be loaded with this predicate.  Use
</div><div id="l450" class="code_block">    predicate <span class="nb">{</span><span class="k">\tt</span> cvt<span class="k">\_canonical</span>/2<span class="nb">}</span> (see below) to convert a usual file
</div><div id="l451" class="code_block">    to a format readable by this predicate.
</div><div id="l452" class="code_block">
</div><div id="l453" class="code_block">    As with <span class="k">\verb</span>|load<span class="nb">_</span>dyn/1|, the source file can be filtered through the C
</div><div id="l454" class="code_block">    preprocessor. However, since all clauses in such a file must be in
</div><div id="l455" class="code_block">    canonical form, the <span class="k">\verb</span>|compiler<span class="nb">_</span>options/1| directive should look as
</div><div id="l456" class="code_block">    follows:
</div><div id="l457" class="code_block">    <span class="c">%%</span>
</div><div id="l458" class="code_block">    <span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l459" class="code_block">     :-(compiler<span class="nb">_</span>options(&#39;.&#39;(xpp<span class="nb">_</span>on,[]))).      
</div><div id="l460" class="code_block">    <span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l461" class="code_block">    <span class="c">%%</span>
</div><div id="l462" class="code_block">
</div><div id="l463" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>ensure<span class="k">\_dync\_loaded</span>(+FileName)<span class="nb">}{</span>consult<span class="nb">}</span>
</div><div id="l464" class="code_block"><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> ensure<span class="k">\_dync\_loaded</span>/1<span class="nb">}}</span>
</div><div id="l465" class="code_block">    Is similar to <span class="nb">{</span><span class="k">\tt</span> load<span class="k">\_dync</span>/1<span class="nb">}</span> except that it does nothing if the
</div><div id="l466" class="code_block">    file has previously been loaded and the file has not been changed
</div><div id="l467" class="code_block">    since.  However the file will be reloaded if the index declaration of
</div><div id="l468" class="code_block">    any predicate in that file has changed to require more indexing, or a
</div><div id="l469" class="code_block">    larger hash table.
</div><div id="l470" class="code_block">
</div><div id="l471" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>cvt<span class="k">\_canonical</span>(+FileName1,+FileName2)<span class="nb">}{</span>consult<span class="nb">}</span>
</div><div id="l472" class="code_block"><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> cvt<span class="k">\_canonical</span>/2<span class="nb">}}</span>
</div><div id="l473" class="code_block">    Converts a file from standard term format to ``canonical&#39;&#39; format.
</div><div id="l474" class="code_block">    The input file name is <span class="nb">{</span><span class="k">\tt</span> FileName1<span class="nb">}</span>; the converted file is put in
</div><div id="l475" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> FileName2<span class="nb">}</span>.  This predicate can be used to convert a file in
</div><div id="l476" class="code_block">    standard Prolog format to one loadable by <span class="nb">{</span><span class="k">\tt</span> load<span class="k">\_dync</span>/1<span class="nb">}</span>.
</div><div id="l477" class="code_block"><span class="k">\end</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l478" class="code_block">
</div><div id="l479" class="code_block"><span class="c">%----------------------------------------------------------------------</span>
</div><div id="l480" class="code_block">
</div><div id="l481" class="code_block">
</div><div id="l482" class="code_block"><span class="k">\section</span><span class="nb">{</span>Ground, Numbervars, Subsumption, Variant<span class="nb">}</span> <span class="k">\label</span><span class="nb">{</span>NumberVars<span class="nb">}</span>
</div><div id="l483" class="code_block"><span class="c">%====================================================================</span>
</div><div id="l484" class="code_block">
</div><div id="l485" class="code_block"><span class="k">\begin</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l486" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>ground(+X)<span class="nb">}{</span>basics<span class="nb">}</span><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> ground/1<span class="nb">}}</span>
</div><div id="l487" class="code_block"><span class="c">%\predindex{ground/1~(L)}</span>
</div><div id="l488" class="code_block">    Succeeds if <span class="nb">{</span><span class="k">\tt</span> X<span class="nb">}</span> is currently instantiated to a term that is 
</div><div id="l489" class="code_block">    completely bound (has no uninstantiated variables in it); 
</div><div id="l490" class="code_block">    otherwise it fails.  Predicate <span class="nb">{</span><span class="k">\tt</span> ground/1<span class="nb">}</span> has no associated 
</div><div id="l491" class="code_block">    error conditions.
</div><div id="l492" class="code_block">
</div><div id="l493" class="code_block"><span class="k">\ournewitem</span><span class="nb">{</span>numbervars(+Term, +FirstN, ?LastN)<span class="nb">}{</span>num<span class="k">\_vars</span><span class="nb">}</span>
</div><div id="l494" class="code_block"><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> numbervars/3<span class="nb">}}</span>
</div><div id="l495" class="code_block"><span class="c">%\predindex{numbervars/3~(L)}</span>
</div><div id="l496" class="code_block">    This predicate provides a mechanism for grounding a (HiLog) term
</div><div id="l497" class="code_block">    so that it may be analyzed.  Each variable in the (HiLog) term
</div><div id="l498" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> Term<span class="nb">}</span> is instantiated to a term of the form <span class="k">\verb</span>|&#39;<span class="s">$</span><span class="nb">VAR&#39;</span><span class="o">(</span><span class="nb">N</span><span class="o">)</span><span class="nb">|,</span>
</div><div id="l499" class="code_block"><span class="nb">    where {</span><span class="nv">\tt</span><span class="nb"> N} is an integer starting from {</span><span class="nv">\tt</span><span class="nb"> FirstN}.  </span>
</div><div id="l500" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> FirstN} is used as the value of {</span><span class="nv">\tt</span><span class="nb"> N} for the first</span>
</div><div id="l501" class="code_block"><span class="nb">    variable in {</span><span class="nv">\tt</span><span class="nb"> Term} </span><span class="o">(</span><span class="nb">starting from the left</span><span class="o">)</span><span class="nb">. The second distinct</span>
</div><div id="l502" class="code_block"><span class="nb">    variable in {</span><span class="nv">\tt</span><span class="nb"> Term} is given a value of {</span><span class="nv">\tt</span><span class="nb"> N} satisfying</span>
</div><div id="l503" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> &quot;N is FirstN </span><span class="o">+</span><span class="nb"> </span><span class="m">1</span><span class="nb">&quot;} and so on.  The last variable in {</span><span class="nv">\tt</span><span class="nb"> Term}</span>
</div><div id="l504" class="code_block"><span class="nb">    has the value {</span><span class="nv">\tt</span><span class="nb"> LastN</span><span class="o">-</span><span class="m">1</span><span class="nb">}.</span>
</div><div id="l505" class="code_block"><span class="c">% $ for prettyprinter....</span>
</div><div id="l506" class="code_block">
</div><div id="l507" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{numbervars</span><span class="o">(+</span><span class="nb">Term</span><span class="o">)</span><span class="nb">}{num</span><span class="nv">\_</span><span class="nb">vars}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> numbervars</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l508" class="code_block"><span class="c">%\predindex{numbervars/1~(L)}</span>
</div><div id="l509" class="code_block"><span class="nb">    This predicate is defined as:</span>
</div><div id="l510" class="code_block"><span class="nb">    </span><span class="nv">\begin</span><span class="nb">{center}</span>
</div><div id="l511" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb">   numbervars</span><span class="o">(</span><span class="nb">Term, </span><span class="m">0</span><span class="nb">, </span><span class="nv">\_</span><span class="o">)</span><span class="nb">}.</span>
</div><div id="l512" class="code_block"><span class="nb">    </span><span class="nv">\end</span><span class="nb">{center}</span>
</div><div id="l513" class="code_block"><span class="nb">    It is included solely for convenience.</span>
</div><div id="l514" class="code_block">
</div><div id="l515" class="code_block"><span class="c">%\ournewitem{varnumbers(Term, FirstN, Copy)}{num\_vars}</span>
</div><div id="l516" class="code_block"><span class="c">%\index{{\tt varnumbers/3}}</span>
</div><div id="l517" class="code_block"><span class="c">%%\predindex{varnumbers/3~(B)}</span>
</div><div id="l518" class="code_block"><span class="c">%    This predicate is a partial inverse of predicate {\tt numbervars/3}.</span>
</div><div id="l519" class="code_block"><span class="c">%    It unifies {\tt Copy} with a copy of {\tt Term} in which subterms of</span>
</div><div id="l520" class="code_block"><span class="c">%    the form \verb|&#39;$VAR&#39;(N)| where {\tt N} is an integer not less than</span>
</div><div id="l521" class="code_block"><span class="c">%    {\tt FirstN} have been systematically replaced by fresh variables. </span>
</div><div id="l522" class="code_block"><span class="c">%    Since 0 is the usual second argument of numbervars/3,</span>
</div><div id="l523" class="code_block"><span class="c">%    \begin{center}</span>
</div><div id="l524" class="code_block"><span class="c">%    {\tt   varnumbers(Term, Copy)}</span>
</div><div id="l525" class="code_block"><span class="c">%    \end{center}</span>
</div><div id="l526" class="code_block"><span class="c">%    is also provided.</span>
</div><div id="l527" class="code_block">
</div><div id="l528" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{unnumbervars</span><span class="o">(+</span><span class="nb">Term, </span><span class="o">+</span><span class="nb">FirstN, ?Copy</span><span class="o">)</span><span class="nb">}{num</span><span class="nv">\_</span><span class="nb">vars}</span>
</div><div id="l529" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> unnumbervars</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l530" class="code_block"><span class="c">%\predindex{unnumbervars/3~(B)}</span>
</div><div id="l531" class="code_block"><span class="nb">    This predicate is a partial inverse of predicate {</span><span class="nv">\tt</span>
</div><div id="l532" class="code_block"><span class="nb">    numbervars</span><span class="o">/</span><span class="m">3</span><span class="nb">}.  It creates a copy of Term in which all subterms of</span>
</div><div id="l533" class="code_block"><span class="nb">    the form </span><span class="nv">\verb</span><span class="nb">|&#39;</span><span class="s">$</span>VAR&#39;(&lt;int&gt;)| where <span class="k">\verb</span>|&lt;int&gt;| is not less than
</div><div id="l534" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> FirstN<span class="nb">}</span> are uniformly replaced by variables.  <span class="k">\verb</span>|&#39;<span class="s">$</span><span class="nb">VAR&#39;&#39;|</span>
</div><div id="l535" class="code_block"><span class="nb">    subterms with the same integer are replaced by the same variable.</span>
</div><div id="l536" class="code_block"><span class="nb">    Also a version {</span><span class="nv">\tt</span><span class="nb"> unnumbervars</span><span class="o">/</span><span class="m">2</span><span class="nb">} is provided which calls {</span><span class="nv">\tt</span>
</div><div id="l537" class="code_block"><span class="nb">    unnumbervars</span><span class="o">/</span><span class="m">3</span><span class="nb">} with the second parameter set to </span><span class="m">0</span><span class="nb">.</span>
</div><div id="l538" class="code_block">
</div><div id="l539" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{subsumes</span><span class="o">(</span><span class="nb">?Term</span><span class="m">1</span><span class="nb">, </span><span class="o">+</span><span class="nb">Term</span><span class="m">2</span><span class="o">)</span><span class="nb">}{subsumes}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> subsumes</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l540" class="code_block"><span class="c">%\predindex{subsumes/2~(L)}</span>
</div><div id="l541" class="code_block"><span class="nb">    Term subsumption is a sort of one</span><span class="o">-</span><span class="nb">way unification.  Term {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l542" class="code_block"><span class="nb">    and {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">} unify if they have a common instance, and unification</span>
</div><div id="l543" class="code_block"><span class="nb">    in Prolog instantiates both terms to that </span><span class="o">(</span><span class="nb">most general</span><span class="o">)</span><span class="nb"> common instance.</span>
</div><div id="l544" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">} subsumes {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">} if {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">} is already an instance of</span>
</div><div id="l545" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">}.  For our purposes, {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">} is an instance of {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l546" class="code_block"><span class="nb">    if there is a substitution that leaves {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">} unchanged and makes</span>
</div><div id="l547" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">} identical to {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">}.  Predicate {</span><span class="nv">\tt</span><span class="nb"> subsumes</span><span class="o">/</span><span class="m">2</span><span class="nb">} does</span>
</div><div id="l548" class="code_block"><span class="nb">    not work as described if {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">} share common</span>
</div><div id="l549" class="code_block"><span class="nb">    variables.</span>
</div><div id="l550" class="code_block">
</div><div id="l551" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{subsumes</span><span class="nv">\_</span><span class="nb">chk</span><span class="o">(+</span><span class="nb">Term</span><span class="m">1</span><span class="nb">, </span><span class="o">+</span><span class="nb">Term</span><span class="m">2</span><span class="o">)</span><span class="nb">}{subsumes}</span>
</div><div id="l552" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> subsumes</span><span class="nv">\_</span><span class="nb">chk</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l553" class="code_block"><span class="c">%\predindex{subsumes\_chk/2~(L)}</span>
</div><div id="l554" class="code_block"><span class="nb">    The {</span><span class="nv">\tt</span><span class="nb"> subsumes</span><span class="nv">\_</span><span class="nb">chk</span><span class="o">/</span><span class="m">2</span><span class="nb">} predicate is true when {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">} subsumes </span>
</div><div id="l555" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">}; that is, when {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">} is already an instance of</span>
</div><div id="l556" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">}.  This predicate simply checks for subsumption and </span>
</div><div id="l557" class="code_block"><span class="nb">    does not bind any variables either in {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">} or in {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">}.</span>
</div><div id="l558" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">} should not share any variables.</span>
</div><div id="l559" class="code_block">
</div><div id="l560" class="code_block"><span class="nb">    Examples:</span>
</div><div id="l561" class="code_block"><span class="nb">    {</span><span class="nv">\footnotesize</span>
</div><div id="l562" class="code_block"><span class="nb">     </span><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l563" class="code_block"><span class="nb">            | ?</span><span class="o">-</span><span class="nb"> subsumes_chk</span><span class="o">(</span><span class="nb">a</span><span class="o">(</span><span class="nb">X,f,Y,X</span><span class="o">)</span><span class="nb">,a</span><span class="o">(</span><span class="nb">U,V,b,S</span><span class="o">))</span><span class="nb">.</span>
</div><div id="l564" class="code_block">
</div><div id="l565" class="code_block"><span class="nb">            no</span>
</div><div id="l566" class="code_block"><span class="nb">            | ?</span><span class="o">-</span><span class="nb"> subsumes_chk</span><span class="o">(</span><span class="nb">a</span><span class="o">(</span><span class="nb">X,Y,X</span><span class="o">)</span><span class="nb">,a</span><span class="o">(</span><span class="nb">b,b,b</span><span class="o">))</span><span class="nb">.</span>
</div><div id="l567" class="code_block">
</div><div id="l568" class="code_block"><span class="nb">            X </span><span class="o">=</span><span class="nb"> _</span><span class="m">595884</span>
</div><div id="l569" class="code_block"><span class="nb">            Y </span><span class="o">=</span><span class="nb"> _</span><span class="m">595624</span>
</div><div id="l570" class="code_block"><span class="nb">     </span><span class="nv">\end</span><span class="nb">{verbatim}}</span>
</div><div id="l571" class="code_block">
</div><div id="l572" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{variant</span><span class="o">(</span><span class="nb">?Term</span><span class="m">1</span><span class="nb">, ?Term</span><span class="m">2</span><span class="o">)</span><span class="nb">}{subsumes}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> variant</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l573" class="code_block"><span class="c">%\predindex{variant/2~(L)}</span>
</div><div id="l574" class="code_block"><span class="nb">    This predicate is true when {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">1</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> Term</span><span class="m">2</span><span class="nb">} are </span>
</div><div id="l575" class="code_block"><span class="nb">    alphabetic variants.  That is, you could imagine that {</span><span class="nv">\tt</span><span class="nb"> variant</span><span class="o">/</span><span class="m">2</span><span class="nb">}</span>
</div><div id="l576" class="code_block"><span class="nb">    as being defined like:</span>
</div><div id="l577" class="code_block"><span class="nb">    </span><span class="nv">\begin</span><span class="nb">{center}</span>
</div><div id="l578" class="code_block"><span class="nb">    </span><span class="nv">\begin</span><span class="nb">{minipage}{</span><span class="m">3</span><span class="nb">.</span><span class="m">5</span><span class="nb">in}</span>
</div><div id="l579" class="code_block"><span class="nb">    </span><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l580" class="code_block"><span class="nb">        variant</span><span class="o">(</span><span class="nb">Term</span><span class="m">1</span><span class="nb">, Term</span><span class="m">2</span><span class="o">)</span><span class="nb"> :</span><span class="o">-</span>
</div><div id="l581" class="code_block"><span class="nb">             subsumes_chk</span><span class="o">(</span><span class="nb">Term</span><span class="m">1</span><span class="nb">, Term</span><span class="m">2</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l582" class="code_block"><span class="nb">             subsumes_chk</span><span class="o">(</span><span class="nb">Term</span><span class="m">2</span><span class="nb">, Term</span><span class="m">1</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l583" class="code_block"><span class="nb">    </span><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l584" class="code_block"><span class="nb">    </span><span class="nv">\end</span><span class="nb">{minipage}</span>
</div><div id="l585" class="code_block"><span class="nb">    </span><span class="nv">\end</span><span class="nb">{center}</span>
</div><div id="l586" class="code_block"><span class="nb">    but the actual implementation of {</span><span class="nv">\tt</span><span class="nb"> variant</span><span class="o">/</span><span class="m">2</span><span class="nb">} is considerably more</span>
</div><div id="l587" class="code_block"><span class="nb">    efficient.  However, in general, it does not work for terms that share</span>
</div><div id="l588" class="code_block"><span class="nb">    variables; an assumption that holds for most </span><span class="o">(</span><span class="nb">reasonable</span><span class="o">)</span><span class="nb"> uses of</span>
</div><div id="l589" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> variant</span><span class="o">/</span><span class="m">2</span><span class="nb">}.</span>
</div><div id="l590" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l591" class="code_block">
</div><div id="l592" class="code_block">
</div><div id="l593" class="code_block"><span class="nv">\section</span><span class="nb">{Lower</span><span class="o">-</span><span class="nb">Level I</span><span class="o">/</span><span class="nb">O}</span>
</div><div id="l594" class="code_block"><span class="nv">\label</span><span class="nb">{sec</span><span class="o">-</span><span class="nb">low</span><span class="o">-</span><span class="nb">level</span><span class="o">-</span><span class="nb">io}</span>
</div><div id="l595" class="code_block"><span class="c">%======================</span>
</div><div id="l596" class="code_block">
</div><div id="l597" class="code_block"><span class="nb">XSB has various low</span><span class="o">-</span><span class="nb">level routines that support input and output, at both</span>
</div><div id="l598" class="code_block"><span class="nb">the term level and the character level.  Unlike the standard Prolog stream</span>
</div><div id="l599" class="code_block"><span class="nb">I</span><span class="o">/</span><span class="nb">O, the low</span><span class="o">-</span><span class="nb">level routines use </span><span class="nv">\emph</span><span class="nb">{XSB I</span><span class="o">/</span><span class="nb">O ports} to refer to files. XSB</span>
</div><div id="l600" class="code_block"><span class="nb">I</span><span class="o">/</span><span class="nb">O ports should not be confused with the file descriptors used by the OS</span>
</div><div id="l601" class="code_block"><span class="nb">Both are small integers, but they refer to different things. However, the</span>
</div><div id="l602" class="code_block"><span class="nb">OS file descriptors are objects returned by the C {</span><span class="nv">\tt</span><span class="nb"> open} function; XSB</span>
</div><div id="l603" class="code_block"><span class="nb">I</span><span class="o">/</span><span class="nb">O ports indices into the internal XSB table of open files. The OS does</span>
</div><div id="l604" class="code_block"><span class="nb">not know about XSB I</span><span class="o">/</span><span class="nb">O ports, while XSB </span><span class="o">(</span><span class="nb">obviously</span><span class="o">)</span><span class="nb"> does know about the OS</span>
</div><div id="l605" class="code_block"><span class="nb">file descriptors. Typically XSB opens files for buffered I</span><span class="o">/</span><span class="nb">O </span><span class="o">(</span><span class="nb">whether using</span>
</div><div id="l606" class="code_block"><span class="nb">the stream I</span><span class="o">/</span><span class="nb">O predicates or the predicates described here</span><span class="o">)</span><span class="nb">, so XSB I</span><span class="o">/</span><span class="nb">O</span>
</div><div id="l607" class="code_block"><span class="nb">ports internally refer to {</span><span class="nv">\tt</span><span class="nb"> FILE} data structures </span><span class="o">(</span><span class="nb">those returned by the</span>
</div><div id="l608" class="code_block"><span class="nb">C {</span><span class="nv">\tt</span><span class="nb"> fopen} function</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l609" class="code_block">
</div><div id="l610" class="code_block"><span class="nb">When it starts, XSB opens a number of standard I</span><span class="o">/</span><span class="nb">O ports that it uses to</span>
</div><div id="l611" class="code_block"><span class="nb">print results, errors, debugging info, etc. The descriptors are described</span>
</div><div id="l612" class="code_block"><span class="nb">in the file {</span><span class="nv">\tt</span><span class="nb"> prolog</span><span class="nv">\_</span><span class="nb">includes</span><span class="o">/</span><span class="nb">standard.h}. This file provides the</span>
</div><div id="l613" class="code_block"><span class="nb">following symbolic definitions:</span>
</div><div id="l614" class="code_block"><span class="c">%%</span>
</div><div id="l615" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l616" class="code_block"><span class="nb">    #define STDIN            </span><span class="m">0</span>
</div><div id="l617" class="code_block"><span class="nb">    #define STDOUT           </span><span class="m">1</span>
</div><div id="l618" class="code_block"><span class="nb">    #define STDERR           </span><span class="m">2</span>
</div><div id="l619" class="code_block"><span class="nb">    #define STDWARN          </span><span class="m">3</span><span class="nb">    </span><span class="o">/*</span><span class="nb"> output stream for xsb warnings  </span><span class="o">*/</span>
</div><div id="l620" class="code_block"><span class="nb">    #define STDMSG           </span><span class="m">4</span><span class="nb">    </span><span class="o">/*</span><span class="nb"> output for regular xsb messages </span><span class="o">*/</span>
</div><div id="l621" class="code_block"><span class="nb">    #define STDDBG           </span><span class="m">5</span><span class="nb">    </span><span class="o">/*</span><span class="nb"> output for debugging info       </span><span class="o">*/</span>
</div><div id="l622" class="code_block"><span class="nb">    #define STDFDBK          </span><span class="m">6</span><span class="nb">    </span><span class="o">/*</span><span class="nb"> output for XSB feedback</span>
</div><div id="l623" class="code_block"><span class="nb">                                     </span><span class="o">(</span><span class="nb">prompt</span><span class="o">/</span><span class="nb">yes</span><span class="o">/</span><span class="nb">no</span><span class="o">/</span><span class="nb">Aborting</span><span class="o">/</span><span class="nb">answers</span><span class="o">)</span><span class="nb"> </span><span class="o">*/</span>
</div><div id="l624" class="code_block">
</div><div id="l625" class="code_block"><span class="nb">    #define AF_INET     </span><span class="m">0</span><span class="nb">     </span><span class="o">/*</span><span class="nb"> XSB</span><span class="o">-</span><span class="nb">side socket request for Internet domain </span><span class="o">*/</span>
</div><div id="l626" class="code_block"><span class="nb">    #define AF_UNIX     </span><span class="m">1</span><span class="nb">     </span><span class="o">/*</span><span class="nb"> XSB</span><span class="o">-</span><span class="nb">side socket request for UNIX domain </span><span class="o">*/</span>
</div><div id="l627" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l628" class="code_block"><span class="c">%%</span>
</div><div id="l629" class="code_block"><span class="nb">In addition, the file </span><span class="nv">\verb</span><span class="nb">|emu</span><span class="o">/</span><span class="nb">file_modes_xsb.h| provides the definitions</span>
</div><div id="l630" class="code_block"><span class="nb">for the file opening modes:</span>
</div><div id="l631" class="code_block"><span class="c">%%</span>
</div><div id="l632" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l633" class="code_block"><span class="nb">    #define OREAD          </span><span class="m">0</span><span class="nb">    </span><span class="o">/*</span><span class="nb"> open for read           </span><span class="o">*/</span>
</div><div id="l634" class="code_block"><span class="nb">    #define OWRITE         </span><span class="m">1</span><span class="nb">    </span><span class="o">/*</span><span class="nb"> open for write          </span><span class="o">*/</span>
</div><div id="l635" class="code_block"><span class="nb">    #define OAPPEND        </span><span class="m">2</span><span class="nb">    </span><span class="o">/*</span><span class="nb"> open for append         </span><span class="o">*/</span>
</div><div id="l636" class="code_block"><span class="nb">    #define OSTRINGR       </span><span class="m">3</span><span class="nb">    </span><span class="o">/*</span><span class="nb"> open string for reading </span><span class="o">*/</span>
</div><div id="l637" class="code_block"><span class="nb">    #define OSTRINGW       </span><span class="m">4</span><span class="nb">    </span><span class="o">/*</span><span class="nb"> open string for writing </span><span class="o">(</span><span class="nb">not implemented</span><span class="o">)</span><span class="nb"> </span><span class="o">*/</span>
</div><div id="l638" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l639" class="code_block"><span class="c">%%</span>
</div><div id="l640" class="code_block"><span class="nb">These definitions can be used in user programs, if the following is</span>
</div><div id="l641" class="code_block"><span class="nb">provided at the top of the source file:</span>
</div><div id="l642" class="code_block"><span class="c">%%</span>
</div><div id="l643" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l644" class="code_block"><span class="nb">    compiler_options</span><span class="o">([</span><span class="nb">xpp_on</span><span class="o">])</span><span class="nb">.</span>
</div><div id="l645" class="code_block"><span class="nb">    #include &quot;standard.h&quot;</span>
</div><div id="l646" class="code_block"><span class="nb">    #include &quot;file_modes_xsb.h&quot;</span>
</div><div id="l647" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l648" class="code_block"><span class="c">%%</span>
</div><div id="l649" class="code_block"><span class="o">(</span><span class="nb">Note: the XSB preprocessor is not invoked on clauses typed into an</span>
</div><div id="l650" class="code_block"><span class="nb">interactive XSB session, so the above applies only to programs loaded from</span>
</div><div id="l651" class="code_block"><span class="nb">a file using {</span><span class="nv">\tt</span><span class="nb"> consult} and such.</span><span class="o">)</span>
</div><div id="l652" class="code_block">
</div><div id="l653" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l654" class="code_block">
</div><div id="l655" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{current</span><span class="nv">\_</span><span class="nb">input</span><span class="nv">\_</span><span class="nb">port</span><span class="o">(-</span><span class="nb">IOport</span><span class="o">)</span><span class="nb">}{curr</span><span class="nv">\_</span><span class="nb">sym} </span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> current</span><span class="nv">\_</span><span class="nb">input</span><span class="nv">\_</span><span class="nb">port</span><span class="o">/</span><span class="nb">}}</span>
</div><div id="l656" class="code_block"><span class="nb">   See {</span><span class="nv">\tt</span><span class="nb"> current</span><span class="nv">\_</span><span class="nb">output</span><span class="nv">\_</span><span class="nb">port</span><span class="o">/</span><span class="m">1</span><span class="nb">}.</span>
</div><div id="l657" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{current</span><span class="nv">\_</span><span class="nb">output</span><span class="nv">\_</span><span class="nb">port</span><span class="o">(-</span><span class="nb">IOport</span><span class="o">)</span><span class="nb">}{curr</span><span class="nv">\_</span><span class="nb">sym} </span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> current</span><span class="nv">\_</span><span class="nb">output</span><span class="nv">\_</span><span class="nb">port</span><span class="o">/</span><span class="nb">}}</span>
</div><div id="l658" class="code_block"><span class="nb">   The above two predicates instantiate {</span><span class="nv">\tt</span><span class="nb"> IOport} to the XSB I</span><span class="o">/</span><span class="nb">O port</span>
</div><div id="l659" class="code_block"><span class="nb">   for the current user input and output </span><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> i.e.}, the things </span>
</div><div id="l660" class="code_block"><span class="nb">   that are manipulated through {</span><span class="nv">\tt</span><span class="nb"> see</span><span class="o">/</span><span class="nb">seen} and {</span><span class="nv">\tt</span><span class="nb"> tell</span><span class="o">/</span><span class="nb">told} predicates</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l661" class="code_block"><span class="nb">   Once the I</span><span class="o">/</span><span class="nb">O port is obtained, it is possible to safely use the</span>
</div><div id="l662" class="code_block"><span class="nb">   lower</span><span class="o">-</span><span class="nb">level I</span><span class="o">/</span><span class="nb">O predicates described below interchangeably with stream</span>
</div><div id="l663" class="code_block"><span class="nb">   I</span><span class="o">/</span><span class="nb">O. </span>
</div><div id="l664" class="code_block"><span class="nb">    </span>
</div><div id="l665" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">open</span><span class="o">(+</span><span class="nb">FileName,</span><span class="o">+</span><span class="nb">Mode,</span><span class="o">-</span><span class="nb">IOport</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io} </span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">open</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l666" class="code_block"><span class="nb">    Opens a file with name {</span><span class="nv">\tt</span><span class="nb"> FileName} to be accessed</span>
</div><div id="l667" class="code_block"><span class="nb">    in mode {</span><span class="nv">\tt</span><span class="nb"> Mode} and returns a file</span><span class="o">-</span><span class="nb">descriptor in {</span><span class="nv">\tt</span><span class="nb"> IOport} that</span>
</div><div id="l668" class="code_block"><span class="nb">    can be used to access the file.  If {</span><span class="nv">\tt</span><span class="nb"> Mode} is atom ``{</span><span class="nv">\tt</span><span class="nb"> r}&#39;&#39;, the</span>
</div><div id="l669" class="code_block"><span class="nb">    the file is opened for reading; if it is ``{</span><span class="nv">\tt</span><span class="nb"> w}&#39;&#39;, the file is</span>
</div><div id="l670" class="code_block"><span class="nb">    opened for writing; if it is ``{</span><span class="nv">\tt</span><span class="nb"> a}&#39;&#39;, the file is opened for</span>
</div><div id="l671" class="code_block"><span class="nb">    appending.  If {</span><span class="nv">\tt</span><span class="nb"> Mode} is ``{</span><span class="nv">\tt</span><span class="nb"> sr}&#39;&#39;, then the string making</span>
</div><div id="l672" class="code_block"><span class="nb">    up the atom {</span><span class="nv">\tt</span><span class="nb"> FileName} is treated as the contents of the file, and</span>
</div><div id="l673" class="code_block"><span class="nb">    a descriptor is returned that allows ``file&#39;&#39; access to that string.</span>
</div><div id="l674" class="code_block"><span class="nb">    This is how one can use XSB&#39;s term I</span><span class="o">/</span><span class="nb">O routines to build terms from</span>
</div><div id="l675" class="code_block"><span class="nb">    atoms. Mode ``{</span><span class="nv">\tt</span><span class="nb"> sw}&#39;&#39; is reserved for ``open string for writing,&#39;&#39;</span>
</div><div id="l676" class="code_block"><span class="nb">    but this has not been implemented as of yet.</span>
</div><div id="l677" class="code_block">
</div><div id="l678" class="code_block"><span class="nb">    The old</span><span class="o">-</span><span class="nb">style mode specification, </span><span class="m">0</span><span class="nb"> </span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> OREAD}</span><span class="o">)</span><span class="nb">, </span><span class="m">1</span><span class="nb"> </span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> OWRITE}</span><span class="o">)</span><span class="nb">, </span><span class="m">2</span>
</div><div id="l679" class="code_block"><span class="nb">    </span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> OAPPEND}</span><span class="o">)</span><span class="nb">, or </span><span class="m">3</span><span class="nb"> </span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> OSTRING}</span><span class="o">)</span><span class="nb">, is also supported.</span>
</div><div id="l680" class="code_block">
</div><div id="l681" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">reopen</span><span class="o">(+</span><span class="nb">FileName,</span><span class="o">+</span><span class="nb">Mode,</span><span class="o">+</span><span class="nb">IOport,</span><span class="o">-</span><span class="nb">RetCode</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">reopen</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l682" class="code_block"><span class="nb">    Takes an existing I</span><span class="o">/</span><span class="nb">O port, closes it, then opens it and</span>
</div><div id="l683" class="code_block"><span class="nb">    attaches it to a file. This can be used to redirect I</span><span class="o">/</span><span class="nb">O from any of the</span>
</div><div id="l684" class="code_block"><span class="nb">    standard streams to a file. For instance, </span>
</div><div id="l685" class="code_block"><span class="c">%%</span>
</div><div id="l686" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l687" class="code_block"><span class="nb">    | ?</span><span class="o">-</span><span class="nb"> file_reopen</span><span class="o">(</span><span class="nb">&#39;</span><span class="o">/</span><span class="nb">dev</span><span class="o">/</span><span class="nb">null&#39;, w, </span><span class="m">3</span><span class="nb">, Error</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l688" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l689" class="code_block"><span class="c">%%</span>
</div><div id="l690" class="code_block"><span class="nb">    redirects all warnings to the Unix black hole. </span>
</div><div id="l691" class="code_block">
</div><div id="l692" class="code_block"><span class="nb">    On success, {</span><span class="nv">\tt</span><span class="nb"> RetCode} is </span><span class="m">0</span><span class="nb">; on error, the return code is negative.</span>
</div><div id="l693" class="code_block">
</div><div id="l694" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{tmpfile</span><span class="nv">\_</span><span class="nb">open</span><span class="o">(-</span><span class="nb">IOport</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> tmpfile</span><span class="nv">\_</span><span class="nb">open</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l695" class="code_block"><span class="nb">    Opens a temporary file with a unique filename. The file is deleted when</span>
</div><div id="l696" class="code_block"><span class="nb">    it is closed or when the program terminates.</span>
</div><div id="l697" class="code_block">
</div><div id="l698" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">clone</span><span class="o">(+</span><span class="nb">SrcIOport,?DestIOport,</span><span class="o">-</span><span class="nb">RetCode</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">clone</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l699" class="code_block"><span class="nb">    This is yet another way to redirect I</span><span class="o">/</span><span class="nb">O. It is a prolog interface to</span>
</div><div id="l700" class="code_block"><span class="nb">    the C {</span><span class="nv">\tt</span><span class="nb"> dup} and {</span><span class="nv">\tt</span><span class="nb"> dup</span><span class="m">2</span><span class="nb">} system calls. If {</span><span class="nv">\tt</span><span class="nb"> DestIOport} is a</span>
</div><div id="l701" class="code_block"><span class="nb">    variable, then this call creates a new XSB I</span><span class="o">/</span><span class="nb">O port that is a</span>
</div><div id="l702" class="code_block"><span class="nb">    clone of {</span><span class="nv">\tt</span><span class="nb"> SrcIOport}. This means that I</span><span class="o">/</span><span class="nb">O sent to either</span>
</div><div id="l703" class="code_block"><span class="nb">    descriptor goes to the same place. If {</span><span class="nv">\tt</span><span class="nb"> DestIOport} is not a</span>
</div><div id="l704" class="code_block"><span class="nb">    variable, then it must be a number corresponding to a valid I</span><span class="o">/</span><span class="nb">O</span>
</div><div id="l705" class="code_block"><span class="nb">    port. In this case, XSB closes {</span><span class="nv">\tt</span><span class="nb"> DestIOport} and makes it </span>
</div><div id="l706" class="code_block"><span class="nb">    into a clone on {</span><span class="nv">\tt</span><span class="nb"> SrcIOport}. For instance, suppose that </span><span class="m">10</span><span class="nb"> is a</span>
</div><div id="l707" class="code_block"><span class="nb">    I</span><span class="o">/</span><span class="nb">O port that is currently open for writing to file {</span><span class="nv">\tt</span><span class="nb"> foo.bar}.</span>
</div><div id="l708" class="code_block"><span class="nb">    Then</span>
</div><div id="l709" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l710" class="code_block"><span class="nb">    </span><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l711" class="code_block"><span class="nb">    | ?</span><span class="o">-</span><span class="nb"> file_clone</span><span class="o">(</span><span class="m">10</span><span class="nb">,</span><span class="m">3</span><span class="nb">,_</span><span class="o">)</span><span class="nb">.      </span>
</div><div id="l712" class="code_block"><span class="nb">    </span><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l713" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l714" class="code_block"><span class="nb">    causes all messages sent to XSB standard warnings port to go to file</span>
</div><div id="l715" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> foo.bar}. While this could be also done with {</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">reopen},</span>
</div><div id="l716" class="code_block"><span class="nb">    there are things that only {</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">clone} can do:</span>
</div><div id="l717" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l718" class="code_block"><span class="nb">    </span><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l719" class="code_block"><span class="nb">    | ?</span><span class="o">-</span><span class="nb"> file_clone</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">10</span><span class="nb">,_</span><span class="o">)</span><span class="nb">.      </span>
</div><div id="l720" class="code_block"><span class="nb">    </span><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l721" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l722" class="code_block"><span class="nb">    This means that I</span><span class="o">/</span><span class="nb">O port </span><span class="m">10</span><span class="nb"> now becomes clone of standard</span>
</div><div id="l723" class="code_block"><span class="nb">    output. So, all subsequent I</span><span class="o">/</span><span class="nb">O will now go to standard output instead</span>
</div><div id="l724" class="code_block"><span class="nb">    of {</span><span class="nv">\tt</span><span class="nb"> foo.bar}. </span>
</div><div id="l725" class="code_block">
</div><div id="l726" class="code_block"><span class="nb">    On success, {</span><span class="nv">\tt</span><span class="nb"> RetCode} is </span><span class="m">0</span><span class="nb">; on error, the return code is negative.</span>
</div><div id="l727" class="code_block">
</div><div id="l728" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">close</span><span class="o">(+</span><span class="nb">IOport</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">close</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l729" class="code_block"><span class="nb">    Closes the file </span><span class="o">(</span><span class="nb">or string</span><span class="o">)</span><span class="nb"> for descriptor {</span><span class="nv">\tt</span><span class="nb"> IOport}.</span>
</div><div id="l730" class="code_block">
</div><div id="l731" class="code_block"><span class="nb">    </span><span class="nv">\newpage</span>
</div><div id="l732" class="code_block"><span class="nb">    </span><span class="nv">\samepage</span><span class="nb">{</span>
</div><div id="l733" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{fmt</span><span class="nv">\_</span><span class="nb">read</span><span class="o">(+</span><span class="nb">Fmt,</span><span class="o">-</span><span class="nb">Term,</span><span class="o">-</span><span class="nb">Ret</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> fmt</span><span class="nv">\_</span><span class="nb">read</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l734" class="code_block"><span class="nv">\vspace</span><span class="nb">{</span><span class="o">-</span><span class="m">7</span><span class="nb">mm}</span>
</div><div id="l735" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{fmt</span><span class="nv">\_</span><span class="nb">read</span><span class="o">(+</span><span class="nb">IOport,</span><span class="o">+</span><span class="nb">Fmt,</span><span class="o">-</span><span class="nb">Term,</span><span class="o">-</span><span class="nb">Ret</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> fmt</span><span class="nv">\_</span><span class="nb">read</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l736" class="code_block"><span class="nb">}</span>
</div><div id="l737" class="code_block"><span class="nb">    These predicates provides a routine for reading data from</span>
</div><div id="l738" class="code_block"><span class="nb">    the current input file </span><span class="o">(</span><span class="nb">which must have been already opened by using</span>
</div><div id="l739" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> see</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span><span class="o">)</span><span class="nb"> according to a C format, as used in the C function</span>
</div><div id="l740" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> scanf}. To use it, it must be imported from the module {</span><span class="nv">\tt</span>
</div><div id="l741" class="code_block"><span class="nb">    file</span><span class="nv">\_</span><span class="nb">io}.  {</span><span class="nv">\tt</span><span class="nb"> Fmt} must be a string of characters </span><span class="o">(</span><span class="nb">enclosed in &quot;&quot;</span><span class="o">)</span>
</div><div id="l742" class="code_block"><span class="nb">    representing the format that </span>
</div><div id="l743" class="code_block"><span class="nb">    will be passed to the C call to {</span><span class="nv">\tt</span><span class="nb"> scanf}.  See the C</span>
</div><div id="l744" class="code_block"><span class="nb">    documentation for {</span><span class="nv">\tt</span><span class="nb"> scanf} for the meaning of this string.</span>
</div><div id="l745" class="code_block"><span class="nb">    The usual alphabetical C escape characters </span><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> e.g.}, </span><span class="s">$</span><span class="k">\backslash</span> n<span class="s">$</span><span class="o">)</span>
</div><div id="l746" class="code_block"><span class="nb">    are recognized, but not the octal or the hexadecimal ones.</span>
</div><div id="l747" class="code_block"><span class="nb">    Another difference with C is that, unlike most C compilers, XSB insists</span>
</div><div id="l748" class="code_block"><span class="nb">    that a single {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%</span><span class="nb">} in the format string signifies format conversion</span>
</div><div id="l749" class="code_block"><span class="nb">    specification. </span><span class="o">(</span><span class="nb">Some C compilers might output {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%</span><span class="nb">} if it is not</span>
</div><div id="l750" class="code_block"><span class="nb">    followed by a valid type conversion spec.</span><span class="o">)</span><span class="nb"> So, to output {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%</span><span class="nb">}</span>
</div><div id="l751" class="code_block"><span class="nb">    you must type {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%\%</span><span class="nb">}.</span>
</div><div id="l752" class="code_block"><span class="nb">    Format can also be an atom enclosed in single quotes. However, in that</span>
</div><div id="l753" class="code_block"><span class="nb">    case, escape sequences are not recognized and are printed as is.</span>
</div><div id="l754" class="code_block">
</div><div id="l755" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Term} is a term </span><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> e.g.}, {</span><span class="nv">\tt</span><span class="nb"> args</span><span class="o">(</span><span class="nb">X,Y,Z</span><span class="o">)</span><span class="nb">}</span><span class="o">)</span><span class="nb">  whose arguments</span>
</div><div id="l756" class="code_block"><span class="nb">    will be unified with the field values read in.  </span><span class="o">(</span><span class="nb">The functor symbol of {</span><span class="nv">\tt</span>
</div><div id="l757" class="code_block"><span class="nb">    Term} is ignored.</span><span class="o">)</span><span class="nb">  Special syntactic sugar is provided for the case</span>
</div><div id="l758" class="code_block"><span class="nb">    when the format string contains only one format specifier: If {</span><span class="nv">\tt</span>
</div><div id="l759" class="code_block"><span class="nb">    Term} is a variable, {</span><span class="nv">\tt</span><span class="nb"> X}, then the predicate behaves as if {</span><span class="nv">\tt</span>
</div><div id="l760" class="code_block"><span class="nb">    Term} were {</span><span class="nv">\tt</span><span class="nb"> arg</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">}.</span>
</div><div id="l761" class="code_block">
</div><div id="l762" class="code_block"><span class="nb">  If the number of arguments exceeds the number of format specifiers, a</span>
</div><div id="l763" class="code_block"><span class="nb">  warning is produced and the extra arguments remain uninstantiated.</span>
</div><div id="l764" class="code_block"><span class="nb">  If the number of format specifiers exceeds the number of arguments, then</span>
</div><div id="l765" class="code_block"><span class="nb">  the remainder of the format string </span><span class="o">(</span><span class="nb">after the last matching specifier</span><span class="o">)</span><span class="nb"> is</span>
</div><div id="l766" class="code_block"><span class="nb">  ignored.</span>
</div><div id="l767" class="code_block"><span class="nb">  </span>
</div><div id="l768" class="code_block"><span class="nb">  Note that floats do not unify with anything.  {</span><span class="nv">\tt</span><span class="nb"> Ret} must be a</span>
</div><div id="l769" class="code_block"><span class="nb">  variable and it will be assigned a return value by the predicate: a</span>
</div><div id="l770" class="code_block"><span class="nb">  negative integer if end</span><span class="o">-</span><span class="nb">of</span><span class="o">-</span><span class="nb">file is encountered; otherwise the number of</span>
</div><div id="l771" class="code_block"><span class="nb">  fields read </span><span class="o">(</span><span class="nb">as returned by {</span><span class="nv">\tt</span><span class="nb"> scanf}.</span><span class="o">)</span>
</div><div id="l772" class="code_block"><span class="nb">  </span>
</div><div id="l773" class="code_block"><span class="nb">  {</span><span class="nv">\tt</span><span class="nb"> fmt</span><span class="nv">\_</span><span class="nb">read} cannot read strings </span><span class="o">(</span><span class="nb">that correspond to the {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%</span><span class="nb">s}</span>
</div><div id="l774" class="code_block"><span class="nb">  format specifier</span><span class="o">)</span><span class="nb"> that are longer than </span><span class="m">16</span><span class="nb">K. Attempting to read longer</span>
</div><div id="l775" class="code_block"><span class="nb">  strings will cause buffer overflow. It is therefore recommended that one</span>
</div><div id="l776" class="code_block"><span class="nb">  should use size modifiers in format strings </span><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> e.g.}, {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%</span><span class="m">2000</span><span class="nb">s}</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l777" class="code_block"><span class="nb">  if such long strings might occur in the input.</span>
</div><div id="l778" class="code_block">
</div><div id="l779" class="code_block"><span class="nb">  </span><span class="nv">\samepage</span><span class="nb">{</span>
</div><div id="l780" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{fmt</span><span class="nv">\_</span><span class="nb">write</span><span class="o">(+</span><span class="nb">Fmt,</span><span class="o">+</span><span class="nb">Term</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> fmt</span><span class="nv">\_</span><span class="nb">write</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l781" class="code_block"><span class="nv">\vspace</span><span class="nb">{</span><span class="o">-</span><span class="m">7</span><span class="nb">mm}</span>
</div><div id="l782" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{fmt</span><span class="nv">\_</span><span class="nb">write</span><span class="o">(+</span><span class="nb">IOport,</span><span class="o">+</span><span class="nb">Fmt,</span><span class="o">+</span><span class="nb">Term</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> fmt</span><span class="nv">\_</span><span class="nb">write</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l783" class="code_block"><span class="nb">}</span>
</div><div id="l784" class="code_block"><span class="nb">    This predicate provides a routine for writing data to</span>
</div><div id="l785" class="code_block"><span class="nb">    the current output file </span><span class="o">(</span><span class="nb">which must have been already opened by using</span>
</div><div id="l786" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> tell</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span><span class="o">)</span><span class="nb"> according to a C format, as used in the C function</span>
</div><div id="l787" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> printf}.</span>
</div><div id="l788" class="code_block"><span class="nb">    To use it, it must be imported from the module {</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">io}.</span>
</div><div id="l789" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Fmt} must be a string of characters </span><span class="o">(</span><span class="nb">enclosed in &quot;&quot;</span><span class="o">)</span>
</div><div id="l790" class="code_block"><span class="nb">    representing the format that </span>
</div><div id="l791" class="code_block"><span class="nb">    will be passed to the C call to {</span><span class="nv">\tt</span><span class="nb"> scanf}.  See the C</span>
</div><div id="l792" class="code_block"><span class="nb">    documentation for {</span><span class="nv">\tt</span><span class="nb"> scanf} for the meaning of this string.</span>
</div><div id="l793" class="code_block"><span class="nb">    The usual alphabetical C escape characters </span><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> e.g.}, </span><span class="s">$</span><span class="k">\backslash</span> n<span class="s">$</span><span class="o">)</span>
</div><div id="l794" class="code_block"><span class="nb">    are recognized, but not the octal or the hexadecimal ones.</span>
</div><div id="l795" class="code_block">
</div><div id="l796" class="code_block"><span class="nb">    In addition to the usual C conversion specifiers, {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%</span><span class="nb">S} is also</span>
</div><div id="l797" class="code_block"><span class="nb">    allowed. The corresponding argument can be any Prolog term. This</span>
</div><div id="l798" class="code_block"><span class="nb">    provides an easy way to print the values of Prolog variables, etc.</span>
</div><div id="l799" class="code_block">
</div><div id="l800" class="code_block"><span class="nb">    Another difference with C is that, unlike most C compilers, XSB insists</span>
</div><div id="l801" class="code_block"><span class="nb">    that a single {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%</span><span class="nb">} in the format string signifies format conversion</span>
</div><div id="l802" class="code_block"><span class="nb">    specification. </span><span class="o">(</span><span class="nb">Some C compilers might output {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%</span><span class="nb">} if it is not</span>
</div><div id="l803" class="code_block"><span class="nb">    followed by a valid type conversion spec.</span><span class="o">)</span><span class="nb"> So, to output {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%</span><span class="nb">}</span>
</div><div id="l804" class="code_block"><span class="nb">    you must type {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\%\%</span><span class="nb">}.</span>
</div><div id="l805" class="code_block"><span class="nb">    </span>
</div><div id="l806" class="code_block"><span class="nb">    Format can also be an atom, but then escape sequences are not</span>
</div><div id="l807" class="code_block"><span class="nb">    recognized.</span>
</div><div id="l808" class="code_block">
</div><div id="l809" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Term} is a term </span><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> e.g.}, {</span><span class="nv">\tt</span><span class="nb"> args</span><span class="o">(</span><span class="nb">X,Y,Z</span><span class="o">)</span><span class="nb">}</span><span class="o">)</span><span class="nb"> whose arguments</span>
</div><div id="l810" class="code_block"><span class="nb">    will be output. The functor symbol of {</span><span class="nv">\tt</span><span class="nb"> Term} is ignored.</span>
</div><div id="l811" class="code_block"><span class="nb">    </span>
</div><div id="l812" class="code_block"><span class="nb">    Special syntactic sugar is provided for the following cases: If {</span><span class="nv">\tt</span>
</div><div id="l813" class="code_block"><span class="nb">      Term} is a variable, {</span><span class="nv">\tt</span><span class="nb"> X}, then it is ignored and only the format</span>
</div><div id="l814" class="code_block"><span class="nb">    string is printed. If {</span><span class="nv">\tt</span><span class="nb"> Term} is a string, integer or a float, then</span>
</div><div id="l815" class="code_block"><span class="nb">    it is assumed that this is the only argument to be printed, {</span><span class="nv">\it</span><span class="nb"> i.e.},</span>
</div><div id="l816" class="code_block"><span class="nb">    it is equivalent to specifying {</span><span class="nv">\tt</span><span class="nb"> arg</span><span class="o">(</span><span class="nb">Term</span><span class="o">)</span><span class="nb">}.</span>
</div><div id="l817" class="code_block">
</div><div id="l818" class="code_block"><span class="nb">    If the number of format specifiers is greater than the number of</span>
</div><div id="l819" class="code_block"><span class="nb">    arguments to be printed, an error is issued. If the number of arguments</span>
</div><div id="l820" class="code_block"><span class="nb">    is greater, then a warning is issued.</span>
</div><div id="l821" class="code_block">
</div><div id="l822" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{fmt</span><span class="nv">\_</span><span class="nb">write</span><span class="nv">\_</span><span class="nb">string</span><span class="o">(-</span><span class="nb">String,</span><span class="o">+</span><span class="nb">Fmt,</span><span class="o">+</span><span class="nb">Term</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l823" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> fmt</span><span class="nv">\_</span><span class="nb">write</span><span class="nv">\_</span><span class="nb">string</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l824" class="code_block"><span class="nb">    This predicate works like the C function {</span><span class="nv">\tt</span><span class="nb"> sprintf}. It takes the</span>
</div><div id="l825" class="code_block"><span class="nb">    format string and substitutes the values from the arguments of {</span><span class="nv">\tt</span>
</div><div id="l826" class="code_block"><span class="nb">      Term} </span><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> e.g.}, {</span><span class="nv">\tt</span><span class="nb"> args</span><span class="o">(</span><span class="nb">X,Y,Z</span><span class="o">)</span><span class="nb">}</span><span class="o">)</span><span class="nb"> for the formatting instructions</span>
</div><div id="l827" class="code_block"><span class="nb">    </span><span class="nv">\%</span><span class="nb">s, </span><span class="nv">\%</span><span class="nb">d, etc. Additional syntactic sugar, as in </span><span class="nv">\verb</span><span class="nb">|fmt_write|, is</span>
</div><div id="l828" class="code_block"><span class="nb">    recognized. The result is available in {</span><span class="nv">\tt</span><span class="nb"> String}. {</span><span class="nv">\tt</span><span class="nb"> Fmt} is a</span>
</div><div id="l829" class="code_block"><span class="nb">    string or an atom that represents the format, as in</span>
</div><div id="l830" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> fmt</span><span class="nv">\_</span><span class="nb">write}.</span>
</div><div id="l831" class="code_block"><span class="nb">    </span>
</div><div id="l832" class="code_block"><span class="nb">    If the number of format specifiers is greater than the number of</span>
</div><div id="l833" class="code_block"><span class="nb">    arguments to be printed, an error is issued. If the number of arguments</span>
</div><div id="l834" class="code_block"><span class="nb">    is greater, then a warning is issued.</span>
</div><div id="l835" class="code_block">
</div><div id="l836" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> fmt</span><span class="nv">\_</span><span class="nb">write</span><span class="nv">\_</span><span class="nb">string} requires that the printed size of each</span>
</div><div id="l837" class="code_block"><span class="nb">    argument </span><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> e.g.}, X,Y,and Z above</span><span class="o">)</span><span class="nb"> must be less than </span><span class="m">16</span><span class="nb">K. Longer</span>
</div><div id="l838" class="code_block"><span class="nb">    arguments are cut to that size, so some loss of information is possible.</span>
</div><div id="l839" class="code_block"><span class="nb">    However, there is no limit on the total size of the output </span><span class="o">(</span><span class="nb">apart from</span>
</div><div id="l840" class="code_block"><span class="nb">    the maximum atom size imposed by XSB</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l841" class="code_block">
</div><div id="l842" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">flush</span><span class="o">(+</span><span class="nb">IOport, </span><span class="o">-</span><span class="nb">Return</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l843" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">flush</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l844" class="code_block"><span class="nb">    Any buffered data gets delivered. If the call is successful, {</span><span class="nv">\tt</span><span class="nb"> Return}</span>
</div><div id="l845" class="code_block"><span class="nb">    is zero; otherwise {</span><span class="nv">\tt</span><span class="nb"> EOF} is returned.</span>
</div><div id="l846" class="code_block">
</div><div id="l847" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">seek</span><span class="o">(+</span><span class="nb">IOport, </span><span class="o">+</span><span class="nb">Offset, </span><span class="o">+</span><span class="nb">Place, </span><span class="o">-</span><span class="nb">Return</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l848" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">seek</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l849" class="code_block"><span class="nb">    Sets the file position indicator for the next input or output</span>
</div><div id="l850" class="code_block"><span class="nb">    operation. The position is {</span><span class="nv">\tt</span><span class="nb"> Offset} bytes from {</span><span class="nv">\tt</span><span class="nb"> Place}.</span>
</div><div id="l851" class="code_block"><span class="nb">    The value of {</span><span class="nv">\tt</span><span class="nb"> Place} can be </span><span class="m">0</span><span class="nb">, </span><span class="m">1</span><span class="nb">, or </span><span class="m">2</span><span class="nb">, which correspond to</span>
</div><div id="l852" class="code_block"><span class="nb">    the beginning of the file, the current position in the file, or</span>
</div><div id="l853" class="code_block"><span class="nb">    the end of the file, respectively. If the call is successful,</span>
</div><div id="l854" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Return} is set to zero.</span>
</div><div id="l855" class="code_block">
</div><div id="l856" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">pos</span><span class="o">(+</span><span class="nb">IOport, </span><span class="o">-</span><span class="nb">Position</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l857" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">pos</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l858" class="code_block"><span class="nb">    Unifies {</span><span class="nv">\tt</span><span class="nb"> Position} with the position inside the file indicated by</span>
</div><div id="l859" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> IOport}.</span>
</div><div id="l860" class="code_block">
</div><div id="l861" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">truncate</span><span class="o">(+</span><span class="nb">IOport, </span><span class="o">+</span><span class="nb">Length, </span><span class="o">-</span><span class="nb">Return</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l862" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">truncate</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l863" class="code_block"><span class="nb">    The regular file  referenced by the I</span><span class="o">/</span><span class="nb">O port {</span><span class="nv">\tt</span><span class="nb"> IOport}</span>
</div><div id="l864" class="code_block"><span class="nb">    is chopped to have the size of {</span><span class="nv">\tt</span><span class="nb"> Length} bytes. Upon successful</span>
</div><div id="l865" class="code_block"><span class="nb">    completion {</span><span class="nv">\tt</span><span class="nb"> Return} is set to zero.</span>
</div><div id="l866" class="code_block">
</div><div id="l867" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">write</span><span class="o">(+</span><span class="nb">IOport,</span><span class="o">+</span><span class="nb">Term</span><span class="o">)</span><span class="nb">}{xsb</span><span class="nv">\_</span><span class="nb">writ}</span>
</div><div id="l868" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">write</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l869" class="code_block"><span class="nb">    Writes the term {</span><span class="nv">\tt</span><span class="nb"> Term} to the file </span><span class="o">(</span><span class="nb">or string</span><span class="o">)</span><span class="nb"> with descriptor {</span><span class="nv">\tt</span>
</div><div id="l870" class="code_block"><span class="nb">    IOport}.</span>
</div><div id="l871" class="code_block">
</div><div id="l872" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">read</span><span class="o">(+</span><span class="nb">IOport,</span><span class="o">-</span><span class="nb">Term</span><span class="o">)</span><span class="nb">}{xsb</span><span class="nv">\_</span><span class="nb">read}</span>
</div><div id="l873" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">read</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l874" class="code_block"><span class="nb">    Reads a term from the file </span><span class="o">(</span><span class="nb">or string</span><span class="o">)</span><span class="nb"> with descriptor {</span><span class="nv">\tt</span>
</div><div id="l875" class="code_block"><span class="nb">    IOport} into {</span><span class="nv">\tt</span><span class="nb"> Term}.  Note that the term must be terminated</span>
</div><div id="l876" class="code_block"><span class="nb">    with a period </span><span class="o">(</span><span class="nb">.</span><span class="o">)</span><span class="nb"> </span><span class="o">(</span><span class="nb">whether it appears in a file or in a string.</span><span class="o">)</span>
</div><div id="l877" class="code_block">
</div><div id="l878" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">read</span><span class="o">(+</span><span class="nb">IOport,</span><span class="o">-</span><span class="nb">Term,</span><span class="o">-</span><span class="nb">Vars</span><span class="o">)</span><span class="nb">}{xsb</span><span class="nv">\_</span><span class="nb">read}</span>
</div><div id="l879" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">read</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l880" class="code_block"><span class="nb">    Reads a term from the file </span><span class="o">(</span><span class="nb">or string</span><span class="o">)</span><span class="nb"> with descriptor {</span><span class="nv">\tt</span>
</div><div id="l881" class="code_block"><span class="nb">    IOport} into {</span><span class="nv">\tt</span><span class="nb"> Term}, and returns in {</span><span class="nv">\tt</span><span class="nb"> Vars} an open</span><span class="o">-</span><span class="nb">tailed list of</span>
</div><div id="l882" class="code_block"><span class="nb">    pairs of names of variables and the variables themselves that</span>
</div><div id="l883" class="code_block"><span class="nb">    appear in Term.  For example, reading a term {</span><span class="nv">\tt</span><span class="nb"> f</span><span class="o">(</span><span class="nb">a,X,Y,X</span><span class="o">)</span><span class="nb">}</span>
</div><div id="l884" class="code_block"><span class="nb">    would result in {</span><span class="nv">\tt</span><span class="nb"> term} being bound to {</span><span class="nv">\tt</span>
</div><div id="l885" class="code_block"><span class="nb">    f</span><span class="o">(</span><span class="nb">a,</span><span class="nv">\_</span><span class="m">25</span><span class="nb">,</span><span class="nv">\_</span><span class="m">26</span><span class="nb">,</span><span class="nv">\_</span><span class="m">25</span><span class="o">)</span><span class="nb">} </span><span class="o">(</span><span class="nb">for some internal variables</span><span class="o">)</span><span class="nb"> and {</span><span class="nv">\tt</span><span class="nb"> Vars}</span>
</div><div id="l886" class="code_block"><span class="nb">    being bound to {</span><span class="o">[</span><span class="nb">vv</span><span class="o">(</span><span class="nb">&#39;X&#39;,</span><span class="nv">\_</span><span class="m">25</span><span class="o">)</span><span class="nb"> vv</span><span class="o">(</span><span class="nb">&#39;Y&#39;,</span><span class="nv">\_</span><span class="m">26</span><span class="o">)</span><span class="nb"> </span><span class="s">$</span><span class="k">\mid</span><span class="s">$</span><span class="nb"> </span><span class="nv">\_</span><span class="m">83</span><span class="o">]</span><span class="nb">}.  Note that the</span>
</div><div id="l887" class="code_block"><span class="nb">    pairing functor symbol is {</span><span class="nv">\tt</span><span class="nb"> vv</span><span class="o">/</span><span class="m">2</span><span class="nb">} and it must be imported from</span>
</div><div id="l888" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> xsb</span><span class="nv">\_</span><span class="nb">read} along with this read predicate.  Also note that </span>
</div><div id="l889" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Vars} is not a proper list, but has a free variable instead </span>
</div><div id="l890" class="code_block"><span class="nb">    of </span><span class="o">[]</span><span class="nb"> at its end.</span>
</div><div id="l891" class="code_block">
</div><div id="l892" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">canonical</span><span class="o">(+</span><span class="nb">IOport,</span><span class="o">-</span><span class="nb">Term,</span><span class="o">-</span><span class="nb">Psc</span><span class="o">)</span><span class="nb">}{machine}</span>
</div><div id="l893" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">canonical</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l894" class="code_block"><span class="nb">    Reads a term that is in canonical format from the the I</span><span class="o">/</span><span class="nb">O port</span>
</div><div id="l895" class="code_block"><span class="nb">    indicated by {</span><span class="nv">\tt</span><span class="nb"> IOport} </span><span class="o">(</span><span class="nb">as returned by {</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">open</span><span class="o">/</span><span class="m">3</span><span class="nb">} or</span>
</div><div id="l896" class="code_block"><span class="nb">    by {</span><span class="nv">\tt</span><span class="nb"> stat</span><span class="nv">\_</span><span class="nb">flag</span><span class="o">(</span><span class="m">10</span><span class="nb">,IOport</span><span class="o">))</span><span class="nb">}, and returns it in {</span><span class="nv">\tt</span><span class="nb"> Term}.</span>
</div><div id="l897" class="code_block"><span class="nb">    It also returns </span><span class="o">(</span><span class="nb">in {</span><span class="nv">\tt</span><span class="nb"> Psc}</span><span class="o">)</span><span class="nb"> the psc address of the main functor</span>
</div><div id="l898" class="code_block"><span class="nb">    symbol of the term, if it is the same as that of the previously</span>
</div><div id="l899" class="code_block"><span class="nb">    read term, and the current term is a ground </span><span class="o">(</span><span class="nb">non </span><span class="m">0</span><span class="o">-</span><span class="nb">ary</span><span class="o">)</span><span class="nb"> fact.</span>
</div><div id="l900" class="code_block"><span class="nb">    </span><span class="o">(</span><span class="nb">This is used for efficiency in the implementation of {</span><span class="nv">\tt</span>
</div><div id="l901" class="code_block"><span class="nb">    load</span><span class="nv">\_</span><span class="nb">dync</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span><span class="o">)</span><span class="nb">.  Otherwise {</span><span class="nv">\tt</span><span class="nb"> Psc} is set to </span><span class="m">0</span><span class="nb">.  To initialize</span>
</div><div id="l902" class="code_block"><span class="nb">    its previous psc value to zero, this predicate can be called with</span>
</div><div id="l903" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> IOport} of </span><span class="o">-</span><span class="m">1000</span><span class="nb">.</span>
</div><div id="l904" class="code_block">
</div><div id="l905" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">line</span><span class="o">(+</span><span class="nb">IOport,</span><span class="o">-</span><span class="nb">String</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l906" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">line</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l907" class="code_block"><span class="nb">    This is a low</span><span class="o">-</span><span class="nb">level predicate that allows XSB to read input files</span>
</div><div id="l908" class="code_block"><span class="nb">    efficiently, line by line. It returns the string read from {</span><span class="nv">\tt</span>
</div><div id="l909" class="code_block"><span class="nb">      IOport} using the variable {</span><span class="nv">\tt</span><span class="nb"> String}.</span>
</div><div id="l910" class="code_block">
</div><div id="l911" class="code_block"><span class="nb">    This predicate fails on reaching the end of file.</span>
</div><div id="l912" class="code_block"><span class="nb">    </span>
</div><div id="l913" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">line</span><span class="nv">\_</span><span class="nb">atom</span><span class="o">(+</span><span class="nb">IOport,</span><span class="o">-</span><span class="nb">String</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l914" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">line</span><span class="nv">\_</span><span class="nb">atom</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l915" class="code_block"><span class="nb">    This predicate is synonymous with </span><span class="nv">\verb</span><span class="nb">|file_read_line|.</span>
</div><div id="l916" class="code_block"><span class="nb">    </span>
</div><div id="l917" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">line</span><span class="nv">\_</span><span class="nb">atom</span><span class="o">(-</span><span class="nb">String</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l918" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">line</span><span class="nv">\_</span><span class="nb">atom</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l919" class="code_block"><span class="nb">   Like </span><span class="nv">\verb</span><span class="nb">|file_read_line_atom</span><span class="o">/</span><span class="m">3</span><span class="nb">|, but {</span><span class="nv">\tt</span><span class="nb"> IOport} is not required.</span>
</div><div id="l920" class="code_block"><span class="nb">   The file being read is the one previously opened with {</span><span class="nv">\tt</span><span class="nb"> see</span><span class="o">/</span><span class="m">1</span><span class="nb">}.</span>
</div><div id="l921" class="code_block">
</div><div id="l922" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">line</span><span class="nv">\_</span><span class="nb">list</span><span class="o">(+</span><span class="nb">IOport,</span><span class="o">-</span><span class="nb">CharList</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l923" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">line</span><span class="nv">\_</span><span class="nb">list</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l924" class="code_block"><span class="nb">    This predicate is like </span><span class="nv">\verb</span><span class="nb">|file_read_line_atom|, but the line read from</span>
</div><div id="l925" class="code_block"><span class="nb">    the input is converted into a list of characters.</span>
</div><div id="l926" class="code_block"><span class="nb">    This predicate is </span><span class="nv">\emph</span><span class="nb">{much} more efficient than {{</span><span class="nv">\tt</span><span class="nb"> fget</span><span class="nv">\_</span><span class="nb">line</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l927" class="code_block"><span class="nb">    </span><span class="o">(</span><span class="nb">see below</span><span class="o">)</span><span class="nb">, and is recommended when speed is important.</span>
</div><div id="l928" class="code_block"><span class="nb">    This predicate fails on reaching the end of file.</span>
</div><div id="l929" class="code_block">
</div><div id="l930" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">line</span><span class="nv">\_</span><span class="nb">list</span><span class="o">(-</span><span class="nb">String</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l931" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">read</span><span class="nv">\_</span><span class="nb">line</span><span class="nv">\_</span><span class="nb">list</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l932" class="code_block"><span class="nb">   Like </span><span class="nv">\verb</span><span class="nb">|file_read_line_list</span><span class="o">/</span><span class="m">3</span><span class="nb">|, but {</span><span class="nv">\tt</span><span class="nb"> IOport} is not required.</span>
</div><div id="l933" class="code_block"><span class="nb">   The file being read is the one previously opened with {</span><span class="nv">\tt</span><span class="nb"> see</span><span class="o">/</span><span class="m">1</span><span class="nb">}.</span>
</div><div id="l934" class="code_block">
</div><div id="l935" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{fget</span><span class="nv">\_</span><span class="nb">line</span><span class="o">(+</span><span class="nb">Str,</span><span class="o">-</span><span class="nb">Inlist,</span><span class="o">-</span><span class="nb">Next</span><span class="o">)</span><span class="nb">}{scrptutl}</span>
</div><div id="l936" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> fget</span><span class="nv">\_</span><span class="nb">line</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l937" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> fget</span><span class="nv">\_</span><span class="nb">line</span><span class="o">/</span><span class="m">3</span><span class="nb">} reads one line from the input stream {</span><span class="nv">\tt</span><span class="nb"> Str} and</span>
</div><div id="l938" class="code_block"><span class="nb">    unifies {</span><span class="nv">\tt</span><span class="nb"> Inlist} to the list of ASCII integers representing the</span>
</div><div id="l939" class="code_block"><span class="nb">    characters in the line, and {</span><span class="nv">\tt</span><span class="nb"> Next} to the line terminator, either</span>
</div><div id="l940" class="code_block"><span class="nb">    a newline </span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> </span><span class="m">10</span><span class="nb">}</span><span class="o">)</span><span class="nb"> or EOF </span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="o">-</span><span class="m">1</span><span class="nb">}</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l941" class="code_block"><span class="nb">    </span>
</div><div id="l942" class="code_block"><span class="nb">    This predicate is obsolete and</span>
</div><div id="l943" class="code_block"><span class="nb">    </span><span class="nv">\verb</span><span class="nb">|file_read_line_list| should be used instead.</span>
</div><div id="l944" class="code_block">
</div><div id="l945" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">write</span><span class="nv">\_</span><span class="nb">line</span><span class="o">(+</span><span class="nb">IOport, </span><span class="o">+</span><span class="nb">String, </span><span class="o">+</span><span class="nb">Offset</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l946" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">write</span><span class="nv">\_</span><span class="nb">line</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l947" class="code_block"><span class="nb">   Write {</span><span class="nv">\tt</span><span class="nb"> String} beginning with character {</span><span class="nv">\tt</span><span class="nb"> Offset}  to the output</span>
</div><div id="l948" class="code_block"><span class="nb">   file represented by the I</span><span class="o">/</span><span class="nb">O port {</span><span class="nv">\tt</span><span class="nb"> IOport}. {</span><span class="nv">\tt</span><span class="nb"> String} can</span>
</div><div id="l949" class="code_block"><span class="nb">   be an atom or a list of ASCII characters. This does </span><span class="nv">\emph</span><span class="nb">{not} put the</span>
</div><div id="l950" class="code_block"><span class="nb">   newline character at the end of the string </span><span class="o">(</span><span class="nb">unless {</span><span class="nv">\tt</span><span class="nb"> String} already</span>
</div><div id="l951" class="code_block"><span class="nb">   had this character</span><span class="o">)</span><span class="nb">. Note that escape sequences, like </span><span class="nv">\verb</span><span class="nb">|</span><span class="nv">\n</span><span class="nb">|, are</span>
</div><div id="l952" class="code_block"><span class="nb">   recognized if {</span><span class="nv">\tt</span><span class="nb"> String} is a character list, but are output as is if</span>
</div><div id="l953" class="code_block"><span class="nb">   {</span><span class="nv">\tt</span><span class="nb"> String} is an atom.</span>
</div><div id="l954" class="code_block"><span class="nb">   </span>
</div><div id="l955" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">write</span><span class="nv">\_</span><span class="nb">line</span><span class="o">(+</span><span class="nb">String, </span><span class="o">+</span><span class="nb">Offset</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l956" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">write</span><span class="nv">\_</span><span class="nb">line</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l957" class="code_block"><span class="nb">   Like </span><span class="nv">\verb</span><span class="nb">|file_write_line</span><span class="o">/</span><span class="m">3</span><span class="nb">|, but output goes to the currently open</span>
</div><div id="l958" class="code_block"><span class="nb">   output stream.</span>
</div><div id="l959" class="code_block">
</div><div id="l960" class="code_block">
</div><div id="l961" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">getbuf</span><span class="o">(+</span><span class="nb">IOport, </span><span class="o">+</span><span class="nb">BytesRequested, </span><span class="o">-</span><span class="nb">String, </span><span class="o">-</span><span class="nb">BytesRead</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l962" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">getbuf</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l963" class="code_block"><span class="nb">Read {</span><span class="nv">\tt</span><span class="nb"> BytesRequested} bytes from file represented by I</span><span class="o">/</span><span class="nb">O port {</span><span class="nv">\tt</span>
</div><div id="l964" class="code_block"><span class="nb">  IOport} </span><span class="o">(</span><span class="nb">which must already be open for reading</span><span class="o">)</span><span class="nb"> into variable {</span><span class="nv">\tt</span>
</div><div id="l965" class="code_block"><span class="nb">  String}. This is analogous to {</span><span class="nv">\tt</span><span class="nb"> fread} in C.  This predicate always</span>
</div><div id="l966" class="code_block"><span class="nb">succeeds. It does not distinguish between a file error and end of file.</span>
</div><div id="l967" class="code_block"><span class="nb">You can determine if either of these conditions has happened by verifying</span>
</div><div id="l968" class="code_block"><span class="nb">that </span><span class="s">$</span><span class="k">\tt</span> BytesRead &lt; BytesRequested<span class="s">$</span><span class="nb">.</span>
</div><div id="l969" class="code_block">
</div><div id="l970" class="code_block">
</div><div id="l971" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">getbuf</span><span class="nv">\_</span><span class="nb">atom</span><span class="o">(+</span><span class="nb">IOport, </span><span class="o">+</span><span class="nb">BytesRequested, </span><span class="o">-</span><span class="nb">String, </span><span class="o">-</span><span class="nb">BytesRead</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l972" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">getbuf</span><span class="nv">\_</span><span class="nb">atom</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l973" class="code_block"><span class="nb">This is synonymous with </span><span class="nv">\verb</span><span class="nb">|file_getbuf|.</span>
</div><div id="l974" class="code_block">
</div><div id="l975" class="code_block"><span class="nb">Note: because XSB does not have an atom table garbage collector yet, this</span>
</div><div id="l976" class="code_block"><span class="nb">predicate should not be used to read large files.</span>
</div><div id="l977" class="code_block">
</div><div id="l978" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">getbuf</span><span class="nv">\_</span><span class="nb">atom</span><span class="o">(+</span><span class="nb">BytesRequested, </span><span class="o">-</span><span class="nb">String, </span><span class="o">-</span><span class="nb">BytesRead</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l979" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">getbuf</span><span class="nv">\_</span><span class="nb">atom</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l980" class="code_block"><span class="nb">Like </span><span class="nv">\verb</span><span class="nb">|file_getbuf_atom</span><span class="o">/</span><span class="m">4</span><span class="nb">|, but reads from the currently open input stream</span>
</div><div id="l981" class="code_block"><span class="o">(</span><span class="nb">using {</span><span class="nv">\tt</span><span class="nb"> see</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span><span class="o">)</span><span class="nb">. This predicate always</span>
</div><div id="l982" class="code_block"><span class="nb">succeeds. It does not distinguish between a file error and end of file.</span>
</div><div id="l983" class="code_block"><span class="nb">You can determine if either of these conditions has happened by verifying</span>
</div><div id="l984" class="code_block"><span class="nb">that </span><span class="s">$</span><span class="k">\tt</span> BytesRead &lt; BytesRequested<span class="s">$</span><span class="nb">.</span>
</div><div id="l985" class="code_block">
</div><div id="l986" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">getbuf</span><span class="nv">\_</span><span class="nb">list</span><span class="o">(+</span><span class="nb">IOport, </span><span class="o">+</span><span class="nb">BytesRequested, </span><span class="o">-</span><span class="nb">CharList, </span><span class="o">-</span><span class="nb">BytesRead</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l987" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">getbuf</span><span class="nv">\_</span><span class="nb">list</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l988" class="code_block"><span class="nb">Like </span><span class="nv">\verb</span><span class="nb">|file_getbuf_atom</span><span class="o">/</span><span class="m">4</span><span class="nb">|, but {</span><span class="nv">\tt</span><span class="nb"> CharList} is instantiated to a list</span>
</div><div id="l989" class="code_block"><span class="nb">of characters that represent the string read from the input.</span>
</div><div id="l990" class="code_block">
</div><div id="l991" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">getbuf</span><span class="nv">\_</span><span class="nb">list</span><span class="o">(+</span><span class="nb">BytesRequested, </span><span class="o">-</span><span class="nb">String, </span><span class="o">-</span><span class="nb">BytesRead</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l992" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">getbuf</span><span class="nv">\_</span><span class="nb">list</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l993" class="code_block"><span class="nb">Like </span><span class="nv">\verb</span><span class="nb">|file_getbuf_list</span><span class="o">/</span><span class="m">3</span><span class="nb">|, but reads from the currently open input stream</span>
</div><div id="l994" class="code_block"><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> i.e.}, with {</span><span class="nv">\tt</span><span class="nb"> see</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l995" class="code_block">
</div><div id="l996" class="code_block">
</div><div id="l997" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">putbuf</span><span class="o">(+</span><span class="nb">IOport, </span><span class="o">+</span><span class="nb">BytesRequested, </span><span class="o">+</span><span class="nb">String, </span><span class="o">+</span><span class="nb">Offset, </span><span class="o">-</span><span class="nb">BytesWritten</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l998" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">putbuf</span><span class="o">/</span><span class="m">5</span><span class="nb">}}</span>
</div><div id="l999" class="code_block"><span class="nb">Write {</span><span class="nv">\tt</span><span class="nb"> BytesRequested} bytes into file represented by I</span><span class="o">/</span><span class="nb">O port {</span><span class="nv">\tt</span>
</div><div id="l1000" class="code_block"><span class="nb">  IOport} </span><span class="o">(</span><span class="nb">which must already be open for writing</span><span class="o">)</span><span class="nb"> from variable {</span><span class="nv">\tt</span>
</div><div id="l1001" class="code_block"><span class="nb">  String} at position {</span><span class="nv">\tt</span><span class="nb"> Offset}. This is analogous to C {</span><span class="nv">\tt</span><span class="nb"> fwrite}.</span>
</div><div id="l1002" class="code_block"><span class="nb">The value of {</span><span class="nv">\tt</span><span class="nb"> String} can be an atom or a list of ASCII characters.</span>
</div><div id="l1003" class="code_block">
</div><div id="l1004" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">putbuf</span><span class="o">(+</span><span class="nb">BytesRequested, </span><span class="o">+</span><span class="nb">String, </span><span class="o">+</span><span class="nb">Offset, </span><span class="o">-</span><span class="nb">BytesWritten</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l1005" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">putbuf</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l1006" class="code_block"><span class="nb">Like </span><span class="nv">\verb</span><span class="nb">|file_putbuf</span><span class="o">/</span><span class="m">3</span><span class="nb">|, but output goes to the currently open output stream.</span>
</div><div id="l1007" class="code_block">
</div><div id="l1008" class="code_block">
</div><div id="l1009" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l1010" class="code_block">
</div><div id="l1011" class="code_block"><span class="nv">\section</span><span class="nb">{String Manipulation}</span>
</div><div id="l1012" class="code_block"><span class="nv">\label</span><span class="nb">{sec</span><span class="o">-</span><span class="nb">strings}</span>
</div><div id="l1013" class="code_block">
</div><div id="l1014" class="code_block"><span class="nb">XSB has a number of powerful builtins that simplify the job of string</span>
</div><div id="l1015" class="code_block"><span class="nb">manipulation. These builting are especially powerful when they are combined</span>
</div><div id="l1016" class="code_block"><span class="nb">with pattern</span><span class="o">-</span><span class="nb">matching facilities provided by the {</span><span class="nv">\tt</span><span class="nb"> regmatch} package</span>
</div><div id="l1017" class="code_block"><span class="nb">described in Chapter~</span><span class="nv">\ref</span><span class="nb">{chap</span><span class="o">-</span><span class="nb">posix}.</span>
</div><div id="l1018" class="code_block">
</div><div id="l1019" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l1020" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{str</span><span class="nv">\_</span><span class="nb">sub</span><span class="o">(+</span><span class="nb">Sub, </span><span class="o">+</span><span class="nb">Str, ?Pos</span><span class="o">)</span><span class="nb">}{string}</span>
</div><div id="l1021" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> str</span><span class="nv">\_</span><span class="nb">sub</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l1022" class="code_block">
</div><div id="l1023" class="code_block"><span class="nb">Succeeds if {</span><span class="nv">\tt</span><span class="nb"> Sub} is a substring of {</span><span class="nv">\tt</span><span class="nb"> Str}. In that case, {</span><span class="nv">\tt</span><span class="nb"> Pos}</span>
</div><div id="l1024" class="code_block"><span class="nb">unifies with the position where the match occurred.</span>
</div><div id="l1025" class="code_block">
</div><div id="l1026" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{str</span><span class="nv">\_</span><span class="nb">cat</span><span class="o">(+</span><span class="nb">Str</span><span class="m">1</span><span class="nb">, </span><span class="o">+</span><span class="nb">Str</span><span class="m">2</span><span class="nb">, ?Result</span><span class="o">)</span><span class="nb">}{string}</span>
</div><div id="l1027" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> str</span><span class="nv">\_</span><span class="nb">cat</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l1028" class="code_block">
</div><div id="l1029" class="code_block"><span class="nb">Concatenates {</span><span class="nv">\tt</span><span class="nb"> Str</span><span class="m">1</span><span class="nb">} with {</span><span class="nv">\tt</span><span class="nb"> Str</span><span class="m">2</span><span class="nb">}. Unifies the result with {</span><span class="nv">\tt</span><span class="nb"> Result}.</span>
</div><div id="l1030" class="code_block">
</div><div id="l1031" class="code_block"><span class="nb">In addition to this, the predicate </span><span class="nv">\verb</span><span class="nb">|fmt_write_string</span><span class="o">/</span><span class="m">3</span><span class="nb">| described in</span>
</div><div id="l1032" class="code_block"><span class="nb">Section~</span><span class="nv">\ref</span><span class="nb">{sec</span><span class="o">-</span><span class="nb">low</span><span class="o">-</span><span class="nb">level</span><span class="o">-</span><span class="nb">io} can be used to concatenate strings and do</span>
</div><div id="l1033" class="code_block"><span class="nb">much more. However, for simple string concatenation, {</span><span class="nv">\tt</span><span class="nb"> str</span><span class="nv">\_</span><span class="nb">cat</span><span class="o">/</span><span class="m">3</span><span class="nb">} is</span>
</div><div id="l1034" class="code_block"><span class="nb">more efficient.</span>
</div><div id="l1035" class="code_block">
</div><div id="l1036" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{str</span><span class="nv">\_</span><span class="nb">length</span><span class="o">(+</span><span class="nb">Str, ?Result</span><span class="o">)</span><span class="nb">}{string}</span>
</div><div id="l1037" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> str</span><span class="nv">\_</span><span class="nb">length</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l1038" class="code_block">
</div><div id="l1039" class="code_block"><span class="nb">Unifies the {</span><span class="nv">\tt</span><span class="nb"> Result}  with the length of {</span><span class="nv">\tt</span><span class="nb"> Str}.</span>
</div><div id="l1040" class="code_block">
</div><div id="l1041" class="code_block"><span class="c">%%</span>
</div><div id="l1042" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{substring</span><span class="o">(+</span><span class="nb">String, </span><span class="o">+</span><span class="nb">BeginOffset, </span><span class="o">+</span><span class="nb">EndOffset, </span><span class="o">-</span><span class="nb">Result</span><span class="o">)</span><span class="nb">}{string}</span>
</div><div id="l1043" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> substring</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l1044" class="code_block"><span class="c">%%</span>
</div><div id="l1045" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> String} can be an atom or a list of characters, and the offsets must</span>
</div><div id="l1046" class="code_block"><span class="nb">be integers.  If {</span><span class="nv">\tt</span><span class="nb"> EndOffset} is negative, endof</span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> String}</span><span class="o">)+</span><span class="nb">{</span><span class="nv">\tt</span>
</div><div id="l1047" class="code_block"><span class="nb">  EndOffset} is assumed. If {</span><span class="nv">\tt</span><span class="nb"> EndOffset} is an unbound variable, then</span>
</div><div id="l1048" class="code_block"><span class="nb">end of string is assumed. If {</span><span class="nv">\tt</span><span class="nb"> BeginOffset} is less than </span><span class="m">0</span><span class="nb">, then </span><span class="m">0</span><span class="nb"> is</span>
</div><div id="l1049" class="code_block"><span class="nb">assumed; if it is greater than the length of the string, then string end is</span>
</div><div id="l1050" class="code_block"><span class="nb">assumed. If {</span><span class="nv">\tt</span><span class="nb"> EndOffset} is non</span><span class="o">-</span><span class="nb">negative, but is less than {</span><span class="nv">\tt</span>
</div><div id="l1051" class="code_block"><span class="nb">  BeginOffset}, then empty string is returned.</span>
</div><div id="l1052" class="code_block">
</div><div id="l1053" class="code_block"><span class="nb">The result returned in the fourth argument is a string, if {</span><span class="nv">\tt</span><span class="nb"> String} is</span>
</div><div id="l1054" class="code_block"><span class="nb">an atom, or a list of characters, if so is {</span><span class="nv">\tt</span><span class="nb"> String}.</span>
</div><div id="l1055" class="code_block">
</div><div id="l1056" class="code_block"><span class="nb">The </span><span class="nv">\verb</span><span class="nb">|substring</span><span class="o">/</span><span class="m">4</span><span class="nb">| predicate always succeeds </span><span class="o">(</span><span class="nb">unless there is an error,</span>
</div><div id="l1057" class="code_block"><span class="nb">such as wrong argument type</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1058" class="code_block">
</div><div id="l1059" class="code_block"><span class="nb">Here are some examples: </span>
</div><div id="l1060" class="code_block"><span class="c">%%</span>
</div><div id="l1061" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1062" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> substring</span><span class="o">(</span><span class="nb">&#39;abcdefg&#39;, </span><span class="m">3</span><span class="nb">, </span><span class="m">5</span><span class="nb">, L</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1063" class="code_block">
</div><div id="l1064" class="code_block"><span class="nb">L </span><span class="o">=</span><span class="nb"> de</span>
</div><div id="l1065" class="code_block">
</div><div id="l1066" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> substring</span><span class="o">(</span><span class="nb">&quot;abcdefg&quot;, </span><span class="m">4</span><span class="nb">, </span><span class="o">-</span><span class="m">1</span><span class="nb">, L</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1067" class="code_block">
</div><div id="l1068" class="code_block"><span class="nb">L </span><span class="o">=</span><span class="nb"> </span><span class="o">[</span><span class="m">101</span><span class="nb">,</span><span class="m">102</span><span class="o">]</span>
</div><div id="l1069" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1070" class="code_block"><span class="c">%%</span>
</div><div id="l1071" class="code_block"><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> i.e.}, L </span><span class="o">=</span><span class="nb"> ef represented using ASCII codes</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1072" class="code_block">
</div><div id="l1073" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{string</span><span class="nv">\_</span><span class="nb">substitute</span><span class="o">(+</span><span class="nb">String, </span><span class="o">+</span><span class="nb">SubstrList, </span><span class="o">+</span><span class="nb">SubstitutionList, </span><span class="o">-</span><span class="nb">OutStr</span><span class="o">)</span><span class="nb">}{string}</span>
</div><div id="l1074" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> string</span><span class="nv">\_</span><span class="nb">substitute</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l1075" class="code_block">
</div><div id="l1076" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> InputStr} can an atom or a list of characters.  {</span><span class="nv">\tt</span><span class="nb"> SubstrList} must</span>
</div><div id="l1077" class="code_block"><span class="nb">be a list of terms of the form {</span><span class="nv">\tt</span><span class="nb"> s</span><span class="o">(</span><span class="nb">BegOffset, EndOffset</span><span class="o">)</span><span class="nb">}, where the name</span>
</div><div id="l1078" class="code_block"><span class="nb">of the functor is immaterial.  The meaning of the offsets is the same as</span>
</div><div id="l1079" class="code_block"><span class="nb">for {</span><span class="nv">\tt</span><span class="nb"> re</span><span class="nv">\_</span><span class="nb">substring</span><span class="o">/</span><span class="m">4</span><span class="nb">}.  Each such term specifies a substring </span><span class="o">(</span><span class="nb">between</span>
</div><div id="l1080" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> BegOffset} and {</span><span class="nv">\tt</span><span class="nb"> EndOffset}; negative {</span><span class="nv">\tt</span><span class="nb"> EndOffset} stands for</span>
</div><div id="l1081" class="code_block"><span class="nb">the end of string</span><span class="o">)</span><span class="nb"> to be replaced.  {</span><span class="nv">\tt</span><span class="nb"> SubstitutionList} must be a list</span>
</div><div id="l1082" class="code_block"><span class="nb">of atoms or character lists.</span>
</div><div id="l1083" class="code_block">
</div><div id="l1084" class="code_block"><span class="nb">This predicate replaces the substrings specified in {</span><span class="nv">\tt</span><span class="nb"> SubstrList} with</span>
</div><div id="l1085" class="code_block"><span class="nb">the corresponding strings from {</span><span class="nv">\tt</span><span class="nb"> SubstitutionList}.  The result is</span>
</div><div id="l1086" class="code_block"><span class="nb">returned in {</span><span class="nv">\tt</span><span class="nb"> OutStr}. {</span><span class="nv">\tt</span><span class="nb"> OutStr} is a list of characters, if so is</span>
</div><div id="l1087" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> InputStr}; otherwise, it is an atom.</span>
</div><div id="l1088" class="code_block">
</div><div id="l1089" class="code_block"><span class="nb">If {</span><span class="nv">\tt</span><span class="nb"> SubstitutionList} is shorter than {</span><span class="nv">\tt</span><span class="nb"> SubstrList} then the last</span>
</div><div id="l1090" class="code_block"><span class="nb">string in {</span><span class="nv">\tt</span><span class="nb"> SubstitutionList} is used for substituting the extra</span>
</div><div id="l1091" class="code_block"><span class="nb">substrings specified in {</span><span class="nv">\tt</span><span class="nb"> SubstitutionList}. As a special case, this</span>
</div><div id="l1092" class="code_block"><span class="nb">makes it possible to replace all specified substrings with a single string.</span>
</div><div id="l1093" class="code_block">
</div><div id="l1094" class="code_block"><span class="nb">As in the case of {</span><span class="nv">\tt</span><span class="nb"> re</span><span class="nv">\_</span><span class="nb">substring</span><span class="o">/</span><span class="m">4</span><span class="nb">}, if {</span><span class="nv">\tt</span><span class="nb"> OutStr} is an atom, it is</span>
</div><div id="l1095" class="code_block"><span class="nb">not interned.  The user should either intern this string or convert it into</span>
</div><div id="l1096" class="code_block"><span class="nb">a list, as explained previously.</span>
</div><div id="l1097" class="code_block">
</div><div id="l1098" class="code_block"><span class="nb">The </span><span class="nv">\verb</span><span class="nb">|string_substitute</span><span class="o">/</span><span class="m">4</span><span class="nb">| predicate always succeeds.</span>
</div><div id="l1099" class="code_block">
</div><div id="l1100" class="code_block"><span class="nb">Here are some examples:</span>
</div><div id="l1101" class="code_block"><span class="c">%%</span>
</div><div id="l1102" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1103" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> string_substitute</span><span class="o">(</span><span class="nb">&#39;qaddf&#39;, </span><span class="o">[</span><span class="nb">s</span><span class="o">(</span><span class="m">2</span><span class="nb">,</span><span class="m">4</span><span class="o">)]</span><span class="nb">, </span><span class="o">[</span><span class="nb">&#39;</span><span class="m">123</span><span class="nb">&#39;</span><span class="o">]</span><span class="nb"> ,L</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1104" class="code_block">
</div><div id="l1105" class="code_block"><span class="nb">L </span><span class="o">=</span><span class="nb"> qa</span><span class="m">123</span><span class="nb">f</span>
</div><div id="l1106" class="code_block">
</div><div id="l1107" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> string_substitute</span><span class="o">(</span><span class="nb">&#39;qaddf&#39;, </span><span class="o">[</span><span class="nb">s</span><span class="o">(</span><span class="m">2</span><span class="nb">,</span><span class="o">-</span><span class="m">1</span><span class="o">)]</span><span class="nb">, </span><span class="o">[</span><span class="nb">&#39;</span><span class="m">123</span><span class="nb">&#39;</span><span class="o">]</span><span class="nb"> ,L</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1108" class="code_block">
</div><div id="l1109" class="code_block"><span class="nb">L </span><span class="o">=</span><span class="nb"> qa</span><span class="m">123</span>
</div><div id="l1110" class="code_block">
</div><div id="l1111" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> string_substitute</span><span class="o">(</span><span class="nb">&quot;abcdefg&quot;, </span><span class="o">[</span><span class="nb">s</span><span class="o">(</span><span class="m">4</span><span class="nb">,</span><span class="o">-</span><span class="m">1</span><span class="o">)]</span><span class="nb">, </span><span class="o">[</span><span class="nb">&quot;</span><span class="m">123</span><span class="nb">&quot;</span><span class="o">]</span><span class="nb">,L</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1112" class="code_block">
</div><div id="l1113" class="code_block"><span class="nb">L </span><span class="o">=</span><span class="nb"> </span><span class="o">[</span><span class="m">97</span><span class="nb">,</span><span class="m">98</span><span class="nb">,</span><span class="m">99</span><span class="nb">,</span><span class="m">100</span><span class="nb">,</span><span class="m">49</span><span class="nb">,</span><span class="m">50</span><span class="nb">,</span><span class="m">51</span><span class="o">]</span>
</div><div id="l1114" class="code_block">
</div><div id="l1115" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> string_substitute</span><span class="o">(</span><span class="nb">&#39;</span><span class="m">1234567890123</span><span class="nb">&#39;, </span><span class="o">[</span><span class="nb">f</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">5</span><span class="o">)</span><span class="nb">,f</span><span class="o">(</span><span class="m">5</span><span class="nb">,</span><span class="m">7</span><span class="o">)</span><span class="nb">,f</span><span class="o">(</span><span class="m">9</span><span class="nb">,</span><span class="o">-</span><span class="m">2</span><span class="o">)]</span><span class="nb">, </span><span class="o">[</span><span class="nb">&quot;pppp&quot;, lll</span><span class="o">]</span><span class="nb">,X</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1116" class="code_block">
</div><div id="l1117" class="code_block"><span class="nb">X </span><span class="o">=</span><span class="nb"> </span><span class="m">1</span><span class="nb">pppplll</span><span class="m">89</span><span class="nb">lll</span>
</div><div id="l1118" class="code_block">
</div><div id="l1119" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> string_substitute</span><span class="o">(</span><span class="nb">&#39;</span><span class="m">1234567890123</span><span class="nb">&#39;, </span><span class="o">[</span><span class="nb">f</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">5</span><span class="o">)</span><span class="nb">,f</span><span class="o">(</span><span class="m">6</span><span class="nb">,</span><span class="m">7</span><span class="o">)</span><span class="nb">,f</span><span class="o">(</span><span class="m">9</span><span class="nb">,</span><span class="o">-</span><span class="m">2</span><span class="o">)]</span><span class="nb">, </span><span class="o">[</span><span class="nb">&#39;</span><span class="o">---</span><span class="nb">&#39;</span><span class="o">]</span><span class="nb">,X</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1120" class="code_block">
</div><div id="l1121" class="code_block"><span class="nb">X </span><span class="o">=</span><span class="nb"> </span><span class="m">1</span><span class="o">---</span><span class="m">6</span><span class="o">---</span><span class="m">89</span><span class="o">---</span>
</div><div id="l1122" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1123" class="code_block"><span class="c">%%</span>
</div><div id="l1124" class="code_block">
</div><div id="l1125" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l1126" class="code_block"><span class="c">%%</span>
</div><div id="l1127" class="code_block">
</div><div id="l1128" class="code_block">
</div><div id="l1129" class="code_block">
</div><div id="l1130" class="code_block"><span class="nv">\section</span><span class="nb">{Script Writing Utilities}</span>
</div><div id="l1131" class="code_block"><span class="c">%========================</span>
</div><div id="l1132" class="code_block">
</div><div id="l1133" class="code_block"><span class="nb">Prolog, </span><span class="o">(</span><span class="nb">or XSB</span><span class="o">)</span><span class="nb"> can be useful for writing scripts in a UNIX system.</span>
</div><div id="l1134" class="code_block"><span class="nb">Prolog&#39;s simple syntax and declarative semantics make it especially</span>
</div><div id="l1135" class="code_block"><span class="nb">suitable for scripts that involve text processing.  Wherever noted, some of</span>
</div><div id="l1136" class="code_block"><span class="nb">these functions are currently working under Unix only.</span>
</div><div id="l1137" class="code_block">
</div><div id="l1138" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l1139" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{date</span><span class="o">(</span><span class="nb">?Date</span><span class="o">)</span><span class="nb">}{scrptutl}</span>
</div><div id="l1140" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> date</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l1141" class="code_block">
</div><div id="l1142" class="code_block"><span class="nb">Unifies {</span><span class="nv">\tt</span><span class="nb"> Date} to the current date, returned as a Prolog term, suitable</span>
</div><div id="l1143" class="code_block"><span class="nb">for term comparison.  Currently this only works under Unix, is slow, and</span>
</div><div id="l1144" class="code_block"><span class="nb">should be rewritten in C using {</span><span class="nv">\tt</span><span class="nb"> time</span><span class="o">()</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> localtime</span><span class="o">()</span><span class="nb">}.</span>
</div><div id="l1145" class="code_block">
</div><div id="l1146" class="code_block"><span class="nb">Example:</span>
</div><div id="l1147" class="code_block"><span class="nb">{</span><span class="nv">\footnotesize</span>
</div><div id="l1148" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1149" class="code_block"><span class="nb">                &gt; date </span>
</div><div id="l1150" class="code_block"><span class="nb">                Thu Feb </span><span class="m">20</span><span class="nb"> </span><span class="m">08</span><span class="nb">:</span><span class="m">46</span><span class="nb">:</span><span class="m">08</span><span class="nb"> EST </span><span class="m">1997</span>
</div><div id="l1151" class="code_block"><span class="nb">                &gt; xsb </span><span class="o">-</span><span class="nb">i</span>
</div><div id="l1152" class="code_block"><span class="nb">               XSB Version </span><span class="m">1</span><span class="nb">.</span><span class="m">7</span>
</div><div id="l1153" class="code_block"><span class="nb">               </span><span class="o">[</span><span class="nb">sequential, single word, optimal mode</span><span class="o">]</span>
</div><div id="l1154" class="code_block"><span class="nb">               | ?</span><span class="o">-</span><span class="nb"> </span><span class="o">[</span><span class="nb">scrptutl</span><span class="o">]</span><span class="nb">.</span>
</div><div id="l1155" class="code_block"><span class="nb">               </span><span class="o">[</span><span class="nb">scrptutl loaded</span><span class="o">]</span>
</div><div id="l1156" class="code_block">
</div><div id="l1157" class="code_block"><span class="nb">               yes</span>
</div><div id="l1158" class="code_block"><span class="nb">               | ?</span><span class="o">-</span><span class="nb"> date</span><span class="o">(</span><span class="nb">D</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1159" class="code_block"><span class="nb">               D </span><span class="o">=</span><span class="nb"> date</span><span class="o">(</span><span class="m">1997</span><span class="nb">,</span><span class="m">1</span><span class="nb">,</span><span class="m">20</span><span class="nb">,</span><span class="m">8</span><span class="nb">,</span><span class="m">47</span><span class="nb">,</span><span class="m">41</span><span class="o">)</span>
</div><div id="l1160" class="code_block">
</div><div id="l1161" class="code_block"><span class="nb">               yes</span>
</div><div id="l1162" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}}</span>
</div><div id="l1163" class="code_block">
</div><div id="l1164" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">time</span><span class="o">(+</span><span class="nb">FileName, </span><span class="o">-</span><span class="nb">time</span><span class="o">(</span><span class="nb">Time</span><span class="m">1</span><span class="nb">,Time</span><span class="m">2</span><span class="o">))</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l1165" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">time</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l1166" class="code_block">
</div><div id="l1167" class="code_block"><span class="nb">Returns file&#39;s modification time. Because </span>
</div><div id="l1168" class="code_block"><span class="nb">XSB steals </span><span class="m">5</span><span class="nb"> bits from each word, time must be returned as two words:</span>
</div><div id="l1169" class="code_block"><span class="nb">Time</span><span class="m">1</span><span class="nb">, representing the most significant digits, and Time</span><span class="m">2</span><span class="nb">, representing</span>
</div><div id="l1170" class="code_block"><span class="nb">the less significant digits.</span>
</div><div id="l1171" class="code_block">
</div><div id="l1172" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">size</span><span class="o">(+</span><span class="nb">FileName, </span><span class="o">-</span><span class="nb">Size</span><span class="o">)</span><span class="nb">}{file</span><span class="nv">\_</span><span class="nb">io}</span>
</div><div id="l1173" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">size</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l1174" class="code_block">
</div><div id="l1175" class="code_block"><span class="nb">Returns file size.</span>
</div><div id="l1176" class="code_block">
</div><div id="l1177" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{directory</span><span class="o">(+</span><span class="nb">Path,?Directory</span><span class="o">)</span><span class="nb">}{directry}</span>
</div><div id="l1178" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> directory</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l1179" class="code_block">
</div><div id="l1180" class="code_block"><span class="nb">Unifies {</span><span class="nv">\tt</span><span class="nb"> Directory} with a list of files in the directory specified by</span>
</div><div id="l1181" class="code_block"><span class="nb">path.  Information about the files is similar to that obtained by {</span><span class="nv">\tt</span><span class="nb"> ls</span>
</div><div id="l1182" class="code_block"><span class="nb">  </span><span class="o">-</span><span class="nb">l}, but transformed for ease of processing.  This currently works for</span>
</div><div id="l1183" class="code_block"><span class="nb">Unix only, is slow, and should be reimplemented in C using {</span><span class="nv">\tt</span><span class="nb"> opendir</span><span class="o">()</span><span class="nb">}</span>
</div><div id="l1184" class="code_block"><span class="nb">and {</span><span class="nv">\tt</span><span class="nb"> readdir</span><span class="o">()</span><span class="nb">}.</span>
</div><div id="l1185" class="code_block">
</div><div id="l1186" class="code_block">
</div><div id="l1187" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{expand</span><span class="nv">\_</span><span class="nb">filename</span><span class="o">(+</span><span class="nb">FileName,</span><span class="o">-</span><span class="nb">ExpandedName</span><span class="o">)</span><span class="nb">}{machine}</span>
</div><div id="l1188" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> expand</span><span class="nv">\_</span><span class="nb">filename</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l1189" class="code_block">
</div><div id="l1190" class="code_block"><span class="nb">Expands the file name passed as the first argument and binds the variable</span>
</div><div id="l1191" class="code_block"><span class="nb">in the second argument to the expanded name. This includes expanding Unix</span>
</div><div id="l1192" class="code_block"><span class="nb">tildas, prepending the current directory, etc. In addition, the expanded</span>
</div><div id="l1193" class="code_block"><span class="nb">file name is ``rectified&#39;&#39; so that multiple repeated slashes are replaced</span>
</div><div id="l1194" class="code_block"><span class="nb">with a single slash, the intervening ``.</span><span class="o">/</span><span class="nb">&#39;&#39; are removed, and ``..</span><span class="o">/</span><span class="nb">&#39;&#39; are</span>
</div><div id="l1195" class="code_block"><span class="nb">applied so that the preceding item in the path name is deleted. For</span>
</div><div id="l1196" class="code_block"><span class="nb">instance, if the current directory is {</span><span class="nv">\tt</span><span class="nb"> </span><span class="o">/</span><span class="nb">home}, then {</span><span class="nv">\tt</span>
</div><div id="l1197" class="code_block"><span class="nb">  abc</span><span class="o">//</span><span class="nb">cde</span><span class="o">/</span><span class="nb">..</span><span class="o">///</span><span class="nb">ff</span><span class="o">/</span><span class="nb">.</span><span class="o">/</span><span class="nb">b} will be converted into {</span><span class="nv">\tt</span><span class="nb"> </span><span class="o">/</span><span class="nb">home</span><span class="o">/</span><span class="nb">abc</span><span class="o">/</span><span class="nb">ff</span><span class="o">/</span><span class="nb">b}.</span>
</div><div id="l1198" class="code_block">
</div><div id="l1199" class="code_block"><span class="nb">Under Windows, this predicates does rectification </span><span class="o">(</span><span class="nb">using</span>
</div><div id="l1200" class="code_block"><span class="nb">backslashes when appropriate</span><span class="o">)</span><span class="nb">, but it does not expand the tildas.</span>
</div><div id="l1201" class="code_block">
</div><div id="l1202" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{tilde</span><span class="nv">\_</span><span class="nb">expand</span><span class="nv">\_</span><span class="nb">filename</span><span class="o">(+</span><span class="nb">FileName,</span><span class="o">-</span><span class="nb">ExpandedName</span><span class="o">)</span><span class="nb">}{machine}</span>
</div><div id="l1203" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> tilde</span><span class="nv">\_</span><span class="nb">expand</span><span class="nv">\_</span><span class="nb">filename</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l1204" class="code_block"><span class="nb">Like {</span><span class="nv">\tt</span><span class="nb"> expand</span><span class="nv">\_</span><span class="nb">filename</span><span class="o">/</span><span class="m">2</span><span class="nb">}, but only expands tildas and does</span>
</div><div id="l1205" class="code_block"><span class="nb">rectification. This does not prepend the current working directory to</span>
</div><div id="l1206" class="code_block"><span class="nb">relative file names.</span>
</div><div id="l1207" class="code_block">
</div><div id="l1208" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{is</span><span class="nv">\_</span><span class="nb">absolute</span><span class="nv">\_</span><span class="nb">filename</span><span class="o">(+</span><span class="nb">FileName</span><span class="o">)</span><span class="nb">}{machine} </span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span>
</div><div id="l1209" class="code_block"><span class="nb">is</span><span class="nv">\_</span><span class="nb">absolute</span><span class="nv">\_</span><span class="nb">filename</span><span class="o">/</span><span class="m">1</span><span class="nb">}} Succeeds, if file name is absolute; fails</span>
</div><div id="l1210" class="code_block"><span class="nb">otherwise.  This predicate works also under Windows, {</span><span class="nv">\it</span>
</div><div id="l1211" class="code_block"><span class="nb">i.e.}, it recognizes drive letters, etc.</span>
</div><div id="l1212" class="code_block">
</div><div id="l1213" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{parse</span><span class="nv">\_</span><span class="nb">filename</span><span class="o">(+</span><span class="nb">FileName,</span><span class="o">-</span><span class="nb">Dir,</span><span class="o">-</span><span class="nb">Base,</span><span class="o">-</span><span class="nb">Extension</span><span class="o">)</span><span class="nb">}{machine}</span>
</div><div id="l1214" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> parse</span><span class="nv">\_</span><span class="nb">filename</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l1215" class="code_block"><span class="nb">This predicate parses file names by separating the directory part, the base</span>
</div><div id="l1216" class="code_block"><span class="nb">name part, and file extension. If file extension is found, it is removed</span>
</div><div id="l1217" class="code_block"><span class="nb">from the base name. Also, directory names are rectified and if a directory</span>
</div><div id="l1218" class="code_block"><span class="nb">name starts with a tilde </span><span class="o">(</span><span class="nb">in Unix</span><span class="o">)</span><span class="nb">, then it is expanded. Directory names</span>
</div><div id="l1219" class="code_block"><span class="nb">always end with a slash or a backslash, as appropriate for the OS at hand.</span>
</div><div id="l1220" class="code_block">
</div><div id="l1221" class="code_block"><span class="nb">For instance, {</span><span class="nv">\tt</span><span class="nb"> </span><span class="s">$</span><span class="k">\sim</span><span class="s">$</span><span class="nb">john</span><span class="o">///</span><span class="nb">doe</span><span class="o">/</span><span class="nb">dir</span><span class="m">1</span><span class="o">//</span><span class="nb">..</span><span class="o">/</span><span class="nb">foo.bar} will be parsed into:</span>
</div><div id="l1222" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> </span><span class="o">/</span><span class="nb">home</span><span class="o">/</span><span class="nb">john</span><span class="o">/</span><span class="nb">doe</span><span class="o">/</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> foo}, and {</span><span class="nv">\tt</span><span class="nb"> bar} </span><span class="o">(</span><span class="nb">where we assume that    </span>
</div><div id="l1223" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> </span><span class="o">/</span><span class="nb">home</span><span class="o">/</span><span class="nb">john} is what {</span><span class="nv">\tt</span><span class="nb"> </span><span class="s">$</span><span class="k">\sim</span><span class="s">$</span><span class="nb">john} expands into</span><span class="o">)</span><span class="nb">.  </span>
</div><div id="l1224" class="code_block">
</div><div id="l1225" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{file</span><span class="nv">\_</span><span class="nb">to</span><span class="nv">\_</span><span class="nb">list</span><span class="o">(</span><span class="nb">IOport, List</span><span class="o">)</span><span class="nb">}{scrptutls}</span>
</div><div id="l1226" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">to</span><span class="nv">\_</span><span class="nb">list</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l1227" class="code_block"><span class="c">%%</span>
</div><div id="l1228" class="code_block"><span class="nb">Read lines from an </span><span class="nv">\emph</span><span class="nb">{open} I</span><span class="o">/</span><span class="nb">O port. Return a</span>
</div><div id="l1229" class="code_block"><span class="nb">list of terms, one per each line read. Each such term is a list of tokens</span>
</div><div id="l1230" class="code_block"><span class="nb">on the corresponding line.  Tokens are lists of characters separated by a</span>
</div><div id="l1231" class="code_block"><span class="nb">space symbol </span><span class="o">(</span><span class="nb">space, newline, return, tabs, formfeed</span><span class="o">)</span><span class="nb">. For instance, if</span>
</div><div id="l1232" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> IOport} </span><span class="m">10</span><span class="nb"> is bound to a file</span>
</div><div id="l1233" class="code_block"><span class="c">%%</span>
</div><div id="l1234" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1235" class="code_block"><span class="nb">ads sdfdsfd ee</span>
</div><div id="l1236" class="code_block"><span class="m">112</span><span class="nb"> </span><span class="m">444</span>
</div><div id="l1237" class="code_block"><span class="m">4555</span><span class="nb">  </span>
</div><div id="l1238" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1239" class="code_block"><span class="c">%%</span>
</div><div id="l1240" class="code_block"><span class="nb">then</span>
</div><div id="l1241" class="code_block"><span class="c">%%</span>
</div><div id="l1242" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1243" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> file_to_list</span><span class="o">(</span><span class="m">10</span><span class="nb">, L</span><span class="o">)</span><span class="nb">.  </span>
</div><div id="l1244" class="code_block"><span class="nb">L </span><span class="o">=</span><span class="nb"> </span><span class="o">[[</span><span class="nb">ads,sdfdsfd,ee</span><span class="o">]</span><span class="nb">,</span><span class="o">[</span><span class="m">112</span><span class="nb">,</span><span class="m">444</span><span class="o">]</span><span class="nb">,</span><span class="o">[</span><span class="m">4555</span><span class="o">]]</span>
</div><div id="l1245" class="code_block"><span class="nb">yes</span>
</div><div id="l1246" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1247" class="code_block"><span class="c">%%</span>
</div><div id="l1248" class="code_block"><span class="nb">Note: {</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">to</span><span class="nv">\_</span><span class="nb">list</span><span class="o">/</span><span class="m">2</span><span class="nb">} does not close the I</span><span class="o">/</span><span class="nb">O port, so it is an</span>
</div><div id="l1249" class="code_block"><span class="nb">application program responsibility.</span>
</div><div id="l1250" class="code_block">
</div><div id="l1251" class="code_block">
</div><div id="l1252" class="code_block"><span class="c">%% This predicate is superseded by spawn_process/5 and shell/5</span>
</div><div id="l1253" class="code_block"><span class="c">%% Do not use it!</span>
</div><div id="l1254" class="code_block"><span class="c">%%</span>
</div><div id="l1255" class="code_block"><span class="c">%%\ournewitem{sysin(+Command,?Output)}{scrptutl}</span>
</div><div id="l1256" class="code_block"><span class="c">%%\index{{\tt sysin/2}}</span>
</div><div id="l1257" class="code_block"><span class="c">%%</span>
</div><div id="l1258" class="code_block"><span class="c">%%      Unifies {\tt Output} with the stdout of {\tt Command}</span>
</div><div id="l1259" class="code_block"><span class="c">%%represented as a list of lists of tokens, where each element in the</span>
</div><div id="l1260" class="code_block"><span class="c">%%outer list of {\tt Command} represents a line of stdout.</span>
</div><div id="l1261" class="code_block"><span class="c">%%</span>
</div><div id="l1262" class="code_block"><span class="c">%%Example:</span>
</div><div id="l1263" class="code_block"><span class="c">%%{\footnotesize</span>
</div><div id="l1264" class="code_block"><span class="c">%%\begin{verbatim}</span>
</div><div id="l1265" class="code_block"><span class="c">%%                &gt; uname -a</span>
</div><div id="l1266" class="code_block"><span class="c">%%                Linux swiftlap 1.2.8 #1 Sun May 7 13:10:10 CDT 1995 i486</span>
</div><div id="l1267" class="code_block"><span class="c">%%                | ?- sysin(&#39;uname -a&#39;,Output).</span>
</div><div id="l1268" class="code_block"><span class="c">%%</span>
</div><div id="l1269" class="code_block"><span class="c">%%                Output = [[Linux,swiftlap,1.2.8,#1,Sun,May,7,13:10:10,CDT,1995,i486]]</span>
</div><div id="l1270" class="code_block"><span class="c">%%</span>
</div><div id="l1271" class="code_block"><span class="c">%%                yes</span>
</div><div id="l1272" class="code_block"><span class="c">%%\end{verbatim}}</span>
</div><div id="l1273" class="code_block">
</div><div id="l1274" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l1275" class="code_block">
</div><div id="l1276" class="code_block">
</div><div id="l1277" class="code_block"><span class="nv">\section</span><span class="nb">{Communication with Subprocesses}</span>
</div><div id="l1278" class="code_block">
</div><div id="l1279" class="code_block"><span class="nb">In the previous section, we have seen several predicates that allow XSB to</span>
</div><div id="l1280" class="code_block"><span class="nb">create other processes. However, these predicates offer only a very limited</span>
</div><div id="l1281" class="code_block"><span class="nb">way to communicate with these processes. The predicate</span>
</div><div id="l1282" class="code_block"><span class="nv">\verb</span><span class="nb">|spawn_process</span><span class="o">/</span><span class="m">5</span><span class="nb">| and friends come to the rescue. It allows to spawn</span>
</div><div id="l1283" class="code_block"><span class="nb">any process </span><span class="o">(</span><span class="nb">including multiple copies of XSB</span><span class="o">)</span><span class="nb"> and redirect its standard</span>
</div><div id="l1284" class="code_block"><span class="nb">input and output to XSB I</span><span class="o">/</span><span class="nb">O ports. XSB can then write to the process and</span>
</div><div id="l1285" class="code_block"><span class="nb">read from it. The section of socket I</span><span class="o">/</span><span class="nb">O describes yet another mode of</span>
</div><div id="l1286" class="code_block"><span class="nb">interprocess communication. </span>
</div><div id="l1287" class="code_block">
</div><div id="l1288" class="code_block"><span class="nb">In addition, the predicate {</span><span class="nv">\tt</span><span class="nb"> pipe</span><span class="nv">\_</span><span class="nb">open</span><span class="o">/</span><span class="m">2</span><span class="nb">} described in this section</span>
</div><div id="l1289" class="code_block"><span class="nb">lets one create any number of pipes </span><span class="o">(</span><span class="nb">that do not need to be connected to</span>
</div><div id="l1290" class="code_block"><span class="nb">the standard I</span><span class="o">/</span><span class="nb">O port</span><span class="o">)</span><span class="nb"> and talk to child processes through these pipes.</span>
</div><div id="l1291" class="code_block">
</div><div id="l1292" class="code_block"><span class="nb">All predicates in this section, except {</span><span class="nv">\tt</span><span class="nb"> pipe</span><span class="nv">\_</span><span class="nb">open</span><span class="o">/</span><span class="m">2</span><span class="nb">} and</span>
</div><div id="l1293" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">/</span><span class="m">2</span><span class="nb">}, must be imported from module {</span><span class="nv">\tt</span><span class="nb"> shell}.</span>
</div><div id="l1294" class="code_block"><span class="nb">The predicates {</span><span class="nv">\tt</span><span class="nb"> pipe</span><span class="nv">\_</span><span class="nb">open</span><span class="o">/</span><span class="m">2</span><span class="nb">} and</span>
</div><div id="l1295" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">/</span><span class="m">2</span><span class="nb">} must be imported from {</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">io}.</span>
</div><div id="l1296" class="code_block">
</div><div id="l1297" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l1298" class="code_block"><span class="nv">\ouritem</span><span class="nb">{spawn</span><span class="nv">\_</span><span class="nb">process</span><span class="o">(+</span><span class="nb">CmdSpec,</span><span class="o">-</span><span class="nb">StreamToProc,</span><span class="o">-</span><span class="nb">StreamFromProc,</span><span class="o">-</span><span class="nb">ProcStderrStream,</span><span class="o">-</span><span class="nb">ProcId</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> spawn</span><span class="nv">\_</span><span class="nb">process</span><span class="o">/</span><span class="m">5</span><span class="nb">}} </span>
</div><div id="l1299" class="code_block"><span class="nb">Spawn a new process specified by {</span><span class="nv">\tt</span><span class="nb"> CmdSpec}. {</span><span class="nv">\tt</span><span class="nb"> CmdSpec} must be</span>
</div><div id="l1300" class="code_block"><span class="nb">either a single atom or a </span><span class="nv">\emph</span><span class="nb">{list} of atoms.</span>
</div><div id="l1301" class="code_block"><span class="nb">If it is an atom, then it must represent a shell command.</span>
</div><div id="l1302" class="code_block"><span class="nb">If it is a list, the first member of the list must be the name of the</span>
</div><div id="l1303" class="code_block"><span class="nb">program to run and the </span>
</div><div id="l1304" class="code_block"><span class="nb">other elements must be arguments to the program. Program name must be specified</span>
</div><div id="l1305" class="code_block"><span class="nb">in such a way as to make sure the OS can find it using the contents of the</span>
</div><div id="l1306" class="code_block"><span class="nb">environment variable {</span><span class="nv">\tt</span><span class="nb"> PATH}.</span>
</div><div id="l1307" class="code_block"><span class="nb">Also note that pipes, I</span><span class="o">/</span><span class="nb">O redirection and such are not allowed in command</span>
</div><div id="l1308" class="code_block"><span class="nb">specification. That is, {</span><span class="nv">\tt</span><span class="nb"> CmdSpec} must represent a single command.</span>
</div><div id="l1309" class="code_block"><span class="o">(</span><span class="nb">But read about process plumbing below and about the related predicate</span>
</div><div id="l1310" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">5</span><span class="nb">}.</span><span class="o">)</span>
</div><div id="l1311" class="code_block">
</div><div id="l1312" class="code_block"><span class="nb">The next three parameters of </span><span class="nv">\verb</span><span class="nb">|spawn_process| are XSB I</span><span class="o">/</span><span class="nb">O ports</span>
</div><div id="l1313" class="code_block"><span class="nb">to the process </span><span class="o">(</span><span class="nb">leading to the subprocess standard input</span><span class="o">)</span><span class="nb">, from the process</span>
</div><div id="l1314" class="code_block"><span class="o">(</span><span class="nb">from its standard output</span><span class="o">)</span><span class="nb">, and a port capturing the</span>
</div><div id="l1315" class="code_block"><span class="nb">subprocess standard error output. The last parameter is the system process id.</span>
</div><div id="l1316" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l1317" class="code_block"><span class="c">%%</span>
</div><div id="l1318" class="code_block">
</div><div id="l1319" class="code_block"><span class="nv">\noindent</span>
</div><div id="l1320" class="code_block"><span class="nb">Here is a simple example of how it works.</span>
</div><div id="l1321" class="code_block">
</div><div id="l1322" class="code_block"><span class="c">%%</span>
</div><div id="l1323" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1324" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> import file_flush</span><span class="o">/</span><span class="m">2</span><span class="nb">, file_read_line_atom</span><span class="o">/</span><span class="m">3</span><span class="nb"> from file_io.</span>
</div><div id="l1325" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> import file_nl</span><span class="o">/</span><span class="m">1</span><span class="nb"> , file_write</span><span class="o">/</span><span class="m">2</span><span class="nb"> from xsb_writ.  </span>
</div><div id="l1326" class="code_block">
</div><div id="l1327" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> spawn_process</span><span class="o">([</span><span class="nb">cat, &#39;</span><span class="o">-</span><span class="nb">&#39;</span><span class="o">]</span><span class="nb">, To, From, Stderr, Pid</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1328" class="code_block"><span class="nb">     file_write</span><span class="o">(</span><span class="nb">To,&#39;Hello cat</span><span class="o">!</span><span class="nb">&#39;</span><span class="o">)</span><span class="nb">, file_nl</span><span class="o">(</span><span class="nb">To</span><span class="o">)</span><span class="nb">, file_flush</span><span class="o">(</span><span class="nb">To,_</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1329" class="code_block"><span class="nb">     file_read_line_atom</span><span class="o">(</span><span class="nb">From,Y,_</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1330" class="code_block">
</div><div id="l1331" class="code_block"><span class="nb">To </span><span class="o">=</span><span class="nb"> </span><span class="m">3</span>
</div><div id="l1332" class="code_block"><span class="nb">From </span><span class="o">=</span><span class="nb"> </span><span class="m">4</span>
</div><div id="l1333" class="code_block"><span class="nb">Stderr </span><span class="o">=</span><span class="nb"> </span><span class="m">5</span>
</div><div id="l1334" class="code_block"><span class="nb">Pid </span><span class="o">=</span><span class="nb"> </span><span class="m">14328</span>
</div><div id="l1335" class="code_block"><span class="nb">Y </span><span class="o">=</span><span class="nb"> Hello cat</span><span class="o">!</span>
</div><div id="l1336" class="code_block">
</div><div id="l1337" class="code_block"><span class="nb">yes</span>
</div><div id="l1338" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1339" class="code_block"><span class="c">%%</span>
</div><div id="l1340" class="code_block">
</div><div id="l1341" class="code_block"><span class="nb">Here we created a new process, which runs the ``{</span><span class="nv">\tt</span><span class="nb"> cat}&#39;&#39; program</span>
</div><div id="l1342" class="code_block"><span class="nb">with argument ``</span><span class="o">--</span><span class="nb">&#39;&#39;. This forces {</span><span class="nv">\tt</span><span class="nb"> cat} to read from standard input and</span>
</div><div id="l1343" class="code_block"><span class="nb">write to standard output. The next line writes a newline</span><span class="o">-</span><span class="nb">terminated string</span>
</div><div id="l1344" class="code_block"><span class="nb">to the XSB port {</span><span class="nv">\tt</span><span class="nb"> To} the, which is bound to the standard input of the</span>
</div><div id="l1345" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> cat} process. The process then copies the input to the standard output.</span>
</div><div id="l1346" class="code_block"><span class="nb">Since standard output of the process is redirected to the XSB port {</span><span class="nv">\tt</span>
</div><div id="l1347" class="code_block"><span class="nb">  From}, the last line in our program is able to read it and return in the</span>
</div><div id="l1348" class="code_block"><span class="nb">variable {</span><span class="nv">\tt</span><span class="nb"> Y}.</span>
</div><div id="l1349" class="code_block">
</div><div id="l1350" class="code_block"><span class="nb">Note that in the second line we used {</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">flush</span><span class="o">/</span><span class="m">2</span><span class="nb">}. Flushing the</span>
</div><div id="l1351" class="code_block"><span class="nb">output is extremely important here, because XSB I</span><span class="o">/</span><span class="nb">O ports are buffered.</span>
</div><div id="l1352" class="code_block"><span class="nb">Thus, {</span><span class="nv">\tt</span><span class="nb"> cat} might not see its input until the buffer is filled up, so</span>
</div><div id="l1353" class="code_block"><span class="nb">the above clause might hang. {</span><span class="nv">\tt</span><span class="nb"> file</span><span class="nv">\_</span><span class="nb">flush</span><span class="o">/</span><span class="m">2</span><span class="nb">} makes sure that the input</span>
</div><div id="l1354" class="code_block"><span class="nb">is immediately available to the subprocess.</span>
</div><div id="l1355" class="code_block">
</div><div id="l1356" class="code_block"><span class="nb">In addition to the above general schema, the user can tell</span>
</div><div id="l1357" class="code_block"><span class="nv">\verb</span><span class="nb">|spawn_process</span><span class="o">/</span><span class="m">5</span><span class="nb">| to not open one of the communication ports or to</span>
</div><div id="l1358" class="code_block"><span class="nb">use one of the existing communication ports.  This is useful when you do</span>
</div><div id="l1359" class="code_block"><span class="nb">not expect to write or read to</span><span class="o">/</span><span class="nb">from the subprocess or when one process</span>
</div><div id="l1360" class="code_block"><span class="nb">wants to write to another </span><span class="o">(</span><span class="nb">see the process plumbing example below</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1361" class="code_block">
</div><div id="l1362" class="code_block"><span class="nb">To tell that a certain port is not needed, it suffices to bind that port to</span>
</div><div id="l1363" class="code_block"><span class="nb">an atom.  For instance,</span>
</div><div id="l1364" class="code_block"><span class="c">%%</span>
</div><div id="l1365" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1366" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> spawn_process</span><span class="o">([</span><span class="nb">cat, &#39;</span><span class="o">-</span><span class="nb">&#39;</span><span class="o">]</span><span class="nb">, To, none, none, _</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1367" class="code_block"><span class="nb">     file_nl</span><span class="o">(</span><span class="nb">To</span><span class="o">)</span><span class="nb">, file_write</span><span class="o">(</span><span class="nb">To,&#39;Hello cat</span><span class="o">!</span><span class="nb">&#39;</span><span class="o">)</span><span class="nb">, file_nl</span><span class="o">(</span><span class="nb">To</span><span class="o">)</span><span class="nb">, file_flush</span><span class="o">(</span><span class="nb">To,_</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1368" class="code_block">
</div><div id="l1369" class="code_block">
</div><div id="l1370" class="code_block"><span class="nb">To </span><span class="o">=</span><span class="nb"> </span><span class="m">3</span><span class="nb">,</span>
</div><div id="l1371" class="code_block"><span class="nb">Hello cat</span><span class="o">!</span>
</div><div id="l1372" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1373" class="code_block"><span class="c">%%</span>
</div><div id="l1374" class="code_block"><span class="nb">reads from XSB and copies the result to standard output. Likewise,</span>
</div><div id="l1375" class="code_block"><span class="c">%%</span>
</div><div id="l1376" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1377" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> spawn_process</span><span class="o">(</span><span class="nb">&#39;cat test&#39;, none, From, none, _</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1378" class="code_block"><span class="nb">     file_read_line_atom</span><span class="o">(</span><span class="nb">From, S, _</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1379" class="code_block">
</div><div id="l1380" class="code_block"><span class="nb">From </span><span class="o">=</span><span class="nb"> </span><span class="m">4</span>
</div><div id="l1381" class="code_block"><span class="nb">S </span><span class="o">=</span><span class="nb"> The first line of file `test&#39;</span>
</div><div id="l1382" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1383" class="code_block"><span class="c">%%</span>
</div><div id="l1384" class="code_block"><span class="nb">In each case, only one of the ports is open. </span><span class="o">(</span><span class="nb">Note that the shell command</span>
</div><div id="l1385" class="code_block"><span class="nb">is specified as an atom rather than a list.</span><span class="o">)</span><span class="nb"> Finally, if both ports are</span>
</div><div id="l1386" class="code_block"><span class="nb">suppressed, then </span><span class="nv">\verb</span><span class="nb">|spawn_process| reduces to the usual</span>
</div><div id="l1387" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">1</span><span class="nb">} call </span><span class="o">(</span><span class="nb">in fact, this is how {</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">1</span><span class="nb">} is implemented</span><span class="o">)</span><span class="nb">:</span>
</div><div id="l1388" class="code_block"><span class="c">%%</span>
</div><div id="l1389" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1390" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> spawn_process</span><span class="o">([</span><span class="nb">pwd</span><span class="o">]</span><span class="nb">, none, none</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1391" class="code_block">
</div><div id="l1392" class="code_block"><span class="o">/</span><span class="nb">usr</span><span class="o">/</span><span class="nb">local</span><span class="o">/</span><span class="nb">foo</span><span class="o">/</span><span class="nb">bar</span>
</div><div id="l1393" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1394" class="code_block"><span class="c">%%</span>
</div><div id="l1395" class="code_block"><span class="nb">On the other hand, if any one of the three port variables in</span>
</div><div id="l1396" class="code_block"><span class="nv">\verb</span><span class="nb">|spawn_process| is bound to an already existing file port, then the</span>
</div><div id="l1397" class="code_block"><span class="nb">subprocess will use that port </span><span class="o">(</span><span class="nb">see the process plumbing example below</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1398" class="code_block">
</div><div id="l1399" class="code_block"><span class="nb">One of the uses of XSB subprocesses is to create XSB servers that spawn</span>
</div><div id="l1400" class="code_block"><span class="nb">subprocesses and control them. A spawned subprocess can be another XSB</span>
</div><div id="l1401" class="code_block"><span class="nb">process. The following example shows one XSB process spawning another,</span>
</div><div id="l1402" class="code_block"><span class="nb">sending it a goal to evaluate and obtaining the result:</span>
</div><div id="l1403" class="code_block"><span class="c">%%</span>
</div><div id="l1404" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1405" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> spawn_process</span><span class="o">([</span><span class="nb">xsb</span><span class="o">]</span><span class="nb">, To, From,Err,_</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1406" class="code_block"><span class="nb">     file_write</span><span class="o">(</span><span class="nb">To,&#39;assert</span><span class="o">(</span><span class="nb">p</span><span class="o">(</span><span class="m">1</span><span class="o">))</span><span class="nb">.&#39;</span><span class="o">)</span><span class="nb">, file_nl</span><span class="o">(</span><span class="nb">To</span><span class="o">)</span><span class="nb">, file_flush</span><span class="o">(</span><span class="nb">To,_</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1407" class="code_block"><span class="nb">     file_write</span><span class="o">(</span><span class="nb">To,&#39;p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">, writeln</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">.&#39;</span><span class="o">)</span><span class="nb">, file_nl</span><span class="o">(</span><span class="nb">To</span><span class="o">)</span><span class="nb">, file_flush</span><span class="o">(</span><span class="nb">To,_</span><span class="o">)</span><span class="nb">, </span>
</div><div id="l1408" class="code_block"><span class="nb">     file_read_line_atom</span><span class="o">(</span><span class="nb">From,XX,_</span><span class="o">)</span><span class="nb">.  </span>
</div><div id="l1409" class="code_block">
</div><div id="l1410" class="code_block"><span class="nb">XX </span><span class="o">=</span><span class="nb"> </span><span class="m">1</span>
</div><div id="l1411" class="code_block">
</div><div id="l1412" class="code_block"><span class="nb">yes</span>
</div><div id="l1413" class="code_block"><span class="nb">| ?</span><span class="o">-</span>
</div><div id="l1414" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1415" class="code_block"><span class="c">%%</span>
</div><div id="l1416" class="code_block"><span class="nb">Here the parent XSB process sends ``</span><span class="nv">\verb</span><span class="nb">|assert</span><span class="o">(</span><span class="nb">p</span><span class="o">(</span><span class="m">1</span><span class="o">))</span><span class="nb">.|&#39;&#39; and then</span>
</div><div id="l1417" class="code_block"><span class="nb">``</span><span class="nv">\verb</span><span class="nb">|p</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">, writeln</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">.|&#39;&#39; to the spawned XSB subprocess. The latter</span>
</div><div id="l1418" class="code_block"><span class="nb">evaluates the goal and prints </span><span class="o">(</span><span class="nb">via ``</span><span class="nv">\verb</span><span class="nb">|writeln</span><span class="o">(</span><span class="nb">X</span><span class="o">)</span><span class="nb">|&#39;&#39;</span><span class="o">)</span>
</div><div id="l1419" class="code_block"><span class="nb">to its standard output. The main process reads it through the {</span><span class="nv">\tt</span><span class="nb"> From}</span>
</div><div id="l1420" class="code_block"><span class="nb">port and binds the variable {</span><span class="nv">\tt</span><span class="nb"> XX} to that output.</span>
</div><div id="l1421" class="code_block">
</div><div id="l1422" class="code_block"><span class="nb">Finally, we should note that the port variables in the</span>
</div><div id="l1423" class="code_block"><span class="nv">\verb</span><span class="nb">|spawn_process| predicate can be used to do process plumbing, {</span><span class="nv">\it</span>
</div><div id="l1424" class="code_block"><span class="nb">  i.e.}, redirect output of one subprocess into the input of another. Here</span>
</div><div id="l1425" class="code_block"><span class="nb">is an example:</span>
</div><div id="l1426" class="code_block"><span class="c">%%</span>
</div><div id="l1427" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1428" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> file_open</span><span class="o">(</span><span class="nb">test,w,IOport</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1429" class="code_block"><span class="nb">     spawn_process</span><span class="o">([</span><span class="nb">cat, &#39;data&#39;</span><span class="o">]</span><span class="nb">, none, FromCat</span><span class="m">1</span><span class="nb">, none, _</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1430" class="code_block"><span class="nb">     spawn_process</span><span class="o">([</span><span class="nb">sort</span><span class="o">]</span><span class="nb">, FromCat</span><span class="m">1</span><span class="nb">, IOport, none, _</span><span class="o">)</span><span class="nb">.  </span>
</div><div id="l1431" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1432" class="code_block"><span class="c">%%</span>
</div><div id="l1433" class="code_block"><span class="nb">Here, we first open file {</span><span class="nv">\tt</span><span class="nb"> test}. Then </span><span class="nv">\verb</span><span class="nb">|cat data| is spawned.  This</span>
</div><div id="l1434" class="code_block"><span class="nb">process has the input and standard error ports blocked </span><span class="o">(</span><span class="nb">as indicated by the</span>
</div><div id="l1435" class="code_block"><span class="nb">atom {</span><span class="nv">\tt</span><span class="nb"> none}</span><span class="o">)</span><span class="nb">, and its output goes into port FromCat</span><span class="m">1</span><span class="nb">.  Then we spawn</span>
</div><div id="l1436" class="code_block"><span class="nb">another process, {</span><span class="nv">\tt</span><span class="nb"> sort}, which picks the output from the first process</span>
</div><div id="l1437" class="code_block"><span class="o">(</span><span class="nb">since it uses the port {</span><span class="nv">\tt</span><span class="nb"> FromCat</span><span class="m">1</span><span class="nb">} as its input</span><span class="o">)</span><span class="nb"> and sends its own</span>
</div><div id="l1438" class="code_block"><span class="nb">output </span><span class="o">(</span><span class="nb">the sorted version of {</span><span class="nv">\tt</span><span class="nb"> data}</span><span class="o">)</span><span class="nb"> to its output port {</span><span class="nv">\tt</span><span class="nb"> IOport}.</span>
</div><div id="l1439" class="code_block"><span class="nb">However, {</span><span class="nv">\tt</span><span class="nb"> IOport} has already been open for output into the file {</span><span class="nv">\tt</span>
</div><div id="l1440" class="code_block"><span class="nb">  test}. Thus, the overall result of the above clause is tantamount to the</span>
</div><div id="l1441" class="code_block"><span class="nb">following shell command:</span>
</div><div id="l1442" class="code_block"><span class="c">%%</span>
</div><div id="l1443" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1444" class="code_block"><span class="nb">        cat data | sort &gt; test  </span>
</div><div id="l1445" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1446" class="code_block"><span class="c">%%</span>
</div><div id="l1447" class="code_block">
</div><div id="l1448" class="code_block"><span class="nv">\paragraph</span><span class="nb">{</span><span class="nv">\em</span><span class="nb"> Important notes about spawned processes</span><span class="nv">\/</span><span class="nb">}:</span>
</div><div id="l1449" class="code_block"><span class="nv">\begin</span><span class="nb">{enumerate}</span>
</div><div id="l1450" class="code_block"><span class="nv">\item</span><span class="nb"> Asynchronous processes spawned by XSB do not disappear </span><span class="o">(</span><span class="nb">at least on</span>
</div><div id="l1451" class="code_block"><span class="nb">  Unix</span><span class="o">)</span><span class="nb"> when they terminate, </span><span class="nv">\emph</span><span class="nb">{unless} the XSB program executes a</span>
</div><div id="l1452" class="code_block"><span class="nb">  </span><span class="nv">\emph</span><span class="nb">{wait} on them </span><span class="o">(</span><span class="nb">see {</span><span class="nv">\tt</span><span class="nb"> process</span><span class="nv">\_</span><span class="nb">control} below</span><span class="o">)</span><span class="nb">. Instead, such</span>
</div><div id="l1453" class="code_block"><span class="nb">  processes become defunct </span><span class="nv">\emph</span><span class="nb">{zombies} </span><span class="o">(</span><span class="nb">in Unix terminology</span><span class="o">)</span><span class="nb">; they do</span>
</div><div id="l1454" class="code_block"><span class="nb">  not do anything, but consume resources </span><span class="o">(</span><span class="nb">such as file descriptors</span><span class="o">)</span><span class="nb">. So,</span>
</div><div id="l1455" class="code_block"><span class="nb">  when a subprocess is known to terminate, it must be waited on.</span>
</div><div id="l1456" class="code_block"><span class="nb">  </span>
</div><div id="l1457" class="code_block"><span class="nv">\item</span><span class="nb"> The XSB parent process must know how to terminate the asynchronous</span>
</div><div id="l1458" class="code_block"><span class="nb">  subprocesses it spawns. The drastic way is to kill it </span><span class="o">(</span><span class="nb">see {</span><span class="nv">\tt</span>
</div><div id="l1459" class="code_block"><span class="nb">    process</span><span class="nv">\_</span><span class="nb">control} below</span><span class="o">)</span><span class="nb">. Sometimes a subprocess might terminate by</span>
</div><div id="l1460" class="code_block"><span class="nb">  itself </span><span class="o">(</span><span class="nb">{</span><span class="nv">\it</span><span class="nb"> e.g.}, having finished reading a file</span><span class="o">)</span><span class="nb">. In other cases, the</span>
</div><div id="l1461" class="code_block"><span class="nb">  parent and the child programs must agree on a protocol by which the</span>
</div><div id="l1462" class="code_block"><span class="nb">  parent can tell the child to exit. The programs in the XSB subdirectory</span>
</div><div id="l1463" class="code_block"><span class="nb">  {</span><span class="nv">\tt</span><span class="nb"> examples</span><span class="o">/</span><span class="nb">subprocess} illustrate this idea. If the child subprocess</span>
</div><div id="l1464" class="code_block"><span class="nb">  is another XSB process, then it can be terminated by sending the atom</span>
</div><div id="l1465" class="code_block"><span class="nb">  {</span><span class="nv">\tt</span><span class="nb"> end</span><span class="nv">\_</span><span class="nb">of</span><span class="nv">\_</span><span class="nb">file} or {</span><span class="nv">\tt</span><span class="nb"> halt} to the standard input of the child.</span>
</div><div id="l1466" class="code_block"><span class="nb">  </span><span class="o">(</span><span class="nb">For this to work, the child XSB must waiting at the prompt</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1467" class="code_block"><span class="nv">\item</span><span class="nb"> It is very important to not forget to close the I</span><span class="o">/</span><span class="nb">O ports that the</span>
</div><div id="l1468" class="code_block"><span class="nb">  parent uses to communicate with the child. These are the ports that are</span>
</div><div id="l1469" class="code_block"><span class="nb">  provided in arguments </span><span class="m">2</span><span class="nb">,</span><span class="m">3</span><span class="nb">,</span><span class="m">4</span><span class="nb"> of {</span><span class="nv">\tt</span><span class="nb"> spawn</span><span class="nv">\_</span><span class="nb">process}. The reason</span>
</div><div id="l1470" class="code_block"><span class="nb">  is that the child might terminate, but these ports will remain open,</span>
</div><div id="l1471" class="code_block"><span class="nb">  since they belong to the parent process. As a result, the parent will own</span>
</div><div id="l1472" class="code_block"><span class="nb">  defunct I</span><span class="o">/</span><span class="nb">O ports and might eventually run out of file descriptors.</span>
</div><div id="l1473" class="code_block"><span class="nv">\end</span><span class="nb">{enumerate}</span>
</div><div id="l1474" class="code_block">
</div><div id="l1475" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l1476" class="code_block"><span class="nv">\ouritem</span><span class="nb">{process</span><span class="nv">\_</span><span class="nb">status</span><span class="o">(+</span><span class="nb">Pid,</span><span class="o">-</span><span class="nb">Status</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> process</span><span class="nv">\_</span><span class="nb">status</span><span class="o">/</span><span class="m">2</span><span class="nb">}} </span>
</div><div id="l1477" class="code_block"><span class="nb">    This predicate always succeeds. Given a process id, it binds the second</span>
</div><div id="l1478" class="code_block"><span class="nb">    argument </span><span class="o">(</span><span class="nb">which must be an unbound variable</span><span class="o">)</span><span class="nb"> to one of the following</span>
</div><div id="l1479" class="code_block"><span class="nb">    atoms: {</span><span class="nv">\tt</span><span class="nb"> running}, {</span><span class="nv">\tt</span><span class="nb"> stopped}, {</span><span class="nv">\tt</span><span class="nb"> exited} </span><span class="o">(</span><span class="nb">normally</span><span class="o">)</span><span class="nb">, {</span><span class="nv">\tt</span>
</div><div id="l1480" class="code_block"><span class="nb">      aborted} </span><span class="o">(</span><span class="nb">abnormally</span><span class="o">)</span><span class="nb">, {</span><span class="nv">\tt</span><span class="nb"> invalid}, and {</span><span class="nv">\tt</span><span class="nb"> unknown}.</span>
</div><div id="l1481" class="code_block"><span class="nb">    The {</span><span class="nv">\tt</span><span class="nb"> invalid} status is given to processes that never existed or</span>
</div><div id="l1482" class="code_block"><span class="nb">    that are not children of the parent XSB process. The {</span><span class="nv">\tt</span><span class="nb"> unknown}</span>
</div><div id="l1483" class="code_block"><span class="nb">    status is assigned when none of the other statuses can be assigned.</span>
</div><div id="l1484" class="code_block">
</div><div id="l1485" class="code_block"><span class="nb">    Note: process status </span><span class="o">(</span><span class="nb">other than {</span><span class="nv">\tt</span><span class="nb"> running}</span><span class="o">)</span><span class="nb"> is system dependent.</span>
</div><div id="l1486" class="code_block"><span class="nb">    Windows does not seem to support {</span><span class="nv">\tt</span><span class="nb"> stopped} and {</span><span class="nv">\tt</span><span class="nb"> aborted}.</span>
</div><div id="l1487" class="code_block"><span class="nb">    Also, processes killed using the </span><span class="nv">\verb</span><span class="nb">|process_control| predicate</span>
</div><div id="l1488" class="code_block"><span class="nb">    </span><span class="o">(</span><span class="nb">described next</span><span class="o">)</span><span class="nb"> are often marked as {</span><span class="nv">\tt</span><span class="nb"> invalid} rather than {</span><span class="nv">\tt</span>
</div><div id="l1489" class="code_block"><span class="nb">    exited}, because Windows seems to lose all information about such</span>
</div><div id="l1490" class="code_block"><span class="nb">    processes.</span>
</div><div id="l1491" class="code_block"><span class="nv">\ouritem</span><span class="nb">{process</span><span class="nv">\_</span><span class="nb">control</span><span class="o">(+</span><span class="nb">Pid,</span><span class="o">+</span><span class="nb">Operation</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> process</span><span class="nv">\_</span><span class="nb">control</span><span class="o">/</span><span class="m">2</span><span class="nb">}} </span>
</div><div id="l1492" class="code_block"><span class="nb">    Perform a process control {</span><span class="nv">\tt</span><span class="nb"> operation} on the process with the given</span>
</div><div id="l1493" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Pid}. </span>
</div><div id="l1494" class="code_block"><span class="nb">    Currently, the only supported operations are {</span><span class="nv">\tt</span><span class="nb"> kill} and {</span><span class="nv">\tt</span><span class="nb"> wait}</span>
</div><div id="l1495" class="code_block"><span class="nb">    </span><span class="o">(</span><span class="nb">both must be atoms</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1496" class="code_block"><span class="nb">    The former causes the process to exit unconditionally, and the latter</span>
</div><div id="l1497" class="code_block"><span class="nb">    waits for process completion.</span>
</div><div id="l1498" class="code_block">
</div><div id="l1499" class="code_block"><span class="nb">    This predicate succeeds, if the operation was performed successfully.</span>
</div><div id="l1500" class="code_block"><span class="nb">    Otherwise, it fails. The {</span><span class="nv">\tt</span><span class="nb"> wait} operation fails if the process</span>
</div><div id="l1501" class="code_block"><span class="nb">    specified in {</span><span class="nv">\tt</span><span class="nb"> Pid} does not exist or is not a child of the parent</span>
</div><div id="l1502" class="code_block"><span class="nb">    XSB process. </span>
</div><div id="l1503" class="code_block"><span class="nb">    </span>
</div><div id="l1504" class="code_block"><span class="nb">    The {</span><span class="nv">\tt</span><span class="nb"> kill} operation might fail, if the process to be killed does</span>
</div><div id="l1505" class="code_block"><span class="nb">    not exist or if the parent XSB process does not have the permission to</span>
</div><div id="l1506" class="code_block"><span class="nb">    terminate that process. Unix and Windows have different ideas as to</span>
</div><div id="l1507" class="code_block"><span class="nb">    what these permissions are. See </span><span class="nv">\emph</span><span class="nb">{kill</span><span class="o">(</span><span class="m">2</span><span class="o">)</span><span class="nb">} for Unix and</span>
</div><div id="l1508" class="code_block"><span class="nb">    </span><span class="nv">\emph</span><span class="nb">{TerminateProcess} for Windows.</span>
</div><div id="l1509" class="code_block"><span class="nb">    </span>
</div><div id="l1510" class="code_block"><span class="nb">    </span><span class="nv">\emph</span><span class="nb">{Note}: under Windows, the programmer&#39;s manual warns of dire</span>
</div><div id="l1511" class="code_block"><span class="nb">    consequences if one kills a process that has DLLs attached to it.</span>
</div><div id="l1512" class="code_block"><span class="nv">\ouritem</span><span class="nb">{get</span><span class="nv">\_</span><span class="nb">process</span><span class="nv">\_</span><span class="nb">table</span><span class="o">(-</span><span class="nb">ProcessList</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> get</span><span class="nv">\_</span><span class="nb">process</span><span class="nv">\_</span><span class="nb">table</span><span class="o">/</span><span class="m">1</span><span class="nb">}} </span>
</div><div id="l1513" class="code_block"><span class="nb">    This predicate is imported from module {</span><span class="nv">\tt</span><span class="nb"> shell}.</span>
</div><div id="l1514" class="code_block"><span class="nb">    It binds {</span><span class="nv">\tt</span><span class="nb"> ProcessList} to the list of terms, each describing one of</span>
</div><div id="l1515" class="code_block"><span class="nb">    the active XSB subprocesses </span><span class="o">(</span><span class="nb">created via </span><span class="nv">\verb</span><span class="nb">|spawn_process</span><span class="o">/</span><span class="m">5</span><span class="nb">|</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1516" class="code_block"><span class="nb">    Each term has the form:</span>
</div><div id="l1517" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l1518" class="code_block"><span class="nb">    </span><span class="nv">\begin</span><span class="nb">{center}</span>
</div><div id="l1519" class="code_block"><span class="nb">      </span><span class="nv">\verb</span><span class="nb">|process</span><span class="o">(</span><span class="nb">Pid,ToStream,FromStream,StderrStream,CommandLine</span><span class="o">)</span><span class="nb">|. </span>
</div><div id="l1520" class="code_block"><span class="nb">    </span><span class="nv">\end</span><span class="nb">{center}</span>
</div><div id="l1521" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l1522" class="code_block"><span class="nb">    The first argument in the term is the process id of the corresponding</span>
</div><div id="l1523" class="code_block"><span class="nb">    process, the next three arguments describe the three standard ports</span>
</div><div id="l1524" class="code_block"><span class="nb">    of the process, and the lat is an atom that shows the command line used</span>
</div><div id="l1525" class="code_block"><span class="nb">    to invoke the process.</span>
</div><div id="l1526" class="code_block"><span class="nb">    This predicate always succeeds.</span>
</div><div id="l1527" class="code_block">
</div><div id="l1528" class="code_block"><span class="nv">\ouritem</span><span class="nb">{shell</span><span class="o">(+</span><span class="nb">CmdSpec,</span><span class="o">-</span><span class="nb">StreamToProc, </span><span class="o">-</span><span class="nb">StreamFromProc, </span><span class="o">-</span><span class="nb">ProcStderr,</span>
</div><div id="l1529" class="code_block"><span class="nb">  </span><span class="o">-</span><span class="nb">ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">5</span><span class="nb">}} </span>
</div><div id="l1530" class="code_block"><span class="nb">    The arguments of this predicate are similar to those of</span>
</div><div id="l1531" class="code_block"><span class="nb">    </span><span class="nv">\verb</span><span class="nb">|spawn_process|, except for the following:</span>
</div><div id="l1532" class="code_block"><span class="nb">    </span><span class="o">(</span><span class="m">1</span><span class="o">)</span><span class="nb"> The first argument is an atom or a list of atoms, like in</span>
</div><div id="l1533" class="code_block"><span class="nb">    </span><span class="nv">\verb</span><span class="nb">|spawn_process|. However, if it is a list of atoms, then the</span>
</div><div id="l1534" class="code_block"><span class="nb">    resulting shell command is obtained by string concatenation. This is</span>
</div><div id="l1535" class="code_block"><span class="nb">    different from </span><span class="nv">\verb</span><span class="nb">|spawn_process| where each member of the list must</span>
</div><div id="l1536" class="code_block"><span class="nb">    represent an argument to the program being invoked </span><span class="o">(</span><span class="nb">and which must be</span>
</div><div id="l1537" class="code_block"><span class="nb">    the first member of that list</span><span class="o">)</span><span class="nb">.  </span><span class="o">(</span><span class="m">2</span><span class="o">)</span><span class="nb"> The last argument is the error</span>
</div><div id="l1538" class="code_block"><span class="nb">    code returned by the shell command and not a process id. The code </span><span class="o">-</span><span class="m">1</span>
</div><div id="l1539" class="code_block"><span class="nb">    and </span><span class="m">127</span><span class="nb"> mean that the shell command failed.</span>
</div><div id="l1540" class="code_block"><span class="nb">    </span>
</div><div id="l1541" class="code_block"><span class="nb">    The {</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">5</span><span class="nb">} predicate is similar to </span><span class="nv">\verb</span><span class="nb">|spawn_process| in that</span>
</div><div id="l1542" class="code_block"><span class="nb">    it spawns another process and can capture that process&#39; input and</span>
</div><div id="l1543" class="code_block"><span class="nb">    output ports.</span>
</div><div id="l1544" class="code_block"><span class="nb">    </span>
</div><div id="l1545" class="code_block"><span class="nb">    The important difference, however, is that XSB will ways until the</span>
</div><div id="l1546" class="code_block"><span class="nb">    process spawned by {</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">5</span><span class="nb">} terminates. In contrast, the process</span>
</div><div id="l1547" class="code_block"><span class="nb">    spawned by </span><span class="nv">\verb</span><span class="nb">|spawn_process| will run concurrently with XSB.  In</span>
</div><div id="l1548" class="code_block"><span class="nb">    this latter case, XSB must explicitly synchronize with the spawned</span>
</div><div id="l1549" class="code_block"><span class="nb">    subprocess using the predicate </span><span class="nv">\verb</span><span class="nb">|process_control</span><span class="o">/</span><span class="m">2</span><span class="nb">| </span><span class="o">(</span><span class="nb">using the {</span><span class="nv">\tt</span>
</div><div id="l1550" class="code_block"><span class="nb">      wait} operation</span><span class="o">)</span><span class="nb">, as described earlier.</span>
</div><div id="l1551" class="code_block"><span class="nb">    </span>
</div><div id="l1552" class="code_block"><span class="nb">    The fact that XSB must wait until {</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">5</span><span class="nb">} finishes has a very</span>
</div><div id="l1553" class="code_block"><span class="nb">    important implication: the amount of data the can be sent to and from</span>
</div><div id="l1554" class="code_block"><span class="nb">    the shell command is limited </span><span class="o">(</span><span class="m">1</span><span class="nb">K is probably safe</span><span class="o">)</span><span class="nb">. This is because the</span>
</div><div id="l1555" class="code_block"><span class="nb">    shell command communicates with XSB via pipes, which have limited</span>
</div><div id="l1556" class="code_block"><span class="nb">    capacity.  So, if the pipe is filled, XSB will hang waiting for {</span><span class="nv">\tt</span>
</div><div id="l1557" class="code_block"><span class="nb">      shell</span><span class="o">/</span><span class="m">5</span><span class="nb">} to finish and {</span><span class="nv">\tt</span><span class="nb"> shel</span><span class="o">/</span><span class="m">5</span><span class="nb">} will wait for XSB to consume data</span>
</div><div id="l1558" class="code_block"><span class="nb">    from the pipe.  Thus, use </span><span class="nv">\verb</span><span class="nb">|spawn_process</span><span class="o">/</span><span class="m">5</span><span class="nb">| for any kind of</span>
</div><div id="l1559" class="code_block"><span class="nb">    significant data exchange between external processes and XSB.</span>
</div><div id="l1560" class="code_block"><span class="nb">  </span>
</div><div id="l1561" class="code_block"><span class="nb">  Another difference between these two forms of spawning subprocesses is</span>
</div><div id="l1562" class="code_block"><span class="nb">  that {</span><span class="nv">\tt</span><span class="nb"> CmdSpec} in {</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">5</span><span class="nb">} can represent </span><span class="nv">\emph</span><span class="nb">{any} shell</span>
</div><div id="l1563" class="code_block"><span class="nb">  statement, including those that have pipes and I</span><span class="o">/</span><span class="nb">O redirection. In</span>
</div><div id="l1564" class="code_block"><span class="nb">  contrast, </span><span class="nv">\verb</span><span class="nb">|spawn_process| only allows command of the form ``program</span>
</div><div id="l1565" class="code_block"><span class="nb">  args&#39;&#39;. For instance,</span>
</div><div id="l1566" class="code_block"><span class="c">%%</span>
</div><div id="l1567" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1568" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> file_open</span><span class="o">(</span><span class="nb">test,w,IOport</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1569" class="code_block"><span class="nb">     shell</span><span class="o">(</span><span class="nb">&#39;cat | sort &gt; data&#39;, IOport, none, none, ErrCode</span><span class="o">)</span>
</div><div id="l1570" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1571" class="code_block"><span class="c">%%</span>
</div><div id="l1572" class="code_block"><span class="nb">As seen from this example, the same rules for blocking I</span><span class="o">/</span><span class="nb">O streams</span>
</div><div id="l1573" class="code_block"><span class="nb">apply to {</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">5</span><span class="nb">}. Finally, we should note that the already familiar</span>
</div><div id="l1574" class="code_block"><span class="nb">standard predicates {</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">1</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">2</span><span class="nb">} are implemented using</span>
</div><div id="l1575" class="code_block"><span class="nb">shell</span><span class="o">/</span><span class="m">5</span><span class="nb">.</span>
</div><div id="l1576" class="code_block">
</div><div id="l1577" class="code_block"><span class="nv">\paragraph</span><span class="nb">{</span><span class="nv">\em</span><span class="nb"> Notes:}</span>
</div><div id="l1578" class="code_block"><span class="c">%%</span>
</div><div id="l1579" class="code_block"><span class="nv">\begin</span><span class="nb">{enumerate}</span>
</div><div id="l1580" class="code_block"><span class="nb">  </span><span class="nv">\item</span><span class="nb">  With {</span><span class="nv">\tt</span><span class="nb"> shell</span><span class="o">/</span><span class="m">5</span><span class="nb">}, you do not have to worry about terminating</span>
</div><div id="l1581" class="code_block"><span class="nb">    child processes: XSB waits until the child exits automatically.</span>
</div><div id="l1582" class="code_block"><span class="nb">    However, since communication pipes have limited capacity, this method</span>
</div><div id="l1583" class="code_block"><span class="nb">    can be used only for exchanging small amounts of information between</span>
</div><div id="l1584" class="code_block"><span class="nb">    parent and child.</span>
</div><div id="l1585" class="code_block"><span class="nb">  </span><span class="nv">\item</span><span class="nb"> The earlier remark about the need to close I</span><span class="o">/</span><span class="nb">O streams to the child</span>
</div><div id="l1586" class="code_block"><span class="nb">    </span><span class="nv">\emph</span><span class="nb">{does} apply.</span>
</div><div id="l1587" class="code_block"><span class="nv">\end</span><span class="nb">{enumerate}</span>
</div><div id="l1588" class="code_block"><span class="c">%%</span>
</div><div id="l1589" class="code_block">
</div><div id="l1590" class="code_block"><span class="nv">\ouritem</span><span class="nb">{pipe</span><span class="nv">\_</span><span class="nb">open</span><span class="o">(-</span><span class="nb">ReadPipe, </span><span class="o">-</span><span class="nb">WritePipe</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> pipe</span><span class="nv">\_</span><span class="nb">open</span><span class="o">/</span><span class="m">2</span><span class="nb">}} </span>
</div><div id="l1591" class="code_block"><span class="nb">  Open a new pipe and return the read end and the write end of that pipe.</span>
</div><div id="l1592" class="code_block"><span class="nb">  If the operation fails, both {</span><span class="nv">\tt</span><span class="nb"> ReadPipe} and {</span><span class="nv">\tt</span><span class="nb"> WritePipe} are bound</span>
</div><div id="l1593" class="code_block"><span class="nb">  to negative numbers.</span>
</div><div id="l1594" class="code_block"><span class="nb">  </span>
</div><div id="l1595" class="code_block"><span class="nb">  The pipes returned by the {</span><span class="nv">\tt</span><span class="nb"> pipe</span><span class="nv">\_</span><span class="nb">open</span><span class="o">/</span><span class="m">2</span><span class="nb">} predicate are small integers</span>
</div><div id="l1596" class="code_block"><span class="nb">  that represent file descriptors used by the underlying OS. They are {</span><span class="nv">\bf</span>
</div><div id="l1597" class="code_block"><span class="nb">    not XSB I</span><span class="o">/</span><span class="nb">O ports}, and they cannot be used for I</span><span class="o">/</span><span class="nb">O directly. To</span>
</div><div id="l1598" class="code_block"><span class="nb">  use them, one must call the {</span><span class="nv">\tt</span><span class="nb"> fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">/</span><span class="m">2</span><span class="nb">} predicate, as described</span>
</div><div id="l1599" class="code_block"><span class="nb">  next.</span><span class="nv">\footnote</span><span class="nb">{</span>
</div><div id="l1600" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l1601" class="code_block"><span class="nb">    XSB does not convert pipes into I</span><span class="o">/</span><span class="nb">O ports automatically.</span>
</div><div id="l1602" class="code_block"><span class="nb">    Because of the way XSB I</span><span class="o">/</span><span class="nb">O ports are represented, they are not</span>
</div><div id="l1603" class="code_block"><span class="nb">    inherited by the child process and they do not make sense to the child</span>
</div><div id="l1604" class="code_block"><span class="nb">    process </span><span class="o">(</span><span class="nb">especially if the child is not another xsb</span><span class="o">)</span><span class="nb">. Therefore, we</span>
</div><div id="l1605" class="code_block"><span class="nb">    must pass the child processes an OS file descriptor instead. The child then</span>
</div><div id="l1606" class="code_block"><span class="nb">    converts these descriptor into XSB I</span><span class="o">/</span><span class="nb">O ports.</span>
</div><div id="l1607" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l1608" class="code_block"><span class="nb">    }</span>
</div><div id="l1609" class="code_block"><span class="nv">\ouritem</span><span class="nb">{fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">(+</span><span class="nb">Pipe, </span><span class="o">-</span><span class="nb">IOport</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">/</span><span class="m">2</span><span class="nb">}} </span>
</div><div id="l1610" class="code_block"><span class="nb">    Take a pipe and convert it to an XSB I</span><span class="o">/</span><span class="nb">O port that can be used</span>
</div><div id="l1611" class="code_block"><span class="nb">    for I</span><span class="o">/</span><span class="nb">O. This predicate is needed because pipes must be associated with</span>
</div><div id="l1612" class="code_block"><span class="nb">    XSB I</span><span class="o">/</span><span class="nb">O ports before any I</span><span class="o">/</span><span class="nb">O can be on them by an XSB program.</span>
</div><div id="l1613" class="code_block">
</div><div id="l1614" class="code_block"><span class="nb">    The best way to illustrate how one can create a new pipe to a child</span>
</div><div id="l1615" class="code_block"><span class="nb">    </span><span class="o">(</span><span class="nb">even if the child has been created earlier</span><span class="o">)</span><span class="nb"> is to show an example.</span>
</div><div id="l1616" class="code_block"><span class="nb">    Consider two programs, {</span><span class="nv">\tt</span><span class="nb"> parent.P} and {</span><span class="nv">\tt</span><span class="nb"> child.P}. The parent</span>
</div><div id="l1617" class="code_block"><span class="nb">    copy of XSB consults {</span><span class="nv">\tt</span><span class="nb"> parent.P}, which does the following: First, it</span>
</div><div id="l1618" class="code_block"><span class="nb">    creates a pipe and spawns a copy of XSB. Then it tells the</span>
</div><div id="l1619" class="code_block"><span class="nb">    child copy of XSB to assert the fact {</span><span class="nv">\tt</span><span class="nb"> pipe</span><span class="o">(</span><span class="nb">RP</span><span class="o">)</span><span class="nb">}, where {</span><span class="nv">\tt</span><span class="nb"> RP} is</span>
</div><div id="l1620" class="code_block"><span class="nb">    a number representing the read part of the pipe. Next, the parent XSB tells</span>
</div><div id="l1621" class="code_block"><span class="nb">    the child XSB to consult the program {</span><span class="nv">\tt</span><span class="nb"> child.P}. Finally, it sends</span>
</div><div id="l1622" class="code_block"><span class="nb">    the message {</span><span class="nv">\tt</span><span class="nb"> Hello</span><span class="o">!</span><span class="nb">}.</span>
</div><div id="l1623" class="code_block">
</div><div id="l1624" class="code_block"><span class="nb">    The {</span><span class="nv">\tt</span><span class="nb"> child.P} program gets the pipe from predicate {</span><span class="nv">\tt</span><span class="nb"> pipe</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l1625" class="code_block"><span class="nb">    </span><span class="o">(</span><span class="nb">note that the parent tells the child XSB to first assert {</span><span class="nv">\tt</span>
</div><div id="l1626" class="code_block"><span class="nb">    pipe</span><span class="o">(</span><span class="nb">RP</span><span class="o">)</span><span class="nb">} and only then to consult the {</span><span class="nv">\tt</span><span class="nb"> child.P} file</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1627" class="code_block"><span class="nb">  After that, the child reads a message from the pipe and prints it to its</span>
</div><div id="l1628" class="code_block"><span class="nb">    standard output. Both programs are shown below:</span>
</div><div id="l1629" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l1630" class="code_block"><span class="nb">    </span><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1631" class="code_block"><span class="c">%% parent.p      </span>
</div><div id="l1632" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> import pipe_open</span><span class="o">/</span><span class="m">2</span><span class="nb">, fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">/</span><span class="m">2</span><span class="nb">, fmt_write</span><span class="o">/</span><span class="m">3</span><span class="nb">, file_flush</span><span class="o">/</span><span class="m">2</span><span class="nb"> from file_io.</span>
</div><div id="l1633" class="code_block"><span class="c">%% Create the pipe and pass it to the child process</span>
</div><div id="l1634" class="code_block"><span class="nb">?</span><span class="o">-</span><span class="nb"> pipe_open</span><span class="o">(</span><span class="nb">RP,WP</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1635" class="code_block"><span class="nb">   </span><span class="c">%% WF is now the XSB I/O port bound to the write part of the pipe</span>
</div><div id="l1636" class="code_block"><span class="nb">   fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">(</span><span class="nb">WP,WF</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1637" class="code_block"><span class="nb">   </span><span class="c">%% We aren&#39;t going to read from child, so let&#39;s close the pipe coming </span>
</div><div id="l1638" class="code_block"><span class="nb">   </span><span class="c">%% from it -- we don&#39;t want to run out of file descriptors!!!</span>
</div><div id="l1639" class="code_block"><span class="nb">   fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">(</span><span class="nb">RP,RF</span><span class="o">)</span><span class="nb">, file_close</span><span class="o">(</span><span class="nb">RF</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1640" class="code_block"><span class="nb">   </span><span class="c">%% ProcInput becomes the XSB stream leading directly to the child&#39;s stdin</span>
</div><div id="l1641" class="code_block"><span class="nb">   spawn_process</span><span class="o">(</span><span class="nb">xsb, ProcInput, block, block, Process</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1642" class="code_block"><span class="nb">   </span><span class="c">%% Tell the child where the reading part of the pipe is</span>
</div><div id="l1643" class="code_block"><span class="nb">   fmt_write</span><span class="o">(</span><span class="nb">ProcInput, &quot;assert</span><span class="o">(</span><span class="nb">pipe</span><span class="o">(</span><span class="c">%d)).\n&quot;, arg(RP)),</span>
</div><div id="l1644" class="code_block"><span class="nb">   fmt_write</span><span class="o">(</span><span class="nb">ProcInput, &quot;</span><span class="o">[</span><span class="nb">child</span><span class="o">]</span><span class="nb">.</span><span class="nv">\n</span><span class="nb">&quot;, _</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1645" class="code_block"><span class="nb">   file_flush</span><span class="o">(</span><span class="nb">ProcInput, _</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1646" class="code_block"><span class="nb">   </span><span class="c">%% Pass a message through the pipe</span>
</div><div id="l1647" class="code_block"><span class="nb">   fmt_write</span><span class="o">(</span><span class="nb">WF, &quot;Hello</span><span class="o">!</span><span class="nv">\n</span><span class="nb">&quot;, _</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1648" class="code_block"><span class="nb">   file_flush</span><span class="o">(</span><span class="nb">WF, _</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1649" class="code_block"><span class="nb">   fmt_write</span><span class="o">(</span><span class="nb">ProcInput, &quot;end_of_file.</span><span class="nv">\n</span><span class="nb">&quot;,_</span><span class="o">)</span><span class="nb">, </span><span class="c">% send end_of_file atom to child</span>
</div><div id="l1650" class="code_block"><span class="nb">   file_flush</span><span class="o">(</span><span class="nb">ProcInput, _</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1651" class="code_block"><span class="nb">   </span><span class="c">%% wait for child (so as to not leave zombies around; </span>
</div><div id="l1652" class="code_block"><span class="nb">   </span><span class="c">%% zombies quit when the parent finishes, but they consume resources)</span>
</div><div id="l1653" class="code_block"><span class="nb">   process_control</span><span class="o">(</span><span class="nb">Process, wait</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1654" class="code_block"><span class="nb">   </span><span class="c">%% Close the ports used to commuicate with the process</span>
</div><div id="l1655" class="code_block"><span class="nb">   </span><span class="c">%% Otherwise, the parent might run out of file descriptors </span>
</div><div id="l1656" class="code_block"><span class="nb">   </span><span class="c">%% (if many processes were spawned)</span>
</div><div id="l1657" class="code_block"><span class="nb">   file_close</span><span class="o">(</span><span class="nb">ProcInput</span><span class="o">)</span><span class="nb">, file_close</span><span class="o">(</span><span class="nb">WF</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1658" class="code_block"><span class="nb">    </span><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1659" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l1660" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l1661" class="code_block"><span class="nb">    </span><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1662" class="code_block"><span class="c">%% child.P</span>
</div><div id="l1663" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> import fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">/</span><span class="m">2</span><span class="nb"> from file_io.</span>
</div><div id="l1664" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> import file_read_line_atom</span><span class="o">/</span><span class="m">3</span><span class="nb"> from file_io.</span>
</div><div id="l1665" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> dynamic pipe</span><span class="o">/</span><span class="m">1</span><span class="nb">.</span>
</div><div id="l1666" class="code_block"><span class="nb">?</span><span class="o">-</span><span class="nb"> pipe</span><span class="o">(</span><span class="nb">P</span><span class="o">)</span><span class="nb">, fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">(</span><span class="nb">P,F</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1667" class="code_block"><span class="nb">   </span><span class="c">%% Acknowledge receipt of the pipe</span>
</div><div id="l1668" class="code_block"><span class="nb">   fmt_write</span><span class="o">(</span><span class="nb">&quot;</span><span class="nv">\nPipe</span><span class="nb"> </span><span class="c">%d received\n&quot;, arg(P)),</span>
</div><div id="l1669" class="code_block"><span class="nb">   </span><span class="c">%% Get a message from the parent and print it to stdout</span>
</div><div id="l1670" class="code_block"><span class="nb">   file_read_line_atom</span><span class="o">(</span><span class="nb">F, Line,_</span><span class="o">)</span><span class="nb">, write</span><span class="o">(</span><span class="nb">&#39;Message was: &#39;</span><span class="o">)</span><span class="nb">, writeln</span><span class="o">(</span><span class="nb">Line</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1671" class="code_block"><span class="nb">    </span><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1672" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l1673" class="code_block"><span class="nb">    This produces the following output:</span>
</div><div id="l1674" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l1675" class="code_block"><span class="nb">    </span><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1676" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> </span><span class="o">[</span><span class="nb">parent</span><span class="o">]</span><span class="nb">.                    &lt;</span><span class="o">-</span><span class="nb"> parent XSB consults parent.P</span>
</div><div id="l1677" class="code_block"><span class="o">[</span><span class="nb">parent loaded</span><span class="o">]</span>
</div><div id="l1678" class="code_block"><span class="nb">yes</span>
</div><div id="l1679" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> </span><span class="o">[</span><span class="nb">xsb_configuration loaded</span><span class="o">]</span><span class="nb">   &lt;</span><span class="o">-</span><span class="nb"> parent.P spawns a child copy of XSB</span>
</div><div id="l1680" class="code_block"><span class="o">[</span><span class="nb">sysinitrc loaded</span><span class="o">]</span><span class="nb">                   Here we see the startup messages of</span>
</div><div id="l1681" class="code_block"><span class="o">[</span><span class="nb">packaging loaded</span><span class="o">]</span><span class="nb">                   the child copy</span>
</div><div id="l1682" class="code_block"><span class="nb">XSB Version </span><span class="m">2</span><span class="nb">.</span><span class="m">0</span><span class="nb"> </span><span class="o">(</span><span class="nb">Gouden Carolus</span><span class="o">)</span><span class="nb"> of June </span><span class="m">27</span><span class="nb">, </span><span class="m">1999</span>
</div><div id="l1683" class="code_block"><span class="o">[</span><span class="nb">i</span><span class="m">686</span><span class="o">-</span><span class="nb">pc</span><span class="o">-</span><span class="nb">linux</span><span class="o">-</span><span class="nb">gnu; mode: optimal; engine: slg</span><span class="o">-</span><span class="nb">wam; scheduling: batched</span><span class="o">]</span>
</div><div id="l1684" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> </span>
</div><div id="l1685" class="code_block"><span class="nb">yes</span>
</div><div id="l1686" class="code_block"><span class="nb">| ?</span><span class="o">-</span><span class="nb"> </span><span class="o">[</span><span class="nb">Compiling .</span><span class="o">/</span><span class="nb">child</span><span class="o">]</span><span class="nb">          &lt;</span><span class="o">-</span><span class="nb"> The child copy of received the pipe from</span>
</div><div id="l1687" class="code_block"><span class="o">[</span><span class="nb">child compiled, cpu time used: </span><span class="m">0</span><span class="nb">.</span><span class="m">1300</span><span class="nb"> seconds</span><span class="o">]</span><span class="nb">     the parent and then the</span>
</div><div id="l1688" class="code_block"><span class="o">[</span><span class="nb">child loaded</span><span class="o">]</span><span class="nb">                                      request to consult child.P</span>
</div><div id="l1689" class="code_block"><span class="nb">Pipe </span><span class="m">15</span><span class="nb"> received                  &lt;</span><span class="o">-</span><span class="nb"> child.P acknowledges receipt of the pipe</span>
</div><div id="l1690" class="code_block"><span class="nb">Message was: Hello</span><span class="o">!</span><span class="nb">               &lt;</span><span class="o">-</span><span class="nb"> child.P gets the message and prints it</span>
</div><div id="l1691" class="code_block"><span class="nb">yes       </span>
</div><div id="l1692" class="code_block"><span class="nb">    </span><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1693" class="code_block"><span class="nb">    </span><span class="c">%%</span>
</div><div id="l1694" class="code_block"><span class="nb">    </span>
</div><div id="l1695" class="code_block"><span class="nb">    Observe that the parent process is very careful about making sure that</span>
</div><div id="l1696" class="code_block"><span class="nb">    the child terminates and also about closing the I</span><span class="o">/</span><span class="nb">O ports after they</span>
</div><div id="l1697" class="code_block"><span class="nb">    are no longer needed.</span>
</div><div id="l1698" class="code_block"><span class="nb">    </span>
</div><div id="l1699" class="code_block"><span class="nb">    Finally, we should note that this mechanism can be used to communicate</span>
</div><div id="l1700" class="code_block"><span class="nb">    through pipes with non</span><span class="o">-</span><span class="nb">XSB processes as well. Indeed, an XSB process</span>
</div><div id="l1701" class="code_block"><span class="nb">    can create a pipe using {</span><span class="nv">\tt</span><span class="nb"> pipe</span><span class="nv">\_</span><span class="nb">open} </span><span class="o">(</span><span class="nv">\emph</span><span class="nb">{before} spawning a</span>
</div><div id="l1702" class="code_block"><span class="nb">    child process</span><span class="o">)</span><span class="nb">, pass one end of the pipe to a child process </span><span class="o">(</span><span class="nb">which can</span>
</div><div id="l1703" class="code_block"><span class="nb">    be a C program</span><span class="o">)</span><span class="nb">, and use {</span><span class="nv">\tt</span><span class="nb"> fd</span><span class="m">2</span><span class="nb">ioport} to convert the other end of</span>
</div><div id="l1704" class="code_block"><span class="nb">    the pipe to an XSB file. The C program, of course, does not need {</span><span class="nv">\tt</span>
</div><div id="l1705" class="code_block"><span class="nb">      fd</span><span class="m">2</span><span class="nb">ioport}, since it can use the pipe file handle directly. Likewise,</span>
</div><div id="l1706" class="code_block"><span class="nb">    a C program can spawn off an XSB process and pass it one end of a pipe.</span>
</div><div id="l1707" class="code_block"><span class="nb">    The XSB child</span><span class="o">-</span><span class="nb">process can then convert this pipe fd to a file using</span>
</div><div id="l1708" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> fd</span><span class="m">2</span><span class="nb">ioport} and then talk to the paren C program.</span>
</div><div id="l1709" class="code_block">
</div><div id="l1710" class="code_block"><span class="nv">\ouritem</span><span class="nb">{sys</span><span class="nv">\_</span><span class="nb">exit</span><span class="o">(-</span><span class="nb">ExitCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> sys</span><span class="nv">\_</span><span class="nb">exit</span><span class="o">/</span><span class="m">1</span><span class="nb">}} </span>
</div><div id="l1711" class="code_block"><span class="nb">This predicate causes XSB subprocess to exit unconditionally with the exit</span>
</div><div id="l1712" class="code_block"><span class="nb">code {</span><span class="nv">\tt</span><span class="nb"> ExitCode}. Normally {</span><span class="nv">\tt</span><span class="nb"> </span><span class="m">0</span><span class="nb">} is considered to indicate normal</span>
</div><div id="l1713" class="code_block"><span class="nb">termination, while other exit codes are used to report various degrees of</span>
</div><div id="l1714" class="code_block"><span class="nb">abnormality.</span>
</div><div id="l1715" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l1716" class="code_block">
</div><div id="l1717" class="code_block">
</div><div id="l1718" class="code_block">
</div><div id="l1719" class="code_block"><span class="nv">\section</span><span class="nb">{Socket I</span><span class="o">/</span><span class="nb">O}</span>
</div><div id="l1720" class="code_block">
</div><div id="l1721" class="code_block"><span class="nb">The XSB socket library defines a number of predicates for communication</span>
</div><div id="l1722" class="code_block"><span class="nb">over BSD</span><span class="o">-</span><span class="nb">style sockets. Most are modeled after and are interfaces to the</span>
</div><div id="l1723" class="code_block"><span class="nb">socket functions with the same name. For detailed information on sockets,</span>
</div><div id="l1724" class="code_block"><span class="nb">the reader is referred to the Unix man pages </span><span class="o">(</span><span class="nb">another good source is</span>
</div><div id="l1725" class="code_block"><span class="nv">\emph</span><span class="nb">{Unix Network Programming}, by W.  Richard Stevens</span><span class="o">)</span><span class="nb">.  Several examples</span>
</div><div id="l1726" class="code_block"><span class="nb">of the use of the XSB sockets interface can be found in the {</span><span class="nv">\tt</span><span class="nb"> XSB</span><span class="o">/</span><span class="nb">examples</span><span class="o">/</span><span class="nb">}</span>
</div><div id="l1727" class="code_block"><span class="nb">directory in the XSB distribution.</span>
</div><div id="l1728" class="code_block">
</div><div id="l1729" class="code_block">
</div><div id="l1730" class="code_block"><span class="nb">XSB supports two modes of communication via sockets: </span><span class="nv">\emph</span><span class="nb">{stream</span><span class="o">-</span><span class="nb">oriented}</span>
</div><div id="l1731" class="code_block"><span class="nb">and </span><span class="nv">\emph</span><span class="nb">{message</span><span class="o">-</span><span class="nb">oriented}. In turn, stream</span><span class="o">-</span><span class="nb">oriented communication can be</span>
</div><div id="l1732" class="code_block"><span class="nv">\emph</span><span class="nb">{buffered} or </span><span class="nv">\emph</span><span class="nb">{character</span><span class="o">-</span><span class="nb">at</span><span class="o">-</span><span class="nb">a</span><span class="o">-</span><span class="nb">time}.</span>
</div><div id="l1733" class="code_block">
</div><div id="l1734" class="code_block"><span class="nb">To use </span><span class="nv">\emph</span><span class="nb">{buffered} stream</span><span class="o">-</span><span class="nb">oriented communication, system socket</span>
</div><div id="l1735" class="code_block"><span class="nb">handles must be converted to XSB I</span><span class="o">/</span><span class="nb">O ports using {</span><span class="nv">\tt</span><span class="nb"> fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">/</span><span class="m">2</span><span class="nb">} and then</span>
</div><div id="l1736" class="code_block"><span class="nb">the regular low</span><span class="o">-</span><span class="nb">level file I</span><span class="o">/</span><span class="nb">O primitives </span><span class="o">(</span><span class="nb">described in</span>
</div><div id="l1737" class="code_block"><span class="nb">Section~</span><span class="nv">\ref</span><span class="nb">{sec</span><span class="o">-</span><span class="nb">low</span><span class="o">-</span><span class="nb">level</span><span class="o">-</span><span class="nb">io}</span><span class="o">)</span><span class="nb"> are used. In stream</span><span class="o">-</span><span class="nb">oriented communication,</span>
</div><div id="l1738" class="code_block"><span class="nb">messages have no boundaries, and communication appears to the processes</span>
</div><div id="l1739" class="code_block"><span class="nb">as reading and writing to a file.  At present, buffered stream</span><span class="o">-</span><span class="nb">oriented</span>
</div><div id="l1740" class="code_block"><span class="nb">communication works under Unix only.</span>
</div><div id="l1741" class="code_block">
</div><div id="l1742" class="code_block"><span class="nv">\emph</span><span class="nb">{Character</span><span class="o">-</span><span class="nb">at</span><span class="o">-</span><span class="nb">a</span><span class="o">-</span><span class="nb">time} stream communication is accomplished using</span>
</div><div id="l1743" class="code_block"><span class="nb">the primitives {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">put</span><span class="o">/</span><span class="m">3</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">get</span><span class="m">0</span><span class="o">/</span><span class="m">3</span><span class="nb">}. These</span>
</div><div id="l1744" class="code_block"><span class="nb">correspond to the usual Prolog {</span><span class="nv">\tt</span><span class="nb"> put</span><span class="o">/</span><span class="m">1</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> get</span><span class="m">0</span><span class="o">/</span><span class="m">1</span><span class="nb">} I</span><span class="o">/</span><span class="nb">O primitives.</span>
</div><div id="l1745" class="code_block">
</div><div id="l1746" class="code_block"><span class="nb">In message</span><span class="o">-</span><span class="nb">oriented communication, processes exchange messages that have</span>
</div><div id="l1747" class="code_block"><span class="nb">well</span><span class="o">-</span><span class="nb">defined boundaries. The communicating processes use {</span><span class="nv">\tt</span>
</div><div id="l1748" class="code_block"><span class="nb">  socket</span><span class="nv">\_</span><span class="nb">send</span><span class="o">/</span><span class="m">3</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">recv</span><span class="o">/</span><span class="m">3</span><span class="nb">} to talk to each other.</span>
</div><div id="l1749" class="code_block"><span class="nb">XSB messages are represented as strings where the first four bytes</span>
</div><div id="l1750" class="code_block"><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> sizeof</span><span class="o">(</span><span class="nb">int</span><span class="o">)</span><span class="nb">}</span><span class="o">)</span><span class="nb"> is an integer </span><span class="o">(</span><span class="nb">represented in the binary network format</span>
</div><div id="l1751" class="code_block"><span class="o">---</span><span class="nb"> see the functions {</span><span class="nv">\tt</span><span class="nb"> htonl} and {</span><span class="nv">\tt</span><span class="nb"> ntohl} in socket documentation</span><span class="o">)</span>
</div><div id="l1752" class="code_block"><span class="nb">and the rest is the body of the message. The integer in the header</span>
</div><div id="l1753" class="code_block"><span class="nb">represents the length of the message body.</span>
</div><div id="l1754" class="code_block">
</div><div id="l1755" class="code_block"><span class="nb">We now describe the XSB socket interface.  All predicates below must be</span>
</div><div id="l1756" class="code_block"><span class="nb">imported from the module {</span><span class="nv">\tt</span><span class="nb"> socket}. Note that almost all predicates have</span>
</div><div id="l1757" class="code_block"><span class="nb">the last argument that unifies with the error code returned from the</span>
</div><div id="l1758" class="code_block"><span class="nb">corresponding socket operation. This argument is explained separately.</span>
</div><div id="l1759" class="code_block">
</div><div id="l1760" class="code_block"><span class="nv">\paragraph</span><span class="nb">{General socket calls.}</span>
</div><div id="l1761" class="code_block"><span class="nb">These are used to open</span><span class="o">/</span><span class="nb">close sockets, to establish connections, and set</span>
</div><div id="l1762" class="code_block"><span class="nb">special socket options.</span>
</div><div id="l1763" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l1764" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="o">(-</span><span class="nb">Sockfd, ?ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l1765" class="code_block"><span class="nb">    A socket {</span><span class="nv">\tt</span><span class="nb"> Sockfd}  in the AF</span><span class="nv">\_</span><span class="nb">INET domain is created.</span>
</div><div id="l1766" class="code_block"><span class="nb">    </span><span class="o">(</span><span class="nb">The AF</span><span class="nv">\_</span><span class="nb">UNIX domain is not yet implemented</span><span class="o">)</span><span class="nb">. </span>
</div><div id="l1767" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Sockfd} is bound to a small integer, called socket descriptor or</span>
</div><div id="l1768" class="code_block"><span class="nb">    socket handle.</span>
</div><div id="l1769" class="code_block">
</div><div id="l1770" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">set</span><span class="nv">\_</span><span class="nb">option</span><span class="o">(+</span><span class="nb">Sockfd,</span><span class="o">+</span><span class="nb">OptionName,</span><span class="o">+</span><span class="nb">Value</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">set</span><span class="nv">\_</span><span class="nb">option</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l1771" class="code_block"><span class="nb">    Set socket option. At present, only the {</span><span class="nv">\tt</span><span class="nb"> linger} option is</span>
</div><div id="l1772" class="code_block"><span class="nb">    supported. ``Lingering&#39;&#39; is a situation when a socket continues to live</span>
</div><div id="l1773" class="code_block"><span class="nb">    after it was shut down by the owner. This is used in order to let the</span>
</div><div id="l1774" class="code_block"><span class="nb">    client program that uses the socket to finish reading or writing</span>
</div><div id="l1775" class="code_block"><span class="nb">    from</span><span class="o">/</span><span class="nb">to the socket. {</span><span class="nv">\tt</span><span class="nb"> Value} represents the number of seconds to linger.</span>
</div><div id="l1776" class="code_block"><span class="nb">    The value </span><span class="o">-</span><span class="m">1</span><span class="nb"> means do not linger at all.</span>
</div><div id="l1777" class="code_block">
</div><div id="l1778" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">close</span><span class="o">(+</span><span class="nb">Sockfd, ?ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">close</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l1779" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Sockfd} is closed. Sockets used in {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">connect</span><span class="o">/</span><span class="m">2</span><span class="nb">}  should</span>
</div><div id="l1780" class="code_block"><span class="nb">    not be closed by {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">close</span><span class="o">/</span><span class="m">1</span><span class="nb">}  as they will be closed when the</span>
</div><div id="l1781" class="code_block"><span class="nb">    corresponding stream is closed.</span>
</div><div id="l1782" class="code_block">
</div><div id="l1783" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">bind</span><span class="o">(+</span><span class="nb">Sockfd,</span><span class="o">+</span><span class="nb">Port, ?ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">bind</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l1784" class="code_block"><span class="nb">   The socket {</span><span class="nv">\tt</span><span class="nb"> Sockfd}  is bound to the specified local port number.</span>
</div><div id="l1785" class="code_block">
</div><div id="l1786" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">connect</span><span class="o">(+</span><span class="nb">Sockfd,</span><span class="o">+</span><span class="nb">Port,</span><span class="o">+</span><span class="nb">Hostname,?ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">connect</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l1787" class="code_block"><span class="nb">    The socket Sockfd is connected to the address </span><span class="o">(</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Hostname}  and</span>
</div><div id="l1788" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Port}</span><span class="o">)</span><span class="nb">. If {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">connect</span><span class="o">/</span><span class="m">4</span><span class="nb">} terminates abnormally for any reason</span>
</div><div id="l1789" class="code_block"><span class="o">(</span><span class="nb">connection refused, timeout, etc.</span><span class="o">)</span><span class="nb">, then XSb closes the socket {</span><span class="nv">\tt</span>
</div><div id="l1790" class="code_block"><span class="nb">    Sockfd} automatically, because such a socket cannot be used according</span>
</div><div id="l1791" class="code_block"><span class="nb">    to the BSD semantics. Therefore, it is always a good idea to check to</span>
</div><div id="l1792" class="code_block"><span class="nb">    the return code and reopen the socket, if the error code is not</span>
</div><div id="l1793" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> SOCK</span><span class="nv">\_</span><span class="nb">OK}.</span>
</div><div id="l1794" class="code_block">
</div><div id="l1795" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">listen</span><span class="o">(+</span><span class="nb">Socket, </span><span class="o">+</span><span class="nb">Length, ?ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">listen</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l1796" class="code_block"><span class="nb">    The socket {</span><span class="nv">\tt</span><span class="nb"> Sockfd}  is defined to have a maximum backlog queue of</span>
</div><div id="l1797" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Length}  pending connections.</span>
</div><div id="l1798" class="code_block">
</div><div id="l1799" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">accept</span><span class="o">(+</span><span class="nb">Sockfd,</span><span class="o">-</span><span class="nb">SockOut, ?ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">accept</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l1800" class="code_block"><span class="nb">    Block the caller until a connection attempt arrives. If the incoming </span>
</div><div id="l1801" class="code_block"><span class="nb">    queue is not empty, the first connection request is accepted, the call</span>
</div><div id="l1802" class="code_block"><span class="nb">    succeeds and returns a new socket, {</span><span class="nv">\tt</span><span class="nb"> SockOut}, which can be used for</span>
</div><div id="l1803" class="code_block"><span class="nb">    this new connection.</span>
</div><div id="l1804" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l1805" class="code_block">
</div><div id="l1806" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Buffered, message</span><span class="o">-</span><span class="nb">based communication.}</span>
</div><div id="l1807" class="code_block"><span class="nb">These calls are similar to the {</span><span class="nv">\tt</span><span class="nb"> recv} and {</span><span class="nv">\tt</span><span class="nb"> send} calls in C, except</span>
</div><div id="l1808" class="code_block"><span class="nb">that XSB wraps a higher</span><span class="o">-</span><span class="nb">level message protocol around these low</span><span class="o">-</span><span class="nb">level</span>
</div><div id="l1809" class="code_block"><span class="nb">functions. More precisely, {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">send</span><span class="o">/</span><span class="m">3</span><span class="nb">} prepends a </span><span class="m">4</span><span class="o">-</span><span class="nb">byte field</span>
</div><div id="l1810" class="code_block"><span class="nb">to each message, which indicates the length of the message</span>
</div><div id="l1811" class="code_block"><span class="nb">body. When {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">recv</span><span class="o">/</span><span class="m">3</span><span class="nb">} reads a message, it first reads the </span><span class="m">4</span><span class="o">-</span><span class="nb">byte</span>
</div><div id="l1812" class="code_block"><span class="nb">field to determine the length of the message and then reads the remainder</span>
</div><div id="l1813" class="code_block"><span class="nb">of the message. </span>
</div><div id="l1814" class="code_block">
</div><div id="l1815" class="code_block"><span class="nb">All this is transparent to the XSB user, but you should know these details</span>
</div><div id="l1816" class="code_block"><span class="nb">if you want to use these details to communicate with external processes</span>
</div><div id="l1817" class="code_block"><span class="nb">written in C and such. All this means that these external programs must</span>
</div><div id="l1818" class="code_block"><span class="nb">implement the same protocol. The subtle point here is that different</span>
</div><div id="l1819" class="code_block"><span class="nb">machines represent integers differently, so an integer must first be</span>
</div><div id="l1820" class="code_block"><span class="nb">converted into the machine</span><span class="o">-</span><span class="nb">independent network format using the functions</span>
</div><div id="l1821" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> htonl} and {</span><span class="nv">\tt</span><span class="nb"> ntohl} provided by the socket library. For instance,</span>
</div><div id="l1822" class="code_block"><span class="nb">to send a message to XSB, one must do something like this:</span>
</div><div id="l1823" class="code_block"><span class="c">%%</span>
</div><div id="l1824" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1825" class="code_block"><span class="nb">char </span><span class="o">*</span><span class="nb">message, </span><span class="o">*</span><span class="nb">msg_body;</span>
</div><div id="l1826" class="code_block"><span class="nb">unsigned int msg_body_len, network_encoded_len;</span>
</div><div id="l1827" class="code_block">
</div><div id="l1828" class="code_block"><span class="nb">  msg_body_len </span><span class="o">=</span><span class="nb"> strlen</span><span class="o">(</span><span class="nb">msg_body</span><span class="o">)</span><span class="nb">;</span>
</div><div id="l1829" class="code_block"><span class="nb">  network_encoded_len </span><span class="o">=</span><span class="nb"> </span><span class="o">(</span><span class="nb">unsigned int</span><span class="o">)</span><span class="nb"> htonl</span><span class="o">((</span><span class="nb">unsigned long int</span><span class="o">)</span><span class="nb"> msg_body_len</span><span class="o">)</span><span class="nb">;</span>
</div><div id="l1830" class="code_block"><span class="nb">  memcpy</span><span class="o">((</span><span class="nb">void </span><span class="o">*)</span><span class="nb"> message, </span><span class="o">(</span><span class="nb">void </span><span class="o">*)</span><span class="nb"> &amp;network_encoded_len, </span><span class="m">4</span><span class="o">)</span><span class="nb">;</span>
</div><div id="l1831" class="code_block"><span class="nb">  strcpy</span><span class="o">(</span><span class="nb">message</span><span class="o">+</span><span class="m">4</span><span class="nb">, msg_body</span><span class="o">)</span><span class="nb">;</span>
</div><div id="l1832" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1833" class="code_block"><span class="c">%%</span>
</div><div id="l1834" class="code_block"><span class="nb">To read a message sent by XSB, one can do as follows:</span>
</div><div id="l1835" class="code_block"><span class="c">%%</span>
</div><div id="l1836" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1837" class="code_block"><span class="nb">int actual_len;</span>
</div><div id="l1838" class="code_block"><span class="nb">char lenbuf</span><span class="o">[</span><span class="m">4</span><span class="o">]</span><span class="nb">, msg_buff;</span>
</div><div id="l1839" class="code_block"><span class="nb">unsigned int msglen, net_encoded_len;  </span>
</div><div id="l1840" class="code_block">
</div><div id="l1841" class="code_block"><span class="nb">  actual_len </span><span class="o">=</span><span class="nb"> </span><span class="o">(</span><span class="nb">long</span><span class="o">)</span><span class="nb">recvfrom</span><span class="o">(</span><span class="nb">sock_handle, lenbuf, </span><span class="m">4</span><span class="nb">, </span><span class="m">0</span><span class="nb">, NULL, </span><span class="m">0</span><span class="o">)</span><span class="nb">;</span>
</div><div id="l1842" class="code_block"><span class="nb">  memcpy</span><span class="o">((</span><span class="nb">void </span><span class="o">*)</span><span class="nb"> &amp;net_encoded_len, </span><span class="o">(</span><span class="nb">void </span><span class="o">*)</span><span class="nb"> lenbuf, </span><span class="m">4</span><span class="o">)</span><span class="nb">;</span>
</div><div id="l1843" class="code_block"><span class="nb">  msglen </span><span class="o">=</span><span class="nb"> ntohl</span><span class="o">(</span><span class="nb">net_encoded_len</span><span class="o">)</span><span class="nb">;</span>
</div><div id="l1844" class="code_block">
</div><div id="l1845" class="code_block"><span class="nb">  msg_buff </span><span class="o">=</span><span class="nb"> calloc</span><span class="o">(</span><span class="nb">msglen</span><span class="o">+</span><span class="m">1</span><span class="nb">, sizeof</span><span class="o">(</span><span class="nb">char</span><span class="o">)))</span><span class="nb">; </span><span class="o">//</span><span class="nb"> check if this suceeded</span><span class="o">!!!</span>
</div><div id="l1846" class="code_block"><span class="nb">  recvfrom</span><span class="o">(</span><span class="nb">sock_handle, msg_buff, msglen, </span><span class="m">0</span><span class="nb">, NULL, </span><span class="m">0</span><span class="o">)</span><span class="nb">;</span>
</div><div id="l1847" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1848" class="code_block"><span class="c">%%</span>
</div><div id="l1849" class="code_block"><span class="nb">If making the external processes follow the XSB protocol is not practical</span>
</div><div id="l1850" class="code_block"><span class="o">(</span><span class="nb">because you did not write these programs</span><span class="o">)</span><span class="nb">, then you should use the</span>
</div><div id="l1851" class="code_block"><span class="nb">character</span><span class="o">-</span><span class="nb">at</span><span class="o">-</span><span class="nb">a</span><span class="o">-</span><span class="nb">time interface or, better, the buffered</span>
</div><div id="l1852" class="code_block"><span class="nb">stream</span><span class="o">-</span><span class="nb">based interface both of which are described in this section.</span>
</div><div id="l1853" class="code_block"><span class="nb">At present, however, the buffered stream</span><span class="o">-</span><span class="nb">based interface does not work on</span>
</div><div id="l1854" class="code_block"><span class="nb">Windows.</span>
</div><div id="l1855" class="code_block"><span class="c">%%</span>
</div><div id="l1856" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l1857" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">recv</span><span class="o">(+</span><span class="nb">Sockfd,</span><span class="o">-</span><span class="nb">Message, ?ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">recv</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l1858" class="code_block"><span class="nb">    Receives a message from the connection identified by the socket descriptor</span>
</div><div id="l1859" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Sockfd}. Binds {</span><span class="nv">\tt</span><span class="nb"> Message} to the message. {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">recv</span><span class="o">/</span><span class="m">3</span><span class="nb">}</span>
</div><div id="l1860" class="code_block"><span class="nb">    provides a message</span><span class="o">-</span><span class="nb">oriented interface. It understands message</span>
</div><div id="l1861" class="code_block"><span class="nb">    boundaries set by {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">send</span><span class="o">/</span><span class="m">3</span><span class="nb">}.</span>
</div><div id="l1862" class="code_block">
</div><div id="l1863" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">send</span><span class="o">(+</span><span class="nb">Sockfd,</span><span class="o">+</span><span class="nb">Message, ?ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">send</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l1864" class="code_block"><span class="nb">    Takes a message </span><span class="o">(</span><span class="nb">which must be an atom</span><span class="o">)</span><span class="nb"> and sends it through the</span>
</div><div id="l1865" class="code_block"><span class="nb">    connection specified by {</span><span class="nv">\tt</span><span class="nb"> Sockfd}. {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">send</span><span class="o">/</span><span class="m">3</span><span class="nb">} provides</span>
</div><div id="l1866" class="code_block"><span class="nb">    message</span><span class="o">-</span><span class="nb">oriented communication. It prepends a </span><span class="m">4</span><span class="o">-</span><span class="nb">byte header to the</span>
</div><div id="l1867" class="code_block"><span class="nb">    message, which tells {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">recv</span><span class="o">/</span><span class="m">3</span><span class="nb">} the length of the message body.</span>
</div><div id="l1868" class="code_block">
</div><div id="l1869" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l1870" class="code_block">
</div><div id="l1871" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Stream</span><span class="o">-</span><span class="nb">oriented, character</span><span class="o">-</span><span class="nb">at</span><span class="o">-</span><span class="nb">a</span><span class="o">-</span><span class="nb">time interface.}</span>
</div><div id="l1872" class="code_block"><span class="nb">Internally, this interface uses the same {</span><span class="nv">\tt</span><span class="nb"> sendto} and {</span><span class="nv">\tt</span><span class="nb"> recvfrom}</span>
</div><div id="l1873" class="code_block"><span class="nb">socket calls, but they are executed for each character separately.</span>
</div><div id="l1874" class="code_block"><span class="nb">This interface is appropriate when the message format is not known or when</span>
</div><div id="l1875" class="code_block"><span class="nb">message boundaries are determined using special delimiters.</span>
</div><div id="l1876" class="code_block">
</div><div id="l1877" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">get</span><span class="m">0</span><span class="o">/</span><span class="m">3</span><span class="nb">} creates the end</span><span class="o">-</span><span class="nb">of</span><span class="o">-</span><span class="nb">file condition when it receives the</span>
</div><div id="l1878" class="code_block"><span class="nb">end</span><span class="o">-</span><span class="nb">of</span><span class="o">-</span><span class="nb">file character {</span><span class="nv">\tt</span><span class="nb"> CH</span><span class="nv">\_</span><span class="nb">EOF</span><span class="nv">\_</span><span class="nb">P} </span><span class="o">(</span><span class="nb">a.k.a. </span><span class="m">255</span><span class="o">)</span><span class="nb"> defined in {</span><span class="nv">\tt</span>
</div><div id="l1879" class="code_block"><span class="nb">  char</span><span class="nv">\_</span><span class="nb">defs.h} </span><span class="o">(</span><span class="nb">which must be included in the XSB program</span><span class="o">)</span><span class="nb">. C programs</span>
</div><div id="l1880" class="code_block"><span class="nb">that need to send an end</span><span class="o">-</span><span class="nb">of</span><span class="o">-</span><span class="nb">file character should send {</span><span class="nv">\tt</span><span class="nb"> </span><span class="o">(</span><span class="nb">char</span><span class="o">)-</span><span class="m">1</span><span class="nb">}.</span>
</div><div id="l1881" class="code_block"><span class="c">%%</span>
</div><div id="l1882" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l1883" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">get</span><span class="m">0</span><span class="o">(+</span><span class="nb">Sockfd, </span><span class="o">-</span><span class="nb">Char, ?ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">get</span><span class="m">0</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l1884" class="code_block"><span class="nb">The equivalent of {</span><span class="nv">\tt</span><span class="nb"> get</span><span class="m">0</span><span class="nb">} for sockets.</span>
</div><div id="l1885" class="code_block">
</div><div id="l1886" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">put</span><span class="o">(+</span><span class="nb">Sockfd, </span><span class="o">+</span><span class="nb">Char, ?ErrorCode</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">put</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l1887" class="code_block"><span class="nb">Similar to put</span><span class="o">/</span><span class="m">1</span><span class="nb">, but works on sockets.</span>
</div><div id="l1888" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l1889" class="code_block"><span class="c">%%</span>
</div><div id="l1890" class="code_block">
</div><div id="l1891" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Socket</span><span class="o">-</span><span class="nb">probing.}</span>
</div><div id="l1892" class="code_block"><span class="nb">With the help of the predicate {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">select</span><span class="o">/</span><span class="m">6</span><span class="nb">} one can establish a</span>
</div><div id="l1893" class="code_block"><span class="nb">group of asynchronous or synchronous socket connections. In the synchronous</span>
</div><div id="l1894" class="code_block"><span class="nb">mode, this call is blocked until one of the sockets in the group becomes</span>
</div><div id="l1895" class="code_block"><span class="nb">available for reading or writing, as described below.  In the asynchronous</span>
</div><div id="l1896" class="code_block"><span class="nb">mode, this call is used to probe the sockets periodically, to find out</span>
</div><div id="l1897" class="code_block"><span class="nb">which sockets have data available for reading or which sockets have room in</span>
</div><div id="l1898" class="code_block"><span class="nb">the buffer to write to.</span>
</div><div id="l1899" class="code_block">
</div><div id="l1900" class="code_block"><span class="nb">The directory {</span><span class="nv">\tt</span><span class="nb"> XSB</span><span class="o">/</span><span class="nb">examples</span><span class="o">/</span><span class="nb">socket</span><span class="o">/</span><span class="nb">select</span><span class="o">/</span><span class="nb">} has a number of examples of</span>
</div><div id="l1901" class="code_block"><span class="nb">the use of the socket</span><span class="o">-</span><span class="nb">probing calls.</span>
</div><div id="l1902" class="code_block"><span class="c">%%</span>
</div><div id="l1903" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l1904" class="code_block"><span class="nb">  </span><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">select</span><span class="o">(+</span><span class="nb">SymConName,</span><span class="o">+</span><span class="nb">Timeout,</span><span class="o">-</span><span class="nb">ReadSockL,</span><span class="o">-</span><span class="nb">WriteSockL,</span><span class="o">-</span><span class="nb">ErrSockL,?ErrorCode</span><span class="o">)</span><span class="nb">} </span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">select</span><span class="o">/</span><span class="m">6</span><span class="nb">}}</span>
</div><div id="l1905" class="code_block"><span class="nb">  {</span><span class="nv">\tt</span><span class="nb"> SymConName} must be an atom that</span>
</div><div id="l1906" class="code_block"><span class="nb">  denotes an existing connection group, which must be previously created with</span>
</div><div id="l1907" class="code_block"><span class="nb">  {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">set</span><span class="nv">\_</span><span class="nb">select</span><span class="o">/</span><span class="m">4</span><span class="nb">} </span><span class="o">(</span><span class="nb">described below</span><span class="o">)</span><span class="nb">. {</span><span class="nv">\tt</span><span class="nb"> ReadSockL}, {</span><span class="nv">\tt</span>
</div><div id="l1908" class="code_block"><span class="nb">    WriteSockL}, {</span><span class="nv">\tt</span><span class="nb"> ErrSockL} are lists of socket handles </span><span class="o">(</span><span class="nb">as returned by</span>
</div><div id="l1909" class="code_block"><span class="nb">  {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="o">/</span><span class="m">2</span><span class="nb">}</span><span class="o">)</span><span class="nb"> that specify the available sockets that are available for</span>
</div><div id="l1910" class="code_block"><span class="nb">  reading, writing, or on which exception conditions occurred.  {</span><span class="nv">\tt</span>
</div><div id="l1911" class="code_block"><span class="nb">    Timeout} must be an integer that specifies the timeout in seconds </span><span class="o">(</span><span class="m">0</span>
</div><div id="l1912" class="code_block"><span class="nb">  means probe and exit immediately</span><span class="o">)</span><span class="nb">. If {</span><span class="nv">\tt</span><span class="nb"> Timeout} is a variable, then</span>
</div><div id="l1913" class="code_block"><span class="nb">  wait indefinitely until one of the sockets becomes available.</span>
</div><div id="l1914" class="code_block">
</div><div id="l1915" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">set</span><span class="nv">\_</span><span class="nb">select</span><span class="o">(+</span><span class="nb">SymConName,</span><span class="o">+</span><span class="nb">ReadSockFdLst,</span><span class="o">+</span><span class="nb">WriteSockFdLst,</span><span class="o">+</span><span class="nb">ErrorSockFdLst</span><span class="o">)</span><span class="nb">} </span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">set</span><span class="nv">\_</span><span class="nb">select</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l1916" class="code_block"><span class="nb">Creates a connection group with the symbolic name {</span><span class="nv">\tt</span><span class="nb"> SymConName}</span>
</div><div id="l1917" class="code_block"><span class="o">(</span><span class="nb">an atom</span><span class="o">)</span><span class="nb"> for subsequent use by {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">select</span><span class="o">/</span><span class="m">6</span><span class="nb">}.</span>
</div><div id="l1918" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> ReadSockFdLst}, {</span><span class="nv">\tt</span><span class="nb"> WriteSockFdLst}, and {</span><span class="nv">\tt</span><span class="nb"> ErrorSockFdLst} are</span>
</div><div id="l1919" class="code_block"><span class="nb">lists of sockets for which {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">select</span><span class="o">/</span><span class="m">6</span><span class="nb">} will be used to monitor read,</span>
</div><div id="l1920" class="code_block"><span class="nb">write, or exception conditions.</span>
</div><div id="l1921" class="code_block">
</div><div id="l1922" class="code_block"><span class="nv">\ouritem</span><span class="nb">{socket</span><span class="nv">\_</span><span class="nb">select</span><span class="nv">\_</span><span class="nb">destroy</span><span class="o">(+</span><span class="nb">SymConName</span><span class="o">)</span><span class="nb">} </span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">select</span><span class="nv">\_</span><span class="nb">destroy</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l1923" class="code_block"><span class="nb">Destroys the specified connection group.</span>
</div><div id="l1924" class="code_block">
</div><div id="l1925" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l1926" class="code_block">
</div><div id="l1927" class="code_block">
</div><div id="l1928" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Error codes.}</span>
</div><div id="l1929" class="code_block"><span class="nb">The error code argument unifies with the error code returned by the</span>
</div><div id="l1930" class="code_block"><span class="nb">corresponding socket commands. The error code </span><span class="o">-</span><span class="m">2</span><span class="nb"> signifies</span>
</div><div id="l1931" class="code_block"><span class="nv">\emph</span><span class="nb">{timeout} for timeout</span><span class="o">-</span><span class="nb">enabled primitives </span><span class="o">(</span><span class="nb">see below</span><span class="o">)</span><span class="nb">. The error code</span>
</div><div id="l1932" class="code_block"><span class="nb">of zero signifies normal termination. Positive error codes denote specific</span>
</div><div id="l1933" class="code_block"><span class="nb">failures, as defined in BSD sockets. When such a failure occurs, an error</span>
</div><div id="l1934" class="code_block"><span class="nb">message is printed, but the predicate succeeds anyway. The specific error</span>
</div><div id="l1935" class="code_block"><span class="nb">codes are part of the socket documentation. Unfortunately, the symbolic</span>
</div><div id="l1936" class="code_block"><span class="nb">names and error numbers of these failures are different between Unix</span>
</div><div id="l1937" class="code_block"><span class="nb">compilers and Visual C</span><span class="o">++</span><span class="nb">. Thus, there is no portable, reliable way to refer</span>
</div><div id="l1938" class="code_block"><span class="nb">to these error codes. The only reliably portable error codes that can be </span>
</div><div id="l1939" class="code_block"><span class="nb">used in XSB programs defined through these symbolic constants:</span>
</div><div id="l1940" class="code_block"><span class="c">%%</span>
</div><div id="l1941" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1942" class="code_block"><span class="nb">#include &quot;socket_defs_xsb.h&quot;  </span>
</div><div id="l1943" class="code_block">
</div><div id="l1944" class="code_block"><span class="nb">#define SOCK_OK       </span><span class="m">0</span><span class="nb">      </span><span class="o">/*</span><span class="nb"> indicates sucessful return from socket      </span><span class="o">*/</span>
</div><div id="l1945" class="code_block"><span class="nb">#define SOCK_EOF     </span><span class="o">-</span><span class="m">1</span><span class="nb">      </span><span class="o">/*</span><span class="nb"> end of file in socket_recv, socket_get</span><span class="m">0</span><span class="nb">     </span><span class="o">*/</span>
</div><div id="l1946" class="code_block">
</div><div id="l1947" class="code_block"><span class="nb">#include &quot;timer_defs_xsb.h&quot;</span>
</div><div id="l1948" class="code_block">
</div><div id="l1949" class="code_block"><span class="nb">#define TIMEOUT_ERR </span><span class="o">-</span><span class="m">2</span><span class="nb">                 </span><span class="o">/*</span><span class="nb"> Timeout error code </span><span class="o">*/</span>
</div><div id="l1950" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l1951" class="code_block"><span class="c">%%</span>
</div><div id="l1952" class="code_block">
</div><div id="l1953" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Timeouts.}</span>
</div><div id="l1954" class="code_block"><span class="nb">XSB socket interface allows the programer to specify timeouts for certain</span>
</div><div id="l1955" class="code_block"><span class="nb">operations. If the operations does not finish within the specified period</span>
</div><div id="l1956" class="code_block"><span class="nb">of time, the operation is aborted and the corresponding predicate succeeds</span>
</div><div id="l1957" class="code_block"><span class="nb">with the {</span><span class="nv">\tt</span><span class="nb"> TIMEOUT</span><span class="nv">\_</span><span class="nb">ERR} error code. The following primitives are</span>
</div><div id="l1958" class="code_block"><span class="nb">timeout</span><span class="o">-</span><span class="nb">enabled: {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">connect</span><span class="o">/</span><span class="m">4</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">accept</span><span class="o">/</span><span class="m">3</span><span class="nb">}, {</span><span class="nv">\tt</span>
</div><div id="l1959" class="code_block"><span class="nb">  socket</span><span class="nv">\_</span><span class="nb">recv</span><span class="o">/</span><span class="m">3</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">send</span><span class="o">/</span><span class="m">3</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">get</span><span class="m">0</span><span class="o">/</span><span class="m">3</span><span class="nb">}, and {</span><span class="nv">\tt</span>
</div><div id="l1960" class="code_block"><span class="nb">  socket</span><span class="nv">\_</span><span class="nb">put</span><span class="o">/</span><span class="m">3</span><span class="nb">}.  To set a timeout value for any of the above primitives,</span>
</div><div id="l1961" class="code_block"><span class="nb">the user should execute {</span><span class="nv">\tt</span><span class="nb"> set</span><span class="nv">\_</span><span class="nb">timer</span><span class="o">/</span><span class="m">1</span><span class="nb">} right before the subgoal to be</span>
</div><div id="l1962" class="code_block"><span class="nb">timed. Note that timeouts are disabled after the corresponding timeout</span><span class="o">-</span><span class="nb">enabled</span>
</div><div id="l1963" class="code_block"><span class="nb">call completes or times out. Therefore, one must use {</span><span class="nv">\tt</span><span class="nb"> set</span><span class="nv">\_</span><span class="nb">timer</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l1964" class="code_block"><span class="nb">before each call that needs to be controlled by a timeout mechanism.</span>
</div><div id="l1965" class="code_block">
</div><div id="l1966" class="code_block"><span class="nb">The most common use of timeouts is to either abort or retry the operation</span>
</div><div id="l1967" class="code_block"><span class="nb">that times out. For the latter, XSB provides the {</span><span class="nv">\tt</span><span class="nb"> sleep</span><span class="o">/</span><span class="m">1</span><span class="nb">} primitive,</span>
</div><div id="l1968" class="code_block"><span class="nb">which allows the program to wait for a few seconds before retrying.</span>
</div><div id="l1969" class="code_block">
</div><div id="l1970" class="code_block"><span class="nb">The {</span><span class="nv">\tt</span><span class="nb"> set</span><span class="nv">\_</span><span class="nb">timer</span><span class="o">/</span><span class="m">1</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> sleep</span><span class="o">/</span><span class="m">1</span><span class="nb">} primitives are described below.</span>
</div><div id="l1971" class="code_block"><span class="nb">They are standard predicates and do not need to be explicitly imported.</span>
</div><div id="l1972" class="code_block"><span class="c">%%</span>
</div><div id="l1973" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l1974" class="code_block"><span class="nv">\ouritem</span><span class="nb">{set</span><span class="nv">\_</span><span class="nb">timer</span><span class="o">(+</span><span class="nb">Seconds</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> set</span><span class="nv">\_</span><span class="nb">timer</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l1975" class="code_block"><span class="nb">Set timeout value. If a timer</span><span class="o">-</span><span class="nb">enabled goal executes after this value is</span>
</div><div id="l1976" class="code_block"><span class="nb">set, the clock begins ticking. If the goal does not finish in time, it</span>
</div><div id="l1977" class="code_block"><span class="nb">succeeds with the error code set to {</span><span class="nv">\tt</span><span class="nb"> TIMEOUT</span><span class="nv">\_</span><span class="nb">ERR}. The timer is turned</span>
</div><div id="l1978" class="code_block"><span class="nb">off after the goal executes </span><span class="o">(</span><span class="nb">whether timed out or not and whether it</span>
</div><div id="l1979" class="code_block"><span class="nb">succeeds or fails</span><span class="o">)</span><span class="nb">. This goal always succeeds.</span>
</div><div id="l1980" class="code_block">
</div><div id="l1981" class="code_block"><span class="nb">Note that if the timer is not set, the timer</span><span class="o">-</span><span class="nb">enabled goals execute</span>
</div><div id="l1982" class="code_block"><span class="nb">``normally,&#39;&#39; without timeouts. In particular, they might block </span><span class="o">(</span><span class="nb">say, on</span>
</div><div id="l1983" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">recv}, if data is not available</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l1984" class="code_block">
</div><div id="l1985" class="code_block"><span class="nv">\ouritem</span><span class="nb">{sleep</span><span class="o">(+</span><span class="nb">Seconds</span><span class="o">)</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> sleep</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l1986" class="code_block"><span class="nb">Put XSB to sleep for the specified number of seconds. Execution resumes</span>
</div><div id="l1987" class="code_block"><span class="nb">after the {</span><span class="nv">\tt</span><span class="nb"> Seconds} number of seconds. This goal always succeeds.</span>
</div><div id="l1988" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l1989" class="code_block"><span class="c">%%</span>
</div><div id="l1990" class="code_block"><span class="nb">Here is an example of the use of the timer:</span>
</div><div id="l1991" class="code_block"><span class="c">%%</span>
</div><div id="l1992" class="code_block"><span class="nv">\begin</span><span class="nb">{samepage}</span>
</div><div id="l1993" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l1994" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> compiler_options</span><span class="o">([</span><span class="nb">xpp_on</span><span class="o">])</span><span class="nb">.</span>
</div><div id="l1995" class="code_block"><span class="nb">#include &quot;timer_defs_xsb.h&quot;</span>
</div><div id="l1996" class="code_block">
</div><div id="l1997" class="code_block"><span class="nb">?</span><span class="o">-</span><span class="nb"> set_timer</span><span class="o">(</span><span class="m">3</span><span class="o">)</span><span class="nb">,  </span><span class="c">% wait for 3 secs</span>
</div><div id="l1998" class="code_block"><span class="nb">   socket_recv</span><span class="o">(</span><span class="nb">Sockfd, Msg, ErrorCode</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l1999" class="code_block"><span class="nb">   </span><span class="o">(</span><span class="nb">ErrorCode </span><span class="o">==</span><span class="nb"> TIMEOUT_ERR</span>
</div><div id="l2000" class="code_block"><span class="nb">   </span><span class="o">-</span><span class="nb">&gt; writeln</span><span class="o">(</span><span class="nb">&#39;Socket read timed out, retrying&#39;</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l2001" class="code_block"><span class="nb">      try_again</span><span class="o">(</span><span class="nb">Sockfd</span><span class="o">)</span>
</div><div id="l2002" class="code_block"><span class="nb">   ;  write</span><span class="o">(</span><span class="nb">&#39;Data received: &#39;</span><span class="o">)</span><span class="nb">, writeln</span><span class="o">(</span><span class="nb">Msg</span><span class="o">)</span>
</div><div id="l2003" class="code_block"><span class="nb">   </span><span class="o">)</span><span class="nb">.</span>
</div><div id="l2004" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l2005" class="code_block"><span class="nv">\end</span><span class="nb">{samepage}</span>
</div><div id="l2006" class="code_block"><span class="c">%%</span>
</div><div id="l2007" class="code_block">
</div><div id="l2008" class="code_block"><span class="nv">\noindent</span>
</div><div id="l2009" class="code_block"><span class="nb">Apart from the above timer</span><span class="o">-</span><span class="nb">enabled primitives, a timeout value can be given</span>
</div><div id="l2010" class="code_block"><span class="nb">to {</span><span class="nv">\tt</span><span class="nb"> socket</span><span class="nv">\_</span><span class="nb">select</span><span class="o">/</span><span class="m">6</span><span class="nb">} directly, as an argument.</span>
</div><div id="l2011" class="code_block">
</div><div id="l2012" class="code_block">
</div><div id="l2013" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Buffered, stream</span><span class="o">-</span><span class="nb">oriented communication.}</span>
</div><div id="l2014" class="code_block"><span class="nb">In Unix, socket descriptors can be ``promoted&#39;&#39; to file streams and the</span>
</div><div id="l2015" class="code_block"><span class="nb">regular read</span><span class="o">/</span><span class="nb">write commands can be used with such streams. In XSB, such</span>
</div><div id="l2016" class="code_block"><span class="nb">promotion can be done using the following predicate:</span>
</div><div id="l2017" class="code_block"><span class="c">%%</span>
</div><div id="l2018" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l2019" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">(+</span><span class="nb">Pipe, </span><span class="o">-</span><span class="nb">IOport</span><span class="o">)</span><span class="nb">}{shell}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">/</span><span class="m">2</span><span class="nb">}} </span>
</div><div id="l2020" class="code_block"><span class="nb">    Take a socket descriptor and convert it to an XSB I</span><span class="o">/</span><span class="nb">O port that can be used</span>
</div><div id="l2021" class="code_block"><span class="nb">    for regular file I</span><span class="o">/</span><span class="nb">O. </span>
</div><div id="l2022" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l2023" class="code_block"><span class="c">%%</span>
</div><div id="l2024" class="code_block"><span class="nb">Once {</span><span class="nv">\tt</span><span class="nb"> IOport} is obtained, all I</span><span class="o">/</span><span class="nb">O primitives described in</span>
</div><div id="l2025" class="code_block"><span class="nb">Section~</span><span class="nv">\ref</span><span class="nb">{sec</span><span class="o">-</span><span class="nb">low</span><span class="o">-</span><span class="nb">level</span><span class="o">-</span><span class="nb">io} can be used. This is, perhaps, the easiest</span>
</div><div id="l2026" class="code_block"><span class="nb">and the most convenient way to use sockets in XSB. </span><span class="o">(</span><span class="nb">This feature has not</span>
</div><div id="l2027" class="code_block"><span class="nb">been implemented for Windows.</span><span class="o">)</span>
</div><div id="l2028" class="code_block">
</div><div id="l2029" class="code_block"><span class="nv">\noindent</span>
</div><div id="l2030" class="code_block"><span class="nb">Here is an example of the use of this feature:</span>
</div><div id="l2031" class="code_block"><span class="c">%%</span>
</div><div id="l2032" class="code_block"><span class="nv">\begin</span><span class="nb">{samepage}</span>
</div><div id="l2033" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l2034" class="code_block"><span class="nb">:</span><span class="o">-</span><span class="nb"> compiler_options</span><span class="o">([</span><span class="nb">xpp_on</span><span class="o">])</span><span class="nb">.</span>
</div><div id="l2035" class="code_block"><span class="nb">#include &quot;socket_defs_xsb.h&quot;</span>
</div><div id="l2036" class="code_block">
</div><div id="l2037" class="code_block"><span class="nb">?</span><span class="o">-</span><span class="nb"> </span><span class="o">(</span><span class="nb">socket</span><span class="o">(</span><span class="nb">Sockfd, SOCK_OK</span><span class="o">)</span>
</div><div id="l2038" class="code_block"><span class="nb">   </span><span class="o">-</span><span class="nb">&gt;   socket_connect</span><span class="o">(</span><span class="nb">Sockfd</span><span class="m">1</span><span class="nb">, </span><span class="m">6020</span><span class="nb">, localhost, Ecode</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l2039" class="code_block"><span class="nb">        </span><span class="o">(</span><span class="nb">Ecode </span><span class="o">==</span><span class="nb"> SOCK_OK</span>
</div><div id="l2040" class="code_block"><span class="nb">        </span><span class="o">-</span><span class="nb">&gt; fd</span><span class="m">2</span><span class="nb">ioport</span><span class="o">(</span><span class="nb">Sockfd, SockIOport</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l2041" class="code_block"><span class="nb">           file_write</span><span class="o">(</span><span class="nb">SockIOport, &#39;Hello Server</span><span class="o">!</span><span class="nb">&#39;</span><span class="o">)</span>
</div><div id="l2042" class="code_block"><span class="nb">        ;  writeln</span><span class="o">(</span><span class="nb">&#39;Can&#39;&#39;t connect to server&#39;</span><span class="o">)</span>
</div><div id="l2043" class="code_block"><span class="nb">        </span><span class="o">)</span><span class="nb">,</span>
</div><div id="l2044" class="code_block"><span class="nb">    ;   writeln</span><span class="o">(</span><span class="nb">&#39;Can&#39;&#39;t open socket&#39;</span><span class="o">)</span><span class="nb">, fail</span>
</div><div id="l2045" class="code_block"><span class="nb">    </span><span class="o">)</span><span class="nb">.</span>
</div><div id="l2046" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l2047" class="code_block"><span class="nv">\end</span><span class="nb">{samepage}</span>
</div><div id="l2048" class="code_block"><span class="c">%%</span>
</div><div id="l2049" class="code_block">
</div><div id="l2050" class="code_block">
</div><div id="l2051" class="code_block"><span class="nv">\section</span><span class="nb">{Arrays}</span>
</div><div id="l2052" class="code_block"><span class="c">%===============</span>
</div><div id="l2053" class="code_block">
</div><div id="l2054" class="code_block"><span class="nb">The module {</span><span class="nv">\tt</span><span class="nb"> array</span><span class="m">1</span><span class="nb">} in directory {</span><span class="nv">\tt</span><span class="nb"> lib} provides a very simple </span>
</div><div id="l2055" class="code_block"><span class="nb">backtrackable array implementation.  The predicates through which the </span>
</div><div id="l2056" class="code_block"><span class="nb">array objects are manipulated are:</span>
</div><div id="l2057" class="code_block">
</div><div id="l2058" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l2059" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{array</span><span class="nv">\_</span><span class="nb">new</span><span class="o">(-</span><span class="nb">Array, </span><span class="o">+</span><span class="nb">Size</span><span class="o">)</span><span class="nb">}{array</span><span class="m">1</span><span class="nb">}</span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> array</span><span class="nv">\_</span><span class="nb">new</span><span class="o">/</span><span class="m">2</span><span class="nb">}}</span>
</div><div id="l2060" class="code_block"><span class="c">%\predindex{array\_new/2~(L)}</span>
</div><div id="l2061" class="code_block"><span class="nb">    Creates a one dimensional empty array of size {</span><span class="nv">\tt</span><span class="nb"> Size}.  All the </span>
</div><div id="l2062" class="code_block"><span class="nb">    elements of this array are variables.</span>
</div><div id="l2063" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{array</span><span class="nv">\_</span><span class="nb">elt</span><span class="o">(+</span><span class="nb">Array, </span><span class="o">+</span><span class="nb">Index, ?Element</span><span class="o">)</span><span class="nb">}{array</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l2064" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> array</span><span class="nv">\_</span><span class="nb">elt</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l2065" class="code_block"><span class="c">%\predindex{array\_elt/3~(L)}</span>
</div><div id="l2066" class="code_block"><span class="nb">    True iff {</span><span class="nv">\tt</span><span class="nb"> Element} is the {</span><span class="nv">\tt</span><span class="nb"> Index}</span><span class="o">-</span><span class="nb">th element of array </span>
</div><div id="l2067" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> Array}.</span>
</div><div id="l2068" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{array</span><span class="nv">\_</span><span class="nb">update</span><span class="o">(+</span><span class="nb">Array, </span><span class="o">+</span><span class="nb">Index, </span><span class="o">+</span><span class="nb">Elem, </span><span class="o">-</span><span class="nb">NewArray</span><span class="o">)</span><span class="nb">}{array</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l2069" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> array</span><span class="nv">\_</span><span class="nb">update</span><span class="o">/</span><span class="m">4</span><span class="nb">}}</span>
</div><div id="l2070" class="code_block"><span class="c">%\predindex{array\_update/4~(L)}</span>
</div><div id="l2071" class="code_block"><span class="nb">    Updates the array {</span><span class="nv">\tt</span><span class="nb"> Array} such that the {</span><span class="nv">\tt</span><span class="nb"> Index}</span><span class="o">-</span><span class="nb">th element</span>
</div><div id="l2072" class="code_block"><span class="nb">    of the new array is {</span><span class="nv">\tt</span><span class="nb"> Elem} and returns the new array in </span>
</div><div id="l2073" class="code_block"><span class="nb">    {</span><span class="nv">\tt</span><span class="nb"> NewArray}.  The implementation is quite efficient in that it </span>
</div><div id="l2074" class="code_block"><span class="nb">    avoids the copying of the entire array.</span>
</div><div id="l2075" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l2076" class="code_block">
</div><div id="l2077" class="code_block"><span class="nb">A small example that shows the use of these predicates is the following:</span>
</div><div id="l2078" class="code_block"><span class="nb">{</span><span class="nv">\footnotesize</span>
</div><div id="l2079" class="code_block"><span class="nb"> </span><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l2080" class="code_block"><span class="nb">           | ?</span><span class="o">-</span><span class="nb"> import </span><span class="o">[</span><span class="nb">array_new</span><span class="o">/</span><span class="m">2</span><span class="nb">, array_elt</span><span class="o">/</span><span class="m">3</span><span class="nb">, array_update</span><span class="o">/</span><span class="m">4</span><span class="o">]</span><span class="nb"> from array</span><span class="m">1</span><span class="nb">.</span>
</div><div id="l2081" class="code_block">
</div><div id="l2082" class="code_block"><span class="nb">           yes</span>
</div><div id="l2083" class="code_block"><span class="nb">           | ?</span><span class="o">-</span><span class="nb"> array_new</span><span class="o">(</span><span class="nb">A, </span><span class="m">4</span><span class="o">)</span><span class="nb">, array_update</span><span class="o">(</span><span class="nb">A,</span><span class="m">1</span><span class="nb">,</span><span class="m">1</span><span class="nb">,B</span><span class="o">)</span><span class="nb">, array_update</span><span class="o">(</span><span class="nb">B,</span><span class="m">2</span><span class="nb">,</span><span class="m">2</span><span class="nb">,C</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l2084" class="code_block"><span class="nb">                </span><span class="o">(</span><span class="nb"> array_update</span><span class="o">(</span><span class="nb">C,</span><span class="m">3</span><span class="nb">,</span><span class="m">3</span><span class="nb">,D</span><span class="o">)</span><span class="nb">, array_elt</span><span class="o">(</span><span class="nb">D,</span><span class="m">3</span><span class="nb">,E</span><span class="o">)</span>
</div><div id="l2085" class="code_block"><span class="nb">                ; array_update</span><span class="o">(</span><span class="nb">C,</span><span class="m">3</span><span class="nb">,</span><span class="m">6</span><span class="nb">,D</span><span class="o">)</span><span class="nb">, array_elt</span><span class="o">(</span><span class="nb">D,</span><span class="m">3</span><span class="nb">,E</span><span class="o">)</span>
</div><div id="l2086" class="code_block"><span class="nb">                ; array_update</span><span class="o">(</span><span class="nb">C,</span><span class="m">3</span><span class="nb">,</span><span class="m">7</span><span class="nb">,D</span><span class="o">)</span><span class="nb">, array_elt</span><span class="o">(</span><span class="nb">D,</span><span class="m">3</span><span class="nb">,E</span><span class="o">)</span>
</div><div id="l2087" class="code_block"><span class="nb">                </span><span class="o">)</span><span class="nb">.</span>
</div><div id="l2088" class="code_block">
</div><div id="l2089" class="code_block"><span class="nb">           A </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">3</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2090" class="code_block"><span class="nb">           B </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">3</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2091" class="code_block"><span class="nb">           C </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">3</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2092" class="code_block"><span class="nb">           D </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">3</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2093" class="code_block"><span class="nb">           E </span><span class="o">=</span><span class="nb"> </span><span class="m">3</span><span class="nb">;</span>
</div><div id="l2094" class="code_block">
</div><div id="l2095" class="code_block"><span class="nb">           A </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">6</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2096" class="code_block"><span class="nb">           B </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">6</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2097" class="code_block"><span class="nb">           C </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">6</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2098" class="code_block"><span class="nb">           D </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">6</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2099" class="code_block"><span class="nb">           E </span><span class="o">=</span><span class="nb"> </span><span class="m">6</span><span class="nb">;</span>
</div><div id="l2100" class="code_block">
</div><div id="l2101" class="code_block"><span class="nb">           A </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">7</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2102" class="code_block"><span class="nb">           B </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">7</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2103" class="code_block"><span class="nb">           C </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">7</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2104" class="code_block"><span class="nb">           D </span><span class="o">=</span><span class="nb"> array</span><span class="o">(</span><span class="m">1</span><span class="nb">,</span><span class="m">2</span><span class="nb">,</span><span class="m">7</span><span class="nb">,_</span><span class="m">874600</span><span class="o">)</span>
</div><div id="l2105" class="code_block"><span class="nb">           E </span><span class="o">=</span><span class="nb"> </span><span class="m">7</span><span class="nb">;</span>
</div><div id="l2106" class="code_block">
</div><div id="l2107" class="code_block"><span class="nb">           no</span>
</div><div id="l2108" class="code_block"><span class="nb"> </span><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l2109" class="code_block"><span class="nb">}</span>
</div><div id="l2110" class="code_block">
</div><div id="l2111" class="code_block">
</div><div id="l2112" class="code_block"><span class="c">%\section{The Profiling Library}</span>
</div><div id="l2113" class="code_block"><span class="c">%==============================</span>
</div><div id="l2114" class="code_block">
</div><div id="l2115" class="code_block"><span class="c">%These predicates are available by loading the library through</span>
</div><div id="l2116" class="code_block"><span class="c">%{\tt [prof\_lib]}.</span>
</div><div id="l2117" class="code_block">
</div><div id="l2118" class="code_block"><span class="c">%\begin{description}</span>
</div><div id="l2119" class="code_block"><span class="c">%\ournewitem{measure(+Call)}{prof\_lib}\index{{\tt measure/1}}</span>
</div><div id="l2120" class="code_block"><span class="c">%\predindex{measure/1~(L)}\label{p:measure}</span>
</div><div id="l2121" class="code_block"><span class="c">%     The same as {\tt once/1} (see the section {\it Meta-Predicates}</span>
</div><div id="l2122" class="code_block"><span class="c">%in Volume 1)</span>
</div><div id="l2123" class="code_block"><span class="c">%     but it also prints out statistical information about the call,</span>
</div><div id="l2124" class="code_block"><span class="c">%     that looks like the information printed out by predicate</span>
</div><div id="l2125" class="code_block"><span class="c">%     {\tt statistics/0} (see the section {\it Execution State} in Volume 1).</span>
</div><div id="l2126" class="code_block"><span class="c">%\end{description}</span>
</div><div id="l2127" class="code_block">
</div><div id="l2128" class="code_block"><span class="c">%----------------------------------------------------------------------</span>
</div><div id="l2129" class="code_block"><span class="c">%\input{tr_assert}</span>
</div><div id="l2130" class="code_block"><span class="nv">\section</span><span class="nb">{Asserts</span><span class="o">/</span><span class="nb">Retracts using Tries }</span>
</div><div id="l2131" class="code_block">
</div><div id="l2132" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">assert</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l2133" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">retract</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l2134" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">retractall</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l2135" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">retract</span><span class="nv">\_</span><span class="nb">nr</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l2136" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> abolish</span><span class="nv">\_</span><span class="nb">trie</span><span class="nv">\_</span><span class="nb">asserted</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l2137" class="code_block"><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">dynamic</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l2138" class="code_block">
</div><div id="l2139" class="code_block"><span class="nb">In </span><span class="nv">\version</span><span class="nb">, trie asserted code has been merged with standard asserted</span>
</div><div id="l2140" class="code_block"><span class="nb">code.  If the user wishes to use tries for dynamic code, the</span>
</div><div id="l2141" class="code_block"><span class="nb">recommended programming practice is as outlined in the section {</span><span class="nv">\it</span>
</div><div id="l2142" class="code_block"><span class="nb">Modification of the Database} in Volume </span><span class="m">1</span><span class="nb">.</span>
</div><div id="l2143" class="code_block"><span class="nb">For compatibility with previous versions, the</span>
</div><div id="l2144" class="code_block"><span class="nb">predicates {</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">assert</span><span class="o">/</span><span class="m">1</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">retract</span><span class="o">/</span><span class="m">1</span><span class="nb">}, {</span><span class="nv">\tt</span>
</div><div id="l2145" class="code_block"><span class="nb">trie</span><span class="nv">\_</span><span class="nb">retractall</span><span class="o">/</span><span class="m">1</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">retract</span><span class="nv">\_</span><span class="nb">nr</span><span class="o">/</span><span class="m">1</span><span class="nb">}, {</span><span class="nv">\tt</span>
</div><div id="l2146" class="code_block"><span class="nb">abolish</span><span class="nv">\_</span><span class="nb">trie</span><span class="nv">\_</span><span class="nb">asserted</span><span class="o">/</span><span class="m">1</span><span class="nb">} and {</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">dynamic</span><span class="o">/</span><span class="m">1</span><span class="nb">} can be imported</span>
</div><div id="l2147" class="code_block"><span class="nb">from the module {</span><span class="nv">\sf</span><span class="nb"> tables}.  However, if the current index</span>
</div><div id="l2148" class="code_block"><span class="nb">specification of these predicates is {</span><span class="nv">\tt</span><span class="nb"> trie} </span><span class="o">(</span><span class="nb">again, see the</span>
</div><div id="l2149" class="code_block"><span class="nb">section {</span><span class="nv">\it</span><span class="nb"> Modification of the Database} in Volume </span><span class="m">1</span><span class="nb">, the predicates</span>
</div><div id="l2150" class="code_block"><span class="nb">are defined as {</span><span class="nv">\tt</span><span class="nb"> assert</span><span class="o">/</span><span class="m">1</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> </span>
</div><div id="l2151" class="code_block"><span class="nb">retract</span><span class="o">/</span><span class="m">1</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> retractall</span><span class="o">/</span><span class="m">1</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> retract</span><span class="nv">\_</span><span class="nb">nr</span><span class="o">/</span><span class="m">1</span><span class="nb">}, {</span><span class="nv">\tt</span><span class="nb"> abolish</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l2152" class="code_block"><span class="nb">and {</span><span class="nv">\tt</span><span class="nb"> dynamic</span><span class="o">/</span><span class="m">1</span><span class="nb">} respectively.  If the index specification is other</span>
</div><div id="l2153" class="code_block"><span class="nb">than {</span><span class="nv">\tt</span><span class="nb"> tries}, the predicate will issue a warning message and have</span>
</div><div id="l2154" class="code_block"><span class="nb">no effect on the database.</span>
</div><div id="l2155" class="code_block">
</div><div id="l2156" class="code_block"><span class="nv">\section</span><span class="nb">{Low</span><span class="o">-</span><span class="nb">level Trie Manipulation Utilities}</span>
</div><div id="l2157" class="code_block">
</div><div id="l2158" class="code_block"><span class="nb">The following utilities are used to implement assert and retract, but they</span>
</div><div id="l2159" class="code_block"><span class="nb">can also be used to implement special purpose operations, like</span>
</div><div id="l2160" class="code_block"><span class="nb">backtrackable assert and retract. All the utilities in this section are</span>
</div><div id="l2161" class="code_block"><span class="nb">very low</span><span class="o">-</span><span class="nb">level and require good understanding of the trie mechanism in XSB.</span>
</div><div id="l2162" class="code_block">
</div><div id="l2163" class="code_block"><span class="nb">The module {</span><span class="nv">\tt</span><span class="nb"> storage} described in Volume </span><span class="m">1</span><span class="nb"> provides a higher</span><span class="o">-</span><span class="nb">level and</span>
</div><div id="l2164" class="code_block"><span class="nb">a more convenient interface to the XSB trie</span><span class="o">-</span><span class="nb">based storage mechanism.</span>
</div><div id="l2165" class="code_block">
</div><div id="l2166" class="code_block"><span class="c">%%</span>
</div><div id="l2167" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l2168" class="code_block"><span class="nb">  </span><span class="c">%%</span>
</div><div id="l2169" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{newtrie</span><span class="o">(-</span><span class="nb">Root</span><span class="o">)</span><span class="nb">}{intern} </span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> newtrie</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l2170" class="code_block"><span class="nb">	Root is instantiated to a handle for a new trie.</span>
</div><div id="l2171" class="code_block">
</div><div id="l2172" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">intern</span><span class="o">(+</span><span class="nb">Term,</span><span class="o">+</span><span class="nb">Root,</span><span class="o">-</span><span class="nb">Leaf,</span><span class="o">-</span><span class="nb">Flag,</span><span class="o">-</span><span class="nb">Skel</span><span class="o">)</span><span class="nb">}{intern}</span><span class="nv">\index</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">intern</span><span class="o">/</span><span class="m">5</span><span class="nb">}</span>
</div><div id="l2173" class="code_block"><span class="c">%%</span>
</div><div id="l2174" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Term} is the Prolog term to be interned. {</span><span class="nv">\tt</span><span class="nb"> Root} is the handle for</span>
</div><div id="l2175" class="code_block"><span class="nb">a trie. {</span><span class="nv">\tt</span><span class="nb"> Leaf} is the handle for the interned {</span><span class="nv">\tt</span><span class="nb"> Term} in the trie.</span>
</div><div id="l2176" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Flag} is </span><span class="m">1</span><span class="nb"> if the term is ``old&#39;&#39; </span><span class="o">(</span><span class="nb">already exists in the trie</span><span class="o">)</span><span class="nb">; it is</span>
</div><div id="l2177" class="code_block"><span class="m">0</span><span class="nb">, if the term is newly inserted.  {</span><span class="nv">\tt</span><span class="nb"> Skel} represents the collection of</span>
</div><div id="l2178" class="code_block"><span class="nb">all the variables in {</span><span class="nv">\tt</span><span class="nb"> Term}. It has the form ret</span><span class="o">(</span><span class="nb">V</span><span class="m">1</span><span class="nb">,V</span><span class="m">2</span><span class="nb">,...,VN</span><span class="o">)</span><span class="nb">, exactly</span>
</div><div id="l2179" class="code_block"><span class="nb">as in {</span><span class="nv">\tt</span><span class="nb"> get</span><span class="nv">\_</span><span class="nb">calls}.</span>
</div><div id="l2180" class="code_block">
</div><div id="l2181" class="code_block">
</div><div id="l2182" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">intern</span><span class="o">(+</span><span class="nb">Term,</span><span class="o">-</span><span class="nb">Leaf,</span><span class="o">-</span><span class="nb">Skel</span><span class="o">)</span><span class="nb">}{intern}</span><span class="nv">\index</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">intern</span><span class="o">/</span><span class="m">3</span><span class="nb">}</span>
</div><div id="l2183" class="code_block"><span class="c">%%</span>
</div><div id="l2184" class="code_block"><span class="nb">Interns {</span><span class="nv">\tt</span><span class="nb"> Term} into the default trie. Does not return the new</span><span class="o">/</span><span class="nb">old flag.</span>
</div><div id="l2185" class="code_block">
</div><div id="l2186" class="code_block">
</div><div id="l2187" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">interned</span><span class="o">(</span><span class="nb">?Term,</span><span class="o">+</span><span class="nb">Root,?Leaf,</span><span class="o">-</span><span class="nb">Skel</span><span class="o">)</span><span class="nb">}{intern}</span><span class="nv">\index</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">interned</span><span class="o">/</span><span class="m">4</span><span class="nb">}</span>
</div><div id="l2188" class="code_block"><span class="c">%%</span>
</div><div id="l2189" class="code_block"><span class="nb">This builtin will backtrack through the terms interned into the trie</span>
</div><div id="l2190" class="code_block"><span class="nb">represented by the handle {</span><span class="nv">\tt</span><span class="nb"> Root} if {</span><span class="nv">\tt</span><span class="nb"> Leaf} is a free variable.</span>
</div><div id="l2191" class="code_block"><span class="nb">Otherwise, if {</span><span class="nv">\tt</span><span class="nb"> Leaf} is bound, it will backtrack over the terms in the</span>
</div><div id="l2192" class="code_block"><span class="nb">trie that unify with the term pointed to by Leaf {</span><span class="nv">\tt</span><span class="nb"> to}.  {</span><span class="nv">\tt</span><span class="nb"> Term} is</span>
</div><div id="l2193" class="code_block"><span class="nb">the term to be retrieved; it can be either </span><span class="o">(</span><span class="nb">partially</span><span class="o">)</span><span class="nb"> bound or free.  {</span><span class="nv">\tt</span>
</div><div id="l2194" class="code_block"><span class="nb">  Skel} is the collection of all the variables in {</span><span class="nv">\tt</span><span class="nb"> Term}; it has the</span>
</div><div id="l2195" class="code_block"><span class="nb">form {</span><span class="nv">\tt</span><span class="nb"> ret</span><span class="o">(</span><span class="nb">V</span><span class="m">1</span><span class="nb">,...,Vn</span><span class="o">)</span><span class="nb">}.</span>
</div><div id="l2196" class="code_block">
</div><div id="l2197" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">interned</span><span class="o">(</span><span class="nb">?Term,?Leaf,</span><span class="o">-</span><span class="nb">Skel</span><span class="o">)</span><span class="nb">}{intern} </span><span class="nv">\index</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">interned</span><span class="o">/</span><span class="m">3</span><span class="nb">}</span>
</div><div id="l2198" class="code_block"><span class="c">%%</span>
</div><div id="l2199" class="code_block"><span class="nb">Similar to {</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">interned</span><span class="o">/</span><span class="m">4</span><span class="nb">}  but uses the default trie.</span>
</div><div id="l2200" class="code_block">
</div><div id="l2201" class="code_block">
</div><div id="l2202" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">unintern</span><span class="o">(+</span><span class="nb">Root,</span><span class="o">+</span><span class="nb">Leaf</span><span class="o">)</span><span class="nb">}{intern} </span><span class="nv">\index</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">unintern</span><span class="o">/</span><span class="m">2</span><span class="nb">}</span>
</div><div id="l2203" class="code_block"><span class="c">%%</span>
</div><div id="l2204" class="code_block"><span class="nb">Uninterns </span><span class="o">(</span><span class="nb">deletes</span><span class="o">)</span><span class="nb"> a term from the trie indicated by root.  This predicate</span>
</div><div id="l2205" class="code_block"><span class="nb">has to be called with care. Uninterning can be done only when the trie from</span>
</div><div id="l2206" class="code_block"><span class="nb">which the term is being uninterned is not being actively accessed.</span>
</div><div id="l2207" class="code_block">
</div><div id="l2208" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">unintern</span><span class="nv">\_</span><span class="nb">nr</span><span class="o">(+</span><span class="nb">Root,</span><span class="o">+</span><span class="nb">Leaf</span><span class="o">)</span><span class="nb">}{intern}</span><span class="nv">\index</span><span class="nb">{trie</span><span class="nv">\_</span><span class="nb">unintern</span><span class="nv">\_</span><span class="nb">nr</span><span class="o">/</span><span class="m">2</span><span class="nb">}</span>
</div><div id="l2209" class="code_block"><span class="c">%%</span>
</div><div id="l2210" class="code_block"><span class="nb">This is a safe version of {</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">unintern</span><span class="o">/</span><span class="m">2</span><span class="nb">}. The term pointed to by</span>
</div><div id="l2211" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> Leaf} is marked as deleted, but is not deleted from the trie. This</span>
</div><div id="l2212" class="code_block"><span class="nb">permits an efficient implementation of backtrackable updates.</span>
</div><div id="l2213" class="code_block">
</div><div id="l2214" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{unmark</span><span class="nv">\_</span><span class="nb">uninterned</span><span class="nv">\_</span><span class="nb">nr</span><span class="o">(+</span><span class="nb">Root,</span><span class="o">+</span><span class="nb">Leaf</span><span class="o">)</span><span class="nb">}{intern}</span><span class="nv">\index</span><span class="nb">{unmark</span><span class="nv">\_</span><span class="nb">uninterned</span><span class="nv">\_</span><span class="nb">nr</span><span class="o">/</span><span class="m">2</span><span class="nb">}</span>
</div><div id="l2215" class="code_block"><span class="nb">The term pointed to by {</span><span class="nv">\tt</span><span class="nb"> Leaf} should have been previously marked for</span>
</div><div id="l2216" class="code_block"><span class="nb">deletion using</span>
</div><div id="l2217" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">unintern</span><span class="nv">\_</span><span class="nb">nr</span><span class="o">/</span><span class="m">2</span><span class="nb">}. This term is then ``unmarked&#39;&#39; </span><span class="o">(</span><span class="nb">or undeleted</span><span class="o">)</span>
</div><div id="l2218" class="code_block"><span class="nb">and becomes again a notmal interned term.</span>
</div><div id="l2219" class="code_block">
</div><div id="l2220" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{reclaim</span><span class="nv">\_</span><span class="nb">uninterned</span><span class="nv">\_</span><span class="nb">nr</span><span class="o">(+</span><span class="nb">Root</span><span class="o">)</span><span class="nb">}{intern}</span>
</div><div id="l2221" class="code_block"><span class="nv">\index</span><span class="nb">{reclaim</span><span class="nv">\_</span><span class="nb">uninterned</span><span class="nv">\_</span><span class="nb">rn</span><span class="o">(+</span><span class="nb">Root</span><span class="o">)</span><span class="nb">}</span>
</div><div id="l2222" class="code_block"><span class="c">%%</span>
</div><div id="l2223" class="code_block"><span class="nb">Not yet implemented.</span><span class="nv">\\</span>
</div><div id="l2224" class="code_block"><span class="nb">Runs through the chain of leaves of the trie {</span><span class="nv">\tt</span><span class="nb"> Root} and</span>
</div><div id="l2225" class="code_block"><span class="nb">deletes the terms that have been marked for deletion by</span>
</div><div id="l2226" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> trie</span><span class="nv">\_</span><span class="nb">unintern</span><span class="nv">\_</span><span class="nb">nr</span><span class="o">/</span><span class="m">2</span><span class="nb">}. This is a garbage collection step that should</span>
</div><div id="l2227" class="code_block"><span class="nb">be done just before returning to the top level.</span>
</div><div id="l2228" class="code_block">
</div><div id="l2229" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{delete</span><span class="nv">\_</span><span class="nb">trie</span><span class="o">(+</span><span class="nb">Root</span><span class="o">)</span><span class="nb">}{intern} </span><span class="nv">\index</span><span class="nb">{delete</span><span class="nv">\_</span><span class="nb">trie</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l2230" class="code_block"><span class="c">%%</span>
</div><div id="l2231" class="code_block"><span class="nb">Deletes all the terms in the trie pointed to by Root.</span>
</div><div id="l2232" class="code_block">
</div><div id="l2233" class="code_block">
</div><div id="l2234" class="code_block"><span class="c">%%</span>
</div><div id="l2235" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l2236" class="code_block">
</div><div id="l2237" class="code_block">
</div><div id="l2238" class="code_block">
</div><div id="l2239" class="code_block"><span class="nv">\section</span><span class="nb">{Extended Logic Programs}  </span><span class="nv">\label</span><span class="nb">{library_utilities:wfsx}</span>
</div><div id="l2240" class="code_block"><span class="nv">\index</span><span class="nb">{WFSX}</span>
</div><div id="l2241" class="code_block"><span class="nv">\index</span><span class="nb">{negation</span><span class="o">!</span><span class="nb">explicit negation}</span>
</div><div id="l2242" class="code_block"><span class="nb">As explained in the section {</span><span class="nv">\it</span><span class="nb"> Using Tabling in XSB}, XSB can</span>
</div><div id="l2243" class="code_block"><span class="nb">compute normal logic programs according to the well</span><span class="o">-</span><span class="nb">founded semantics.</span>
</div><div id="l2244" class="code_block"><span class="nb">In fact, XSB </span>
</div><div id="l2245" class="code_block"><span class="nb">can also compute {</span><span class="nv">\em</span><span class="nb"> Extended Logic Programs}, which contain an</span>
</div><div id="l2246" class="code_block"><span class="nb">operator for explicit negation </span><span class="o">(</span><span class="nb">written using the symbol {</span><span class="nv">\tt</span><span class="nb"> </span><span class="o">-</span><span class="nb">} in</span>
</div><div id="l2247" class="code_block"><span class="nb">addition to the negation</span><span class="o">-</span><span class="nb">by</span><span class="o">-</span><span class="nb">failure of the well</span><span class="o">-</span><span class="nb">founded semantics</span>
</div><div id="l2248" class="code_block"><span class="o">(</span><span class="nv">\verb</span><span class="nb">|</span><span class="nv">\+</span><span class="nb">| or {</span><span class="nv">\tt</span><span class="nb"> not}</span><span class="o">)</span><span class="nb">.  Extended logic programs can be extremely</span>
</div><div id="l2249" class="code_block"><span class="nb">useful when reasoning about actions, for model</span><span class="o">-</span><span class="nb">based diagnosis, and</span>
</div><div id="l2250" class="code_block"><span class="nb">for many other uses </span><span class="nv">\cite</span><span class="nb">{AlPe</span><span class="m">95</span><span class="nb">}.  The library, {</span><span class="nv">\sf</span><span class="nb"> slx} provides a means</span>
</div><div id="l2251" class="code_block"><span class="nb">to compile programs so that they can be executed by XSB according to</span>
</div><div id="l2252" class="code_block"><span class="nb">the {</span><span class="nv">\em</span><span class="nb"> well</span><span class="o">-</span><span class="nb">founded semantics with explicit negation} </span><span class="nv">\cite</span><span class="nb">{ADP</span><span class="m">95</span><span class="nb">}.</span>
</div><div id="l2253" class="code_block"><span class="nb">Briefly, WFSX is an extension of the well</span><span class="o">-</span><span class="nb">founded semantics to include</span>
</div><div id="l2254" class="code_block"><span class="nb">explicit negation and which is based on the {</span><span class="nv">\em</span><span class="nb"> coherence principle}</span>
</div><div id="l2255" class="code_block"><span class="nb">in which an atom is taken to be default false if it is proven to be</span>
</div><div id="l2256" class="code_block"><span class="nb">explicitly false, intuitively:</span>
</div><div id="l2257" class="code_block"><span class="nv">\[</span>
</div><div id="l2258" class="code_block"><span class="o">-</span><span class="nb">p </span><span class="nv">\Rightarrow</span><span class="nb"> not</span><span class="nv">\</span><span class="nb"> p.</span>
</div><div id="l2259" class="code_block"><span class="nv">\]</span>
</div><div id="l2260" class="code_block">
</div><div id="l2261" class="code_block"><span class="nb">This section is not intended to be a primer on extended logic</span>
</div><div id="l2262" class="code_block"><span class="nb">programming or on WFSX semantics, but we do provide a few sample</span>
</div><div id="l2263" class="code_block"><span class="nb">programs to indicate the action of WFSX.  Consider the program</span>
</div><div id="l2264" class="code_block"><span class="nb">{</span><span class="nv">\small</span><span class="nb"> </span>
</div><div id="l2265" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l2266" class="code_block"><span class="nb">s:</span><span class="o">-</span><span class="nb"> not t.</span>
</div><div id="l2267" class="code_block">
</div><div id="l2268" class="code_block"><span class="nb">t:</span><span class="o">-</span><span class="nb"> r.</span>
</div><div id="l2269" class="code_block"><span class="nb">t.</span>
</div><div id="l2270" class="code_block">
</div><div id="l2271" class="code_block"><span class="nb">r:</span><span class="o">-</span><span class="nb"> not r.</span>
</div><div id="l2272" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l2273" class="code_block"><span class="nb">}</span>
</div><div id="l2274" class="code_block"><span class="nb">If the clause {</span><span class="nv">\tt</span><span class="nb"> </span><span class="o">-</span><span class="nb">t} were not present, the atoms {</span><span class="nv">\tt</span><span class="nb"> r, t, s} would</span>
</div><div id="l2275" class="code_block"><span class="nb">all be undefined in WFSX just as they would be in the well</span><span class="o">-</span><span class="nb">founded</span>
</div><div id="l2276" class="code_block"><span class="nb">semantics.  However, when the clause {</span><span class="nv">\tt</span><span class="nb"> t} is included, {</span><span class="nv">\tt</span><span class="nb"> t}</span>
</div><div id="l2277" class="code_block"><span class="nb">becomes true in the well</span><span class="o">-</span><span class="nb">founded model, while {</span><span class="nv">\tt</span><span class="nb"> s} becomes false.</span>
</div><div id="l2278" class="code_block"><span class="nb">Next, consider the program</span>
</div><div id="l2279" class="code_block"><span class="nb">{</span><span class="nv">\small</span><span class="nb"> </span>
</div><div id="l2280" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l2281" class="code_block"><span class="nb">s:</span><span class="o">-</span><span class="nb"> not t.</span>
</div><div id="l2282" class="code_block">
</div><div id="l2283" class="code_block"><span class="nb">t:</span><span class="o">-</span><span class="nb"> r.</span>
</div><div id="l2284" class="code_block"><span class="o">-</span><span class="nb">t.</span>
</div><div id="l2285" class="code_block">
</div><div id="l2286" class="code_block"><span class="nb">r:</span><span class="o">-</span><span class="nb"> not r.</span>
</div><div id="l2287" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l2288" class="code_block"><span class="nb">}</span>
</div><div id="l2289" class="code_block"><span class="nb">In this program, the explicitly false truth value for {</span><span class="nv">\tt</span><span class="nb"> t} obtained</span>
</div><div id="l2290" class="code_block"><span class="nb">by the rule {</span><span class="nv">\tt</span><span class="nb"> </span><span class="o">-</span><span class="nb">t} overrides the undefined truth value for {</span><span class="nv">\tt</span><span class="nb"> t}</span>
</div><div id="l2291" class="code_block"><span class="nb">obtained by the rule {</span><span class="nv">\tt</span><span class="nb"> t:</span><span class="o">-</span><span class="nb"> r}.  The WFSX model for this program</span>
</div><div id="l2292" class="code_block"><span class="nb">will assign the truth value of {</span><span class="nv">\tt</span><span class="nb"> t} as false, and that of {</span><span class="nv">\tt</span><span class="nb"> s}</span>
</div><div id="l2293" class="code_block"><span class="nb">as true.  If the above program were contained in the file {</span><span class="nv">\tt</span>
</div><div id="l2294" class="code_block"><span class="nb">test.P}, an XSB session using {</span><span class="nv">\tt</span><span class="nb"> test.P} might look like the</span>
</div><div id="l2295" class="code_block"><span class="nb">following:</span>
</div><div id="l2296" class="code_block"><span class="nb">{</span><span class="nv">\small</span>
</div><div id="l2297" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l2298" class="code_block"><span class="nb">              &gt; xsb</span>
</div><div id="l2299" class="code_block"><span class="nb">              </span>
</div><div id="l2300" class="code_block"><span class="nb">              | ?</span><span class="o">-</span><span class="nb"> </span><span class="o">[</span><span class="nb">slx</span><span class="o">]</span><span class="nb">.</span>
</div><div id="l2301" class="code_block"><span class="nb">              </span><span class="o">[</span><span class="nb">slx loaded</span><span class="o">]</span>
</div><div id="l2302" class="code_block"><span class="nb">            </span>
</div><div id="l2303" class="code_block"><span class="nb">              yes</span>
</div><div id="l2304" class="code_block"><span class="nb">              | ?</span><span class="o">-</span><span class="nb"> slx_compile</span><span class="o">(</span><span class="nb">&#39;test.P&#39;</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l2305" class="code_block"><span class="nb">              </span><span class="o">[</span><span class="nb">Compiling .</span><span class="o">/</span><span class="nb">tmptest</span><span class="o">]</span>
</div><div id="l2306" class="code_block"><span class="nb">              </span><span class="o">[</span><span class="nb">tmptest compiled, cpu time used: </span><span class="m">0</span><span class="nb">.</span><span class="m">1280</span><span class="nb"> seconds</span><span class="o">]</span>
</div><div id="l2307" class="code_block"><span class="nb">              </span><span class="o">[</span><span class="nb">tmptest loaded</span><span class="o">]</span>
</div><div id="l2308" class="code_block"><span class="nb">            </span>
</div><div id="l2309" class="code_block"><span class="nb">              | ?</span><span class="o">-</span><span class="nb"> s.</span>
</div><div id="l2310" class="code_block"><span class="nb">              </span>
</div><div id="l2311" class="code_block"><span class="nb">              yes</span>
</div><div id="l2312" class="code_block"><span class="nb">              | ?</span><span class="o">-</span><span class="nb"> t.</span>
</div><div id="l2313" class="code_block">
</div><div id="l2314" class="code_block"><span class="nb">              no</span>
</div><div id="l2315" class="code_block"><span class="nb">              | ?</span><span class="o">-</span><span class="nb"> naf t.</span>
</div><div id="l2316" class="code_block"><span class="nb">              </span>
</div><div id="l2317" class="code_block"><span class="nb">              yes</span>
</div><div id="l2318" class="code_block"><span class="nb">              | ?</span><span class="o">-</span><span class="nb"> r.</span>
</div><div id="l2319" class="code_block">
</div><div id="l2320" class="code_block"><span class="nb">              no</span>
</div><div id="l2321" class="code_block"><span class="nb">              | ?</span><span class="o">-</span><span class="nb"> naf r.</span>
</div><div id="l2322" class="code_block"><span class="nb">              </span>
</div><div id="l2323" class="code_block"><span class="nb">              no</span>
</div><div id="l2324" class="code_block"><span class="nb">              | ?</span><span class="o">-</span><span class="nb"> und r.</span>
</div><div id="l2325" class="code_block"><span class="nb">              </span>
</div><div id="l2326" class="code_block"><span class="nb">              yes</span>
</div><div id="l2327" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l2328" class="code_block"><span class="nb">}</span>
</div><div id="l2329" class="code_block"><span class="nb">In the above program, the query {</span><span class="nv">\tt</span><span class="nb"> ?</span><span class="o">-</span><span class="nb"> t.} did not succeed,  because</span>
</div><div id="l2330" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> t} is false in WFSX: accordingly the query {</span><span class="nv">\tt</span><span class="nb"> naf t} did</span>
</div><div id="l2331" class="code_block"><span class="nb">succeed, because it is true that t is false via negation</span><span class="o">-</span><span class="nb">as</span><span class="o">-</span><span class="nb">failure,</span>
</div><div id="l2332" class="code_block"><span class="nb">in addition to {</span><span class="nv">\tt</span><span class="nb"> t} being false via explicit negation.  Note that</span>
</div><div id="l2333" class="code_block"><span class="nb">after being processed by the SLX preprocessor, {</span><span class="nv">\tt</span><span class="nb"> r} is undefined</span>
</div><div id="l2334" class="code_block"><span class="nb">but does not succeed, although {</span><span class="nv">\tt</span><span class="nb"> und r} will succeed.</span>
</div><div id="l2335" class="code_block">
</div><div id="l2336" class="code_block"><span class="nb">We note in passing that programs under WFSX can be paraconsistent.</span>
</div><div id="l2337" class="code_block"><span class="nb">For instance in the program.</span>
</div><div id="l2338" class="code_block"><span class="nb">{</span><span class="nv">\small</span>
</div><div id="l2339" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l2340" class="code_block"><span class="nb">              p:</span><span class="o">-</span><span class="nb"> q.</span>
</div><div id="l2341" class="code_block">
</div><div id="l2342" class="code_block"><span class="nb">              q:</span><span class="o">-</span><span class="nb"> not q.</span>
</div><div id="l2343" class="code_block"><span class="nb">              </span><span class="o">-</span><span class="nb">q.</span>
</div><div id="l2344" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l2345" class="code_block"><span class="nb">}</span>
</div><div id="l2346" class="code_block"><span class="nb">both {</span><span class="nv">\tt</span><span class="nb"> p} and {</span><span class="nv">\tt</span><span class="nb"> q} will be true {</span><span class="nv">\em</span><span class="nb"> and} false in the WFSX</span>
</div><div id="l2347" class="code_block"><span class="nb">model.  Accordingly, under SLX preprocessing, both {</span><span class="nv">\tt</span><span class="nb"> p} and {</span><span class="nv">\tt</span>
</div><div id="l2348" class="code_block"><span class="nb">naf p} will succeed.</span>
</div><div id="l2349" class="code_block">
</div><div id="l2350" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l2351" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{slx</span><span class="nv">\_</span><span class="nb">compile</span><span class="o">(+</span><span class="nb">File</span><span class="o">)</span><span class="nb">}{slx}</span>
</div><div id="l2352" class="code_block"><span class="nb">Preprocesses and loads the extended logic program named {</span><span class="nv">\tt</span><span class="nb"> File}.</span>
</div><div id="l2353" class="code_block"><span class="nb">Default negation in {</span><span class="nv">\tt</span><span class="nb"> File} must be represented using the operator</span>
</div><div id="l2354" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> not} rather than using {</span><span class="nv">\tt</span><span class="nb"> tnot} or </span><span class="nv">\verb</span><span class="nb">|</span><span class="nv">\+</span><span class="nb">|.  If {</span><span class="nv">\tt</span><span class="nb"> L} is an</span>
</div><div id="l2355" class="code_block"><span class="nb">objective literal </span><span class="o">(</span><span class="nb">e.g. of the form </span><span class="s">$</span>A<span class="s">$</span><span class="nb"> or </span><span class="s">$</span>-A<span class="s">$</span><span class="nb"> where </span><span class="s">$</span>A<span class="s">$</span><span class="nb"> is an atom</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l2356" class="code_block"><span class="nb">a query {</span><span class="nv">\tt</span><span class="nb"> ?</span><span class="o">-</span><span class="nb"> L} will succeed if {</span><span class="nv">\tt</span><span class="nb"> L} is true in the WFSX model,</span>
</div><div id="l2357" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> naf L} will succeed if {</span><span class="nv">\tt</span><span class="nb"> L} is false in the WFSX model, and</span>
</div><div id="l2358" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> und L} will succeed if {</span><span class="nv">\tt</span><span class="nb"> L} is undefined in the WFSX model.</span>
</div><div id="l2359" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l2360" class="code_block">
</div><div id="l2361" class="code_block">
</div><div id="l2362" class="code_block"><span class="nv">\section</span><span class="nb">{Generalized Annotated Programs}  </span><span class="nv">\label</span><span class="nb">{library_utilities:gap}</span>
</div><div id="l2363" class="code_block"><span class="nv">\index</span><span class="nb">{Generalized Annotated Programs}</span>
</div><div id="l2364" class="code_block">
</div><div id="l2365" class="code_block"><span class="nb">Generalized Annotated Programs </span><span class="o">(</span><span class="nb">GAPs</span><span class="o">)</span><span class="nb"> </span><span class="nv">\cite</span><span class="nb">{KiSu</span><span class="m">92</span><span class="nb">} offer a powerful</span>
</div><div id="l2366" class="code_block"><span class="nb">computational framework for handling paraconsistentcy and quantitative</span>
</div><div id="l2367" class="code_block"><span class="nb">information within logic programs.  The tabling of XSB is well</span><span class="o">-</span><span class="nb">suited</span>
</div><div id="l2368" class="code_block"><span class="nb">to implementing GAPs, and the gap library provides a meta</span><span class="o">-</span><span class="nb">interpreter</span>
</div><div id="l2369" class="code_block"><span class="nb">that has proven robust and efficient enough for a commercial</span>
</div><div id="l2370" class="code_block"><span class="nb">application in data mining.  The current meta</span><span class="o">-</span><span class="nb">interpreter is limited</span>
</div><div id="l2371" class="code_block"><span class="nb">to range</span><span class="o">-</span><span class="nb">restricted programs.</span>
</div><div id="l2372" class="code_block">
</div><div id="l2373" class="code_block"><span class="nb">A description of GAPs along with full documentation for this</span>
</div><div id="l2374" class="code_block"><span class="nb">meta</span><span class="o">-</span><span class="nb">interpreter is provided in </span><span class="nv">\cite</span><span class="nb">{Swif</span><span class="m">99</span><span class="nb">a} </span><span class="o">(</span><span class="nb">currently also</span>
</div><div id="l2375" class="code_block"><span class="nb">available at {</span><span class="nv">\tt</span><span class="nb"> http:</span><span class="o">//</span><span class="nb">www.cs.sunysb.edu</span><span class="o">/</span><span class="s">$</span><span class="k">\sim</span><span class="s">$</span><span class="nb">tswift}</span><span class="o">)</span><span class="nb">.  Currently, the</span>
</div><div id="l2376" class="code_block"><span class="nb">interface to the GAP library is through the following call.</span>
</div><div id="l2377" class="code_block">
</div><div id="l2378" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l2379" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{meta</span><span class="o">(</span><span class="nb">?Annotated</span><span class="nv">\_</span><span class="nb">atom</span><span class="o">)</span><span class="nb">}{gap} </span>
</div><div id="l2380" class="code_block"><span class="c">%</span>
</div><div id="l2381" class="code_block"><span class="nb">If {</span><span class="nv">\tt</span><span class="nb"> Annotated</span><span class="nv">\_</span><span class="nb">atom} is of the form {</span><span class="nv">\tt</span>
</div><div id="l2382" class="code_block"><span class="nb">Atom:</span><span class="o">[</span><span class="nb">Lattice</span><span class="nv">\_</span><span class="nb">type,Annotation</span><span class="o">]</span><span class="nb">} the meta</span><span class="o">-</span><span class="nb">interpreter computes bindings</span>
</div><div id="l2383" class="code_block"><span class="nb">for {</span><span class="nv">\tt</span><span class="nb"> Atom} and {</span><span class="nv">\tt</span><span class="nb"> Annotation} by evaluating the program</span>
</div><div id="l2384" class="code_block"><span class="nb">according to the definitions provided for {</span><span class="nv">\tt</span><span class="nb"> Lattice</span><span class="nv">\_</span><span class="nb">type}.</span>
</div><div id="l2385" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l2386" class="code_block">
</div><div id="l2387" class="code_block">
</div><div id="l2388" class="code_block"><span class="nv">\section</span><span class="nb">{Random Number Generator}</span>
</div><div id="l2389" class="code_block"><span class="c">%================================</span>
</div><div id="l2390" class="code_block">
</div><div id="l2391" class="code_block"><span class="nb">The following predicates are provided in module </span><span class="nv">\texttt</span><span class="nb">{random} to</span>
</div><div id="l2392" class="code_block"><span class="nb">generate random numbers </span><span class="o">(</span><span class="nb">both integers and floating numbers</span><span class="o">)</span><span class="nb">:</span>
</div><div id="l2393" class="code_block">
</div><div id="l2394" class="code_block"><span class="nv">\begin</span><span class="nb">{description}</span>
</div><div id="l2395" class="code_block">
</div><div id="l2396" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{random</span><span class="o">(-</span><span class="nb">Number</span><span class="o">)</span><span class="nb">}{random} </span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> random</span><span class="o">/</span><span class="m">1</span><span class="nb">}}</span>
</div><div id="l2397" class="code_block"><span class="c">%</span>
</div><div id="l2398" class="code_block"><span class="nb">Binds </span><span class="nv">\texttt</span><span class="nb">{Number} to a random float in the interval </span><span class="o">[</span><span class="m">0</span><span class="nb">.</span><span class="m">0</span><span class="nb">, </span><span class="m">1</span><span class="nb">.</span><span class="m">0</span><span class="o">)</span><span class="nb">.</span>
</div><div id="l2399" class="code_block"><span class="nb">Note that </span><span class="m">1</span><span class="nb">.</span><span class="m">0</span><span class="nb"> will never be generated.</span>
</div><div id="l2400" class="code_block">
</div><div id="l2401" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{random</span><span class="o">(+</span><span class="nb">Lower,</span><span class="o">+</span><span class="nb">Upper,</span><span class="o">-</span><span class="nb">Number</span><span class="o">)</span><span class="nb">}{random} </span><span class="nv">\index</span><span class="nb">{{</span><span class="nv">\tt</span><span class="nb"> random</span><span class="o">/</span><span class="m">3</span><span class="nb">}}</span>
</div><div id="l2402" class="code_block"><span class="nb">    Binds </span><span class="nv">\texttt</span><span class="nb">{Number} to a random integer in the interval</span>
</div><div id="l2403" class="code_block"><span class="nb">    </span><span class="o">[</span><span class="nv">\texttt</span><span class="nb">{Lower},</span><span class="nv">\texttt</span><span class="nb">{Upper}</span><span class="o">)</span><span class="nb"> if </span><span class="nv">\texttt</span><span class="nb">{Lower} and </span><span class="nv">\texttt</span><span class="nb">{Upper}</span>
</div><div id="l2404" class="code_block"><span class="nb">    are integers.  Otherwise </span><span class="nv">\texttt</span><span class="nb">{Number} is bound to a random float</span>
</div><div id="l2405" class="code_block"><span class="nb">    between </span><span class="nv">\texttt</span><span class="nb">{Lower} and </span><span class="nv">\texttt</span><span class="nb">{Upper}.  </span><span class="nv">\texttt</span><span class="nb">{Upper} will</span>
</div><div id="l2406" class="code_block"><span class="nb">    never be generated.</span>
</div><div id="l2407" class="code_block">
</div><div id="l2408" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{genrand</span><span class="o">(</span><span class="nb">?State</span><span class="o">)</span><span class="nb">}{random} </span><span class="nv">\index</span><span class="nb">{genrand</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l2409" class="code_block"><span class="nb">    Tries to unify </span><span class="nv">\texttt</span><span class="nb">{State} with the term </span><span class="nv">\texttt</span><span class="nb">{rand</span><span class="o">(</span><span class="nb">X,Y,Z</span><span class="o">)</span><span class="nb">}</span>
</div><div id="l2410" class="code_block"><span class="nb">    where </span><span class="nv">\texttt</span><span class="nb">{X},</span><span class="nv">\texttt</span><span class="nb">{Y},and </span><span class="nv">\texttt</span><span class="nb">{Z} are integers describing</span>
</div><div id="l2411" class="code_block"><span class="nb">    the state of the random generator.</span>
</div><div id="l2412" class="code_block">
</div><div id="l2413" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{setrand</span><span class="o">(</span><span class="nb">rand</span><span class="o">(+</span><span class="nb">X,</span><span class="o">+</span><span class="nb">Y,</span><span class="o">+</span><span class="nb">Z</span><span class="o">))</span><span class="nb">}{random} </span><span class="nv">\index</span><span class="nb">{setrand</span><span class="o">/</span><span class="m">1</span><span class="nb">}</span>
</div><div id="l2414" class="code_block"><span class="nb">    Sets the state of the random generator.  </span><span class="nv">\texttt</span><span class="nb">{X},</span><span class="nv">\texttt</span><span class="nb">{Y}, and</span>
</div><div id="l2415" class="code_block"><span class="nb">    </span><span class="nv">\texttt</span><span class="nb">{Z} must be integers in the ranges </span><span class="o">[</span><span class="m">1</span><span class="nb">,</span><span class="m">30269</span><span class="o">)</span><span class="nb">, </span><span class="o">[</span><span class="m">1</span><span class="nb">,</span><span class="m">30307</span><span class="o">)</span><span class="nb">,</span>
</div><div id="l2416" class="code_block"><span class="nb">    </span><span class="o">[</span><span class="m">1</span><span class="nb">,</span><span class="m">30323</span><span class="o">)</span><span class="nb">, respectively.</span>
</div><div id="l2417" class="code_block">
</div><div id="l2418" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{randseq</span><span class="o">(+</span><span class="nb">K, </span><span class="o">+</span><span class="nb">N, </span><span class="o">-</span><span class="nb">RandomSeq</span><span class="o">)</span><span class="nb">}{random} </span><span class="nv">\index</span><span class="nb">{randseq</span><span class="o">/</span><span class="m">3</span><span class="nb">}</span>
</div><div id="l2419" class="code_block"><span class="nb">    Generates a sequence of </span><span class="nv">\texttt</span><span class="nb">{K} unique integers chosen randomly</span>
</div><div id="l2420" class="code_block"><span class="nb">    in the range from </span><span class="m">1</span><span class="nb"> to </span><span class="nv">\texttt</span><span class="nb">{N}.  </span><span class="nv">\texttt</span><span class="nb">{RandomSeq} is not</span>
</div><div id="l2421" class="code_block"><span class="nb">    returned in any particular order.</span>
</div><div id="l2422" class="code_block">
</div><div id="l2423" class="code_block"><span class="nv">\ournewitem</span><span class="nb">{randset</span><span class="o">(+</span><span class="nb">K, </span><span class="o">+</span><span class="nb">N, </span><span class="o">-</span><span class="nb">RandomSet</span><span class="o">)</span><span class="nb">}{random} </span><span class="nv">\index</span><span class="nb">{randset</span><span class="o">/</span><span class="m">3</span><span class="nb">}</span>
</div><div id="l2424" class="code_block"><span class="nb">    Generates an ordered set of </span><span class="nv">\texttt</span><span class="nb">{K} unique integers chosen</span>
</div><div id="l2425" class="code_block"><span class="nb">    randomly in the range from </span><span class="m">1</span><span class="nb"> to </span><span class="nv">\texttt</span><span class="nb">{N}.  The set is returned in</span>
</div><div id="l2426" class="code_block"><span class="nb">    reversed order, with the largest element first and the smallest</span>
</div><div id="l2427" class="code_block"><span class="nb">    last.</span>
</div><div id="l2428" class="code_block">
</div><div id="l2429" class="code_block"><span class="nv">\end</span><span class="nb">{description}</span>
</div><div id="l2430" class="code_block">
</div><div id="l2431" class="code_block">
</div><div id="l2432" class="code_block">
</div><div id="l2433" class="code_block"><span class="c">%%% Local Variables: </span>
</div><div id="l2434" class="code_block"><span class="c">%%% mode: latex</span>
</div><div id="l2435" class="code_block"><span class="c">%%% TeX-master: &quot;manual2&quot;</span>
</div><div id="l2436" class="code_block"><span class="c">%%% End: </span>
</div></pre></div></td></tr></table></div>

      
    </div>
  

                    </div>
                    
                    
                </div>
            



        </div>
    </section>
      

    <footer class="sandiego">
    <div class="as-row">
        <div class="footer-wrapper">
            <nav aria-label="Site Links" role="navigation">
                <section>
                    <div class="as-h2">SourceForge</div>
                    <ul>
                    
                        <li><a href="/create/" title="Create a Project">Create a Project</a></li>
                    
                        <li><a href="/directory/" title="Open Source Software Directory">Open Source Software</a></li>
                        <li><a href="/software/" title="Business Software Directory">Business Software</a></li>
                        
                            
                            <li><a href="/top" title="Top Open Source Projects">Top Downloaded Projects</a></li>
                        

                    </ul>
                </section>
            </nav>
            <nav aria-label="Company Links" role="navigation">
                <section>
                    <div class="as-h2">Company</div>
                    <ul>
                        <li><a href="/about">About</a></li>
                        <li><a href="/about/leadership" title="Open Source Software Directory">Team</a></li>
                        <li class="h-card">
                            <address>
                                <span class="p-name p-org">SourceForge Headquarters</span><br>
                                <span class="p-street-address">225 Broadway Suite 1600</span><br>
                                <span class="p-locality">San Diego, CA <span class="p-postal-code">92101</span></span><br>
                                <span class="p-tel">+1 (858) 422-6466</span><br>
                            </address>
                        </li>
                        <li id="social">
                            
<span></span>
<a href="https://twitter.com/sourceforge" class="twitter" rel="nofollow" target="_blank" title="SourceForge on X">


<svg  class="vertical-icon-fix" data-name="twitter" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1684 408q-67 98-162 167 1 14 1 42 0 130-38 259.5t-115.5 248.5-184.5 210.5-258 146-323 54.5q-271 0-496-145 35 4 78 4 225 0 401-138-105-2-188-64.5t-114-159.5q33 5 61 5 43 0 85-11-112-23-185.5-111.5t-73.5-205.5v-4q68 38 146 41-66-44-105-115t-39-154q0-88 44-163 121 149 294.5 238.5t371.5 99.5q-8-38-8-74 0-134 94.5-228.5t228.5-94.5q140 0 236 102 109-21 205-78-37 115-142 178 93-10 186-50z"/></svg></a>
<a href="https://fosstodon.org/@sourceforge" rel="me nofollow" target="_blank" title="SourceForge on Mastodon">


<svg  class="vertical-icon-fix" data-name="mastodon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M433 179.11c0-97.2-63.71-125.7-63.71-125.7-62.52-28.7-228.56-28.4-290.48 0 0 0-63.72 28.5-63.72 125.7 0 115.7-6.6 259.4 105.63 289.1 40.51 10.7 75.32 13 103.33 11.4 50.81-2.8 79.32-18.1 79.32-18.1l-1.7-36.9s-36.31 11.4-77.12 10.1c-40.41-1.4-83-4.4-89.63-54a102.54 102.54 0 0 1-.9-13.9c85.63 20.9 158.65 9.1 178.75 6.7 56.12-6.7 105-41.3 111.23-72.9 9.8-49.8 9-121.5 9-121.5zm-75.12 125.2h-46.63v-114.2c0-49.7-64-51.6-64 6.9v62.5h-46.33V197c0-58.5-64-56.6-64-6.9v114.2H90.19c0-122.1-5.2-147.9 18.41-175 25.9-28.9 79.82-30.8 103.83 6.1l11.6 19.5 11.6-19.5c24.11-37.1 78.12-34.8 103.83-6.1 23.71 27.3 18.4 53 18.4 175z"/></svg></a>
<a href="https://www.facebook.com/sourceforgenet/" class="facebook" rel="nofollow" target="_blank" title="SourceForge on Facebook">


<svg  data-name="facebook" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1343 12v264h-157q-86 0-116 36t-30 108v189h293l-39 296h-254v759h-306v-759h-255v-296h255v-218q0-186 104-288.5t277-102.5q147 0 228 12z"/></svg></a>
<a href="https://www.linkedin.com/company/sourceforge.net" class="linkedin" rel="nofollow" target="_blank" title="SourceForge on LinkedIn">


<svg  data-name="linkedin" viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M477 625v991h-330v-991h330zm21-306q1 73-50.5 122t-135.5 49h-2q-82 0-132-49t-50-122q0-74 51.5-122.5t134.5-48.5 133 48.5 51 122.5zm1166 729v568h-329v-530q0-105-40.5-164.5t-126.5-59.5q-63 0-105.5 34.5t-63.5 85.5q-11 30-11 81v553h-329q2-399 2-647t-1-296l-1-48h329v144h-2q20-32 41-56t56.5-52 87-43.5 114.5-15.5q171 0 275 113.5t104 332.5z"/></svg></a>

<a href="/user/newsletters" rel=nofollow class="newsletter" title="Subscribe to our newsletter">


<svg  class="vertical-icon-fix" data-name="mmSF_11mail" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 42 42" enable-background="new 0 0 42 42" xml:space="preserve"><path fill="#FFFFFF" d="M0,6v30h42V6H0z M24.2,21.2c-0.8,0.8-2.3,2-3.2,2c-0.9,0-2.4-1.2-3.2-2L5.8,9.7h30.3L24.2,21.2z M13.7,21l-9.9,9.4V11.6L13.7,21z M15.7,23L15.7,23c0.5,0.5,2.9,2.9,5.3,2.9c2.4,0,4.8-2.4,5.2-2.8l0.1-0.1l9.8,9.4H5.8L15.7,23z M28.3,21l9.9-9.5v18.9L28.3,21z"/></svg></a>

<span></span>
                        </li>
                    </ul>
                </section>
            </nav>
             <nav aria-label="Resources Links" role="navigation">
                <section>
                    <div class="as-h2">Resources</div>
                    <ul>
                        
                            <li><a href="/support" title="Support Section">Support</a></li>
                            <li><a href="/p/forge/documentation/Docs%20Home/" title="Site Documentation">Site Documentation</a></li>
                        
                        <li><a href="https://fosstodon.org/@sourceforgestatus" title="Site Status" rel="me nofollow">Site Status</a></li>
                        <li><a href="/reviews" title="Reviews" rel="me nofollow">SourceForge Reviews</a></li>

                    </ul>
                </section>
            </nav>
            <section class="footer-logo">
                <a href="/" title="Home" class="sf-logo">
                    
    
    <img src="https://a.fsdn.com/con/images/sandiego/sf-logo-full.svg"  alt="SourceForge logo" class="sf-logo-full"/>
                </a>
            </section>
        </div>
    </div>
    <section class="l-nav-bottom">
        <nav class="row">
            
                
            
        
    <div class="columns small-12 large-6 copyright-notice">
        &copy; 2025 Slashdot Media. All Rights Reserved.
    </div>
    <div class="columns large-6 links links-right">
        

    
    

    <a href="https://slashdotmedia.com/terms-of-use" target="_blank" title="Terms" rel="nofollow">Terms</a>
    <a href="https://slashdotmedia.com/privacy-statement/" target="_blank" title="Privacy" rel="nofollow">Privacy</a>

    
    
    

    
        <a href="https://slashdotmedia.com/opt-out-choices/" target="_blank" title="Opt Out" rel="nofollow">Opt Out</a>
    

    
        <a href="https://slashdotmedia.com/contact/" target="_blank" title="Advertise" rel="nofollow">Advertise</a>
    
    </div>
        </nav>
    </section>

    </footer>
    





    
    
    <div id="newsletter-floating" class="sandiego newsletter-floating-new">
        <a class="close-button btn-closer" data-close aria-label="Close modal">
            <span aria-hidden="true">&times;</span>
        </a>
        <div class="as-h2">Want the latest updates on software, tech news, and AI?</div>
        <div class="row">
            <div class="column small-2 medium-2 large-2" style="padding-left: 0px; padding-right: 0px;"><img src="/images/sandiego/sf_email_icon.svg"  alt="" /></div>
            <div class="as-h3 column small-10 medium-10 large-10">Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.</div>
        </div>
        <form action="/user/newsletters/" method="post">
            <div class="row">
              <input class="newsletter-input" type="email" placeholder="Enter your email address" autocomplete="off" name="newsletter_email"
                     value="">
              <input type="hidden" name="source" value="floating">
              <button type="submit" class="button blue newsletter-button">Submit</button>
            </div>
        </form>
    </div>
    






</div>


<div id="messages">
    
</div>


    <!-- ew:body_js -->


    <script type="text/javascript" src="https://a.fsdn.com/allura/nf/1752257864/_ew_/_slim/js?href=allura%2Fjs%2Fjquery.notify.js%3Ballura%2Fjs%2Fjquery.tooltipster.js%3Ballura%2Fjs%2Fallura-base.js%3Ballura%2Fjs%2Fchecklist.js%3Ballura%2Fjs%2Fadmin_modal.js%3Bjs%2Fjquery.lightbox_me.js%3Ballura%2Fjs%2Fmemorable.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fshared.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fsticky.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fsandiego%2Fchrome.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fsandiego%2Futilities.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.core.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.util.mediaQuery.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.util.keyboard.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.util.box.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.util.nest.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.dropdownMenu.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.offcanvas.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.toggler.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fsandiego%2Fproject.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Fjquery.typeahead.min.js%3Ballura%2Fjs%2Fmaximize-content.js"></script>

    
<!-- /ew:body_js -->



    <!-- ew:body_js_tail -->


    <script type="text/javascript" src="https://a.fsdn.com/allura/nf/1752257864/_ew_/_slim/js?href=theme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.util.triggers.min.js%3Btheme%2Fsftheme%2Fjs%2Fsftheme%2Fvendor%2Ffoundation6%2Fplugins%2Ffoundation.reveal.min.js"></script>

    
<!-- /ew:body_js_tail -->




<script type="text/javascript">(function() {
  $('#access_urls .btn').click(function(evt){
    evt.preventDefault();
    var parent = $(this).parents('.btn-bar');
    var checkout_cmd = $(this).attr('data-url');
    $(parent).find('input').val(checkout_cmd);
    $(parent).find('span').text($(this).attr('title')+' access');
    $(this).parent().children('.btn').removeClass('active');
    $(this).addClass('active');
    if (checkout_cmd.indexOf(' http://') !== -1 || checkout_cmd.indexOf(' https://') !== -1 ) {
      $('#http-2fa-msg').show();
    } else {
      $('#http-2fa-msg').hide();
    }
  });
  $('#access_urls .btn').first().click();

  
  var repo_status = document.getElementById('repo_status');
  // The repo_status div will only be present if repo.status != 'ready'
  if (repo_status) {
    $('.spinner').show()
    var delay = 500;
    function check_status() {
        $.get('/p/xsb/src/status', function(data) {
            if (data.status === 'ready') {
                $('.spinner').hide()
                $('#repo_status h2').html('Repo status: ready. <a href="." rel="nofollow">Click here to refresh this page.</a>');
            }
            else {
                $('#repo_status h2 span').html(data.status);
                if (delay < 60000){
                    delay = delay * 2;
                }
                window.setTimeout(check_status, delay);
            }
        });
    }
    var status_checker = window.setTimeout(check_status, delay);
    
  }
}());
</script>

<script type="text/javascript">(function() {
  $(window).on('hashchange', function(e) {
    var hash = window.location.hash.substring(1);
    if ('originalEvent' in e && 'oldURL' in e.originalEvent) {
      $('#' + e.originalEvent.oldURL.split('#')[1]).css('background-color', 'transparent');
    }
    if (hash !== '' && hash.substring(0, 1) === 'l' && !isNaN(hash.substring(1))) {
      $('#' + hash).css('background-color', '#ffff99');
    }
  }).trigger('hashchange');

  var clicks = 0;
  $('.code_block').each(function(index, element) {
    $(element).on('click', function() {
      // Trick to ignore double and triple clicks
      clicks++;
      if (clicks === 1) {
        setTimeout(function() {
          if (clicks === 1) {
            var hash = window.location.hash.substring(1);
            if (hash !== '' && hash.substring(0, 1) === 'l' && !isNaN(hash.substring(1))) {
              $('#' + hash).css('background-color', 'transparent');
            }
            $(element).css('background-color', '#ffff99');
            window.history.pushState({}, document.title, window.location.pathname + window.location.search + '#' + $(element).attr('id'));
          }
          clicks = 0;
        }, 500);
      }
    });
  });
}());
</script>


    


    
    
    <noscript><p><img src="https://analytics.slashdotmedia.com/index.php?idsite=39" style="border:0;position:absolute;top:0;" alt="" /></p></noscript>
    
    <script>
        $(document).foundation();
    </script>
    








    

<script>
    (function () {
        function load_bombora() {
            /*global _ml:true, window */
            _ml = window._ml || {};
            
            _ml.eid = '771';
            _ml.fp = '004685ec-e292-4e54-b751-f89c4f04e79b';  
            var s = document.getElementsByTagName('script')[0], cd = new Date(), mltag = document.createElement('script');
            mltag.type = 'text/javascript';
            mltag.async = true;
            mltag.defer = true;
            mltag.src = '//ml314.com/tag.aspx?' + cd.getDate() + cd.getMonth() + cd.getFullYear();
            s.parentNode.insertBefore(mltag, s);
        }
        bizx.cmp.ifConsent({ purposes: 'all', vendors: 'bombora'},function() {
                    if (document.hidden) {
                        document.addEventListener('visibilitychange', function () {
                            if (!document.hidden) {
                                load_bombora();
                            }
                        }, {once: true});
                    } else {
                        load_bombora();
                    }
                });
    })();
</script>




<script>
    $(document).ready(function () {
        $(".tooltip, .m-tooltip").each(function(){
            let $el = $(this);
            $el.tooltipster({
                animation: 'fade',
                delay: 200,
                theme: 'tooltipster-light',
                trigger: 'hover',
                position: $el.data('position') || 'right',
                iconCloning: false,
                maxWidth: 300,
                contentAsHTML: true,
                interactive: true
            }).focus(function () {
                $(this).tooltipster('show');
            }).blur(function () {
                $(this).tooltipster('hide');
            });
        });
    });
</script>

    



<script type="text/javascript">
    bizx.cmp.ifConsent({ purposes: ['storage', 'measurement'], vendors: 'google-analytics'}, function () {
        /* jshint ignore:start */
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
                (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
            m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
        /* jshint ignore:end */

        window.dataLayer = window.dataLayer || [];
        function gtag(){ window.dataLayer.push(arguments); }
        window.gtag = window.gtag || gtag;
        bizx.cmp.embedScript("https://www.googletagmanager.com/gtag/js");
        gtag('js', new Date());
        gtag('set', {
            'page_location': 'https://sourceforge.net/p/xsb/src/2137/tree/trunk/XSB/docs/userman/library.tex',
        });
    });
</script>










<script>
        function gam(id){
            bizx.cmp.ifConsent({ purposes: 'all' }, function () {
                bizx.cmp.embedScript(`https://pagead2.googlesyndication.com/pagead/js/pcd.js?${id}`,
                    true,  // async
                    'head', // location
                    null, // callback
                    false, // defer
                    {id: `google-pcd-tag-${id}`, 'data-audience-pixel': 'dc_iu=/41014381/DFPAudiencePixel;dc_seg=' + id});
            });
        }

        
            gam("8901705213");gam("8901712041");</script>

<script type="text/javascript">
    /*global ga, gtag */

    
        
        bizx.cmp.ifConsent({ purposes: ['storage', 'measurement'], vendors: 'google-analytics'}, function () {
            gtag('config', 'G-1H226E4E4L', {
                
                send_page_view: false,
                'SF_Page_Type': '', 
                user_properties: {
                    'SF_Logged_in': 'Logged Out', 
                },
                'devicePixelRatio': SF.devicePixelRatio, 
            });
            gtag('event', 'page_view', { send_to: 'G-1H226E4E4L' });
        });
    
    
    
        
</script>

</body>
</html>