

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


    

















<html lang="en" class="no-js">
<head>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
    <title>
  XSB / Src  (SVN)-old /
  [r1610]
  /trunk/XSB/docs/userman/ccallingxsb.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 = 'bf0bf24d-d12c-4904-b5bc-5e2285e4124f';
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>.XwpDCgwXCjsOFwnCrLCkcOOLcOjwpnDkcKywqLDvsOswkX {
        display: none
    }</style>

    
    
    
        <link rel="canonical" href="https://sourceforge.net/p/xsb/src/1610/tree/trunk/XSB/docs/userman/ccallingxsb.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%3Abf0bf24d-d12c-4904-b5bc-5e2285e4124f&id=site_name%3Asourceforge.net&id=url%3A%2Fp%2Fxsb%2Fsrc%2F1610%2Ftree%2Ftrunk%2FXSB%2Fdocs%2Fuserman%2Fccallingxsb.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/1610/" rel="nofollow">[r1610]</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> /
  
 ccallingxsb.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/1610/log/?path=/trunk/XSB/docs/userman/ccallingxsb.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>
        467 lines (421 with data), 22.5 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></pre></div></td><td class="code"><div><pre><div id="l1" class="code_block"><span class="k">\chapter</span><span class="nb">{</span>Calling <span class="k">\ourprolog\</span> from C<span class="nb">}</span>
</div><div id="l2" class="code_block"><span class="c">%===================================</span>
</div><div id="l3" class="code_block"><span class="k">\label</span><span class="nb">{</span>ccallingxsb<span class="nb">}</span>
</div><div id="l4" class="code_block">
</div><div id="l5" class="code_block">There are many situations in which it may be desirable to use
</div><div id="l6" class="code_block"><span class="k">\ourprolog\</span> as a rule-processing subcomponent of a larger system,
</div><div id="l7" class="code_block">which is written in another language.  To do this, one wants to be
</div><div id="l8" class="code_block">able to <span class="nb">{</span><span class="k">\em</span> call<span class="nb">}</span><span class="k">\</span> <span class="k">\ourprolog\</span> from the host language, often C,
</div><div id="l9" class="code_block">providing queries for <span class="k">\ourprolog\</span> to evaluate and retrieving back the
</div><div id="l10" class="code_block">answers.  An interface for calling <span class="k">\ourprolog\</span> from C is provided for
</div><div id="l11" class="code_block">this purpose and is described in this chapter.  Simple examples of
</div><div id="l12" class="code_block">the use of this interface are given in the <span class="nb">{</span><span class="k">\tt</span> XSB/examples/c<span class="k">\_calling\_XSB</span><span class="nb">}</span>
</div><div id="l13" class="code_block">subdirectory, in files <span class="nb">{</span><span class="k">\tt</span> cmain.c<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> cmain2.c<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> ctest.P<span class="nb">}</span>, and <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l14" class="code_block">Makefile<span class="nb">}</span>.
</div><div id="l15" class="code_block">
</div><div id="l16" class="code_block"><span class="k">\section</span><span class="nb">{</span>C Functions for Calling <span class="k">\ourprolog</span><span class="nb">}</span>
</div><div id="l17" class="code_block">
</div><div id="l18" class="code_block"><span class="k">\ourprolog\</span> provides several C functions (declared in <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l19" class="code_block">XSB/emu/cinterf.h<span class="nb">}</span> and defined in <span class="k">\\</span> <span class="nb">{</span><span class="k">\tt</span> XSB/emu/cinterf.c<span class="nb">}</span>), which can
</div><div id="l20" class="code_block">be called from C to interact with <span class="k">\ourprolog\</span> as a subroutine. These
</div><div id="l21" class="code_block">functions allow a C program to initialize <span class="k">\ourprolog\</span> (most easily with
</div><div id="l22" class="code_block">a call to <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_init\_string</span>(options)<span class="nb">}</span>) and then to interact with it
</div><div id="l23" class="code_block">to have it perform various functions.  One can send commands to have
</div><div id="l24" class="code_block">them evaluated by <span class="k">\ourprolog</span> .  A command is a deterministic query which
</div><div id="l25" class="code_block">simply succeeds or fails (without returning any interesting data value.)
</div><div id="l26" class="code_block">One can also send a query to be evaluated and then retrieve, one at a
</div><div id="l27" class="code_block">time, the answers produced for it.  There are several levels of
</div><div id="l28" class="code_block">interface provided.  The highest level interface uses strings to
</div><div id="l29" class="code_block">communicate queries to <span class="k">\ourprolog\</span> and to get answers back.  The <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l30" class="code_block">xsb<span class="k">\_command\_string</span>(cmd)<span class="nb">}</span> function allows you to pass a command as a
</div><div id="l31" class="code_block">(period-terminated) string to <span class="k">\ourprolog</span> .  The <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l32" class="code_block">xsb<span class="k">\_query\_string\_string</span>(query,buff,sep)<span class="nb">}</span> function allows
</div><div id="l33" class="code_block">you to pass a query to XSB as a string, and have its (first) answer
</div><div id="l34" class="code_block">returned as a string.  Subsequent answers can be calculated and
</div><div id="l35" class="code_block">retrieved using <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_next\_string</span>(buff,sep)<span class="nb">}</span>.
</div><div id="l36" class="code_block">
</div><div id="l37" class="code_block">There are lower-level interfaces that allow you to manipulate directly
</div><div id="l38" class="code_block">the <span class="k">\ourprolog\</span> data structures (both to construct queries and to
</div><div id="l39" class="code_block">retrieve answers) and thus avoid the overhead of converting to and from
</div><div id="l40" class="code_block">strings.  See the detailed descriptions of the routines below to see how
</div><div id="l41" class="code_block">to use the lower level interface.
</div><div id="l42" class="code_block">
</div><div id="l43" class="code_block">Currently, only one query can be active at a time.
</div><div id="l44" class="code_block">I.e., one must completely finish processing one query (either by
</div><div id="l45" class="code_block">retrieving all the answers for it, or by issuing a call to <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l46" class="code_block">xsb<span class="k">\_close\_query</span>()<span class="nb">}</span>, before trying to evaluate another.  The
</div><div id="l47" class="code_block">routines to perform all these functions are described following:
</div><div id="l48" class="code_block">
</div><div id="l49" class="code_block"><span class="k">\begin</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l50" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_init</span>(int argc, char *argv[])<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_init</span><span class="nb">}}</span>
</div><div id="l51" class="code_block">This is a C-callable function that initializes <span class="k">\ourprolog</span> . It must be
</div><div id="l52" class="code_block">called before any other calls can be made.  <span class="nb">{</span><span class="k">\tt</span> argc<span class="nb">}</span> is the count of
</div><div id="l53" class="code_block">the number of arguments in the <span class="nb">{</span><span class="k">\tt</span> argv<span class="nb">}</span> vector.  The <span class="nb">{</span><span class="k">\tt</span> argv<span class="nb">}</span>
</div><div id="l54" class="code_block">vector is exactly as would be passed from the command line to
</div><div id="l55" class="code_block"><span class="k">\ourprolog</span> .  It must contain at least the following two things:
</div><div id="l56" class="code_block"><span class="c">%%</span>
</div><div id="l57" class="code_block"><span class="k">\begin</span><span class="nb">{</span>itemize<span class="nb">}</span>
</div><div id="l58" class="code_block"><span class="k">\item</span> <span class="s">$</span><span class="nv">\tt</span><span class="nb"> argv</span><span class="o">[</span><span class="m">0</span><span class="o">]</span><span class="s">$</span> must be an absolute or relative path name of the XSB
</div><div id="l59" class="code_block">  installation directory (<span class="nb">{</span><span class="k">\it</span> i.e.<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> <span class="k">\$</span>XSB<span class="k">\_DIR</span><span class="nb">}</span>.  Here is an
</div><div id="l60" class="code_block">  example, which assumes that we invoke the C program from the XSB
</div><div id="l61" class="code_block">  installation directory.
</div><div id="l62" class="code_block">    <span class="c">%%</span>
</div><div id="l63" class="code_block">    <span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l64" class="code_block">int main(int argc, char *argv[])
</div><div id="l65" class="code_block"><span class="nb">{</span> 
</div><div id="l66" class="code_block">  int myargc = 2;
</div><div id="l67" class="code_block">  char *myargv[2];
</div><div id="l68" class="code_block">
</div><div id="l69" class="code_block">  /* XSB<span class="nb">_</span>init relies on the calling program to pass the addr of the XSB
</div><div id="l70" class="code_block">     installation directory. From here, it will find all the libraries */
</div><div id="l71" class="code_block">  myargv[0] = &quot;.&quot;;
</div><div id="l72" class="code_block">  myargv[1] = &quot;-n&quot;;
</div><div id="l73" class="code_block">
</div><div id="l74" class="code_block">  /* Initialize xsb */
</div><div id="l75" class="code_block">  xsb<span class="nb">_</span>init(myargc,myargv);
</div><div id="l76" class="code_block">    <span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l77" class="code_block">    <span class="c">%%</span>
</div><div id="l78" class="code_block">  <span class="k">\item</span> <span class="s">$</span><span class="nv">\tt</span><span class="nb"> argv</span><span class="o">[</span><span class="m">1</span><span class="o">]</span><span class="s">$</span> must be the <span class="nb">{</span><span class="k">\tt</span> -n<span class="nb">}</span> flag.  This flag tells
</div><div id="l79" class="code_block">    <span class="k">\ourprolog\</span> not to start the read-eval-print top loop, but to act as a
</div><div id="l80" class="code_block">    subroutine to a calling C routine.
</div><div id="l81" class="code_block"><span class="k">\end</span><span class="nb">{</span>itemize<span class="nb">}</span>
</div><div id="l82" class="code_block"><span class="c">%%</span>
</div><div id="l83" class="code_block">Other flags are optional, but can be used to modify sizes of the various
</div><div id="l84" class="code_block">spaces used in <span class="k">\ourprolog</span>.  In particular, if <span class="k">\ourprolog\</span> will be required
</div><div id="l85" class="code_block">to load some other (usually C) program using the foreign language
</div><div id="l86" class="code_block">interface, then the -E option must be used to specify the full path name of
</div><div id="l87" class="code_block">the executable of the main C program.  See the section on Command Line
</div><div id="l88" class="code_block">Options in Volume 1 
</div><div id="l89" class="code_block">for more details.  <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_init</span><span class="nb">}</span> returns 0 if initialization is
</div><div id="l90" class="code_block">completed, and 1 if some error is encountered.
</div><div id="l91" class="code_block">
</div><div id="l92" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_init\_string</span>(char *options)<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_init\_string</span><span class="nb">}}</span>
</div><div id="l93" class="code_block">This is a variant of <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_init</span><span class="nb">}</span> which takes the command line as a
</div><div id="l94" class="code_block">string argument (rather than as a argc/argv pair.)  For example, a call
</div><div id="l95" class="code_block">could be
</div><div id="l96" class="code_block"><span class="c">%%</span>
</div><div id="l97" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l98" class="code_block">   xsb<span class="nb">_</span>init<span class="nb">_</span>string(&quot;. -n&quot;);
</div><div id="l99" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l100" class="code_block"><span class="c">%%</span>
</div><div id="l101" class="code_block">Note that just as with <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_init</span><span class="nb">}</span>, you must pass the path name of the
</div><div id="l102" class="code_block">XSB installation directory. In the above, we pass ``.&#39;&#39;, assuming that we
</div><div id="l103" class="code_block">are invoking the C program from the XSB installation directory.  The
</div><div id="l104" class="code_block">parameters following the file name are just as those that could appear on a
</div><div id="l105" class="code_block">command line.  The function of this subroutine is exactly the same as <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l106" class="code_block">  xsb<span class="k">\_init</span><span class="nb">}</span>, and its return codes are the same.
</div><div id="l107" class="code_block">
</div><div id="l108" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_command</span>()<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_command</span><span class="nb">}}</span>
</div><div id="l109" class="code_block">This function passes a command to <span class="k">\ourprolog</span> .  No query can be active
</div><div id="l110" class="code_block">when this command is called.  Before calling <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_command</span><span class="nb">}</span>, the
</div><div id="l111" class="code_block">calling program must construct the <span class="k">\ourprolog\</span> term representing the
</div><div id="l112" class="code_block">command in register 1 in <span class="k">\ourprolog</span> &#39;s space.  This can be done by
</div><div id="l113" class="code_block">using the <span class="nb">{</span><span class="k">\tt</span> c2p<span class="k">\_*</span><span class="nb">}</span> (and <span class="nb">{</span><span class="k">\tt</span> p2p<span class="k">\_*</span><span class="nb">}</span>) routines, which are
</div><div id="l114" class="code_block">described in Section <span class="k">\ref</span><span class="nb">{</span>c2p<span class="nb">_</span>p2p<span class="nb">_</span>p2c<span class="nb">}</span> below.  Register 2 may also be
</div><div id="l115" class="code_block">set before the call to <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> (using <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l116" class="code_block">xsb<span class="k">\_make\_vars</span>(int)<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_set\_var\_*</span>()<span class="nb">}</span>) in which case any
</div><div id="l117" class="code_block">variables set to values in the <span class="nb">{</span><span class="k">\tt</span> ret/n<span class="nb">}</span> term will be so bound in
</div><div id="l118" class="code_block">the call to the command goal.  <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_command</span><span class="nb">}</span> invokes the command
</div><div id="l119" class="code_block">represented in register 1 and returns 0 if the command succeeds and 1
</div><div id="l120" class="code_block">if it fails. In either case it resets register 1 back to a free
</div><div id="l121" class="code_block">variable. If there is an error, it returns 2.
</div><div id="l122" class="code_block">
</div><div id="l123" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_command\_string</span>(char *cmd)<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_command\_string</span><span class="nb">}}</span>
</div><div id="l124" class="code_block">This function passes a command to <span class="k">\ourprolog</span> .  The command is a
</div><div id="l125" class="code_block">string consisting of a term that can be read by the <span class="k">\ourprolog\</span>
</div><div id="l126" class="code_block">reader.  The string must be terminated by a period (.).  Any previous
</div><div id="l127" class="code_block">query must have already been closed.  In all other respects, <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l128" class="code_block">xsb<span class="k">\_command\_string</span><span class="nb">}</span> is similar to <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_command</span><span class="nb">}</span>.
</div><div id="l129" class="code_block">
</div><div id="l130" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_query</span>()<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}}</span>
</div><div id="l131" class="code_block">This function passes a query to <span class="k">\ourprolog</span> .  Any previous query must
</div><div id="l132" class="code_block">have already been closed.  A query is expected to return possibly
</div><div id="l133" class="code_block">multiple data answers.  The first is found and made available to the
</div><div id="l134" class="code_block">caller as a result of this call.  To get subsequent answers, <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l135" class="code_block">xsb<span class="k">\_next</span><span class="nb">}</span> must be called.  Before calling <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> the caller
</div><div id="l136" class="code_block">must construct the term representing the query in <span class="k">\ourprolog</span> &#39;s
</div><div id="l137" class="code_block">register 1 (using routines described in Section <span class="k">\ref</span><span class="nb">{</span>c2p<span class="nb">_</span>p2p<span class="nb">_</span>p2c<span class="nb">}</span>
</div><div id="l138" class="code_block">below.)  If the query has no answers (i.e., just fails), register 1 is
</div><div id="l139" class="code_block">set back to a free variable and <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> returns 1.  If the
</div><div id="l140" class="code_block">query has at least one answer, the variables in the query term in
</div><div id="l141" class="code_block">register 1 are bound to those answers and <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> returns 0.
</div><div id="l142" class="code_block">In addition, register 2 is bound to a term whose main functor symbol
</div><div id="l143" class="code_block">is <span class="nb">{</span><span class="k">\tt</span> ret/n<span class="nb">}</span>, where n is the number of variables in the query. The
</div><div id="l144" class="code_block">main subfields of this term are set to the variable values for the
</div><div id="l145" class="code_block">first answer. (These fields can be accessed by the functions <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l146" class="code_block">p2c<span class="k">\_*</span><span class="nb">}</span>, or the functions <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_var\_*</span><span class="nb">}</span>, described in Section
</div><div id="l147" class="code_block"><span class="k">\ref</span><span class="nb">{</span>c2p<span class="nb">_</span>p2p<span class="nb">_</span>p2c<span class="nb">}</span> below.)  Thus there are two places the answers are
</div><div id="l148" class="code_block">returned. Register 2 is used to make it easier to access them.  To get
</div><div id="l149" class="code_block">subsequent answers, <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_next</span><span class="nb">}</span> must be called.  Register 2 may
</div><div id="l150" class="code_block">also be set before the call to <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> (using <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l151" class="code_block">xsb<span class="k">\_make\_vars</span>(int)<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_set\_var\_*</span>()<span class="nb">}</span>) in which case any
</div><div id="l152" class="code_block">variables set to values in the <span class="nb">{</span><span class="k">\tt</span> ret/n<span class="nb">}</span> term will be so bound in
</div><div id="l153" class="code_block">the call to the goal.
</div><div id="l154" class="code_block">
</div><div id="l155" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_query\_string</span>(char *query)<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_query\_string</span><span class="nb">}}</span>
</div><div id="l156" class="code_block">This function passes a query to <span class="k">\ourprolog</span> .  The query is a string
</div><div id="l157" class="code_block">consisting of a term that can be read by the <span class="k">\ourprolog\</span> reader.  The
</div><div id="l158" class="code_block">string must be terminated with a period (.).  Any previous query must
</div><div id="l159" class="code_block">have already been closed.  In all other respects, xsb<span class="k">\_query\_string</span>
</div><div id="l160" class="code_block">is similar to xsb<span class="k">\_query</span>, except the only way to retrieve answers is
</div><div id="l161" class="code_block">through Register 2.  The ability to create the return structure and
</div><div id="l162" class="code_block">bind variables in it is particularly useful in this function.
</div><div id="l163" class="code_block">
</div><div id="l164" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_query\_string\_string</span>(char *query, VarString *buff
</div><div id="l165" class="code_block">char *sep)<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_query\_string\_string</span><span class="nb">}}</span> This function
</div><div id="l166" class="code_block">is a variant of <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query\_string</span><span class="nb">}</span> that returns its answer (if
</div><div id="l167" class="code_block">there is one) as a string.  An example call is:
</div><div id="l168" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l169" class="code_block">rc = xsb<span class="nb">_</span>query<span class="nb">_</span>string<span class="nb">_</span>string(&quot;append(X,Y,[a,b,c]).&quot;,buff,&quot;;&quot;);
</div><div id="l170" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l171" class="code_block">The first argument is the period-terminated query string.  The second
</div><div id="l172" class="code_block">argument is a variable string buffer in which the subroutine returns the answer
</div><div id="l173" class="code_block">(if any.) The variable string data type <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span>  is explained in
</div><div id="l174" class="code_block">Section~<span class="k">\ref</span><span class="nb">{</span>sec-varstring<span class="nb">}</span>. The last argument is a string
</div><div id="l175" class="code_block">provided by the caller, which is used to separate fields in the returned
</div><div id="l176" class="code_block">answer.  For the example query, buff would be set to the string:
</div><div id="l177" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l178" class="code_block">        [];[a,b,c]
</div><div id="l179" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l180" class="code_block">which is the first answer to the append query.  There are two fields of
</div><div id="l181" class="code_block">this answer, corresponding to the two variables in the query, <span class="k">\verb</span>|X|
</div><div id="l182" class="code_block">and <span class="k">\verb</span>|Y|.  The bindings of those variables make up the answer and
</div><div id="l183" class="code_block">the individual fields are separated by the <span class="k">\verb</span>|sep| string, here the
</div><div id="l184" class="code_block">semicolon (<span class="k">\verb</span>|;|).  If the answer would overflow the buffer, the
</div><div id="l185" class="code_block">subroutine returns 3 as its function value.  Otherwise its returns are
</div><div id="l186" class="code_block">just as for <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query\_string</span><span class="nb">}</span>.  In the answer string, <span class="k">\ourprolog\</span>
</div><div id="l187" class="code_block">atoms are printed in their in their standard print form (without
</div><div id="l188" class="code_block">quotes).  Complex terms are printed in a canonical form, with atoms
</div><div id="l189" class="code_block">quoted if necessary, and lists produced in the normal list notation.
</div><div id="l190" class="code_block">
</div><div id="l191" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_next</span>()<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_next</span><span class="nb">}}</span>
</div><div id="l192" class="code_block">This routine is called after <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> (which must have
</div><div id="l193" class="code_block">returned 0) to retrieve more answers.  It rebinds the query variables
</div><div id="l194" class="code_block">in the term in register 1 and rebinds the argument fields of the <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l195" class="code_block">ret/n<span class="nb">}</span> answer term in register 2 to reflect the next answer to the
</div><div id="l196" class="code_block">query.  It returns 0 if an answer is found, and returns 1 if there are
</div><div id="l197" class="code_block">no more answers and no answer is returned. On a return of 1, the query
</div><div id="l198" class="code_block">has been closed.  After a query is closed, another <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_command</span><span class="nb">}</span>
</div><div id="l199" class="code_block">or <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> invocation can be made.
</div><div id="l200" class="code_block">
</div><div id="l201" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_next\_string</span>(VarString *buff,char *sep)<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span>
</div><div id="l202" class="code_block">xsb<span class="k">\_next\_string</span><span class="nb">}}</span>  This routine is a variant of <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_next</span><span class="nb">}</span> that
</div><div id="l203" class="code_block">returns its answer (if there is one) as a string.  Its treatment of
</div><div id="l204" class="code_block">answers is just as <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query\_string\_string</span><span class="nb">}</span>.  For example after
</div><div id="l205" class="code_block">the example call 
</div><div id="l206" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l207" class="code_block">rc = xsb<span class="nb">_</span>query<span class="nb">_</span>string<span class="nb">_</span>string(&quot;append(X,Y,[a,b,c]).&quot;,buff,&quot;;&quot;);
</div><div id="l208" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l209" class="code_block">which returns with buff set to 
</div><div id="l210" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l211" class="code_block">        [];[a,b,c]
</div><div id="l212" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l213" class="code_block">Then a call:
</div><div id="l214" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l215" class="code_block">rc = xsb<span class="nb">_</span>next<span class="nb">_</span>string(buff,&quot;;&quot;);
</div><div id="l216" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l217" class="code_block">returns with buff set to 
</div><div id="l218" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l219" class="code_block">        [a];[b,c]
</div><div id="l220" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l221" class="code_block">the second answer to the indicated query. <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_next\_string</span><span class="nb">}</span>
</div><div id="l222" class="code_block">returns codes just as <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_next</span><span class="nb">}</span>, but returns 3 if the answer
</div><div id="l223" class="code_block">buffer would overflow.
</div><div id="l224" class="code_block">
</div><div id="l225" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_close\_query</span>()<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_close\_query</span><span class="nb">}}</span>
</div><div id="l226" class="code_block">This routine closes a query, before all its answers have been
</div><div id="l227" class="code_block">retrieved.  Since <span class="k">\ourprolog\</span> is (usually) a tuple-at-a-time system,
</div><div id="l228" class="code_block">answers that are not retrieved are not computed.
</div><div id="l229" class="code_block">It is an error to call <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> again without
</div><div id="l230" class="code_block">first either retrieving all the answers to the previous query or
</div><div id="l231" class="code_block">calling <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_close\_query</span><span class="nb">}</span> to close it.
</div><div id="l232" class="code_block">
</div><div id="l233" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>int xsb<span class="k">\_close</span>()<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_close</span><span class="nb">}}</span>
</div><div id="l234" class="code_block">This routine closes the entire connection to <span class="k">\ourprolog</span> .  After this,
</div><div id="l235" class="code_block">no more calls can be made (including calls to <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_init</span><span class="nb">}</span>.)
</div><div id="l236" class="code_block"><span class="k">\end</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l237" class="code_block">
</div><div id="l238" class="code_block"><span class="k">\section</span><span class="nb">{</span>The Variable-length String Data Type<span class="nb">}</span><span class="k">\label</span><span class="nb">{</span>sec-varstring<span class="nb">}</span>
</div><div id="l239" class="code_block">
</div><div id="l240" class="code_block"><span class="k">\index</span><span class="nb">{</span>VarString<span class="nb">}</span> XSB uses variable-length strings to communicate with
</div><div id="l241" class="code_block">certain C subroutines when the size of the output that needs to be passed
</div><div id="l242" class="code_block">from the Prolog side to the C side is not known. Variable-length strings
</div><div id="l243" class="code_block">adjust themselves depending on the size of the data they must hold and are
</div><div id="l244" class="code_block">ideal for this situation. For instance, as we have seem the two subroutines
</div><div id="l245" class="code_block"><span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query\_string\_string</span>(query,buff,sep)<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l246" class="code_block">  xsb<span class="k">\_next\_string</span>(buff,sep)<span class="nb">}</span> use the variable string data type, <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l247" class="code_block">  VarString<span class="nb">}</span>, for their second argument.  To use this data type, make sure
</div><div id="l248" class="code_block">that
</div><div id="l249" class="code_block"><span class="c">%%</span>
</div><div id="l250" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l251" class="code_block">#include &quot;cinterf.h&quot;  
</div><div id="l252" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l253" class="code_block"><span class="c">%%</span>
</div><div id="l254" class="code_block">appears at the top of the program file.  Variables of the <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span>
</div><div id="l255" class="code_block">type are declared using a macro that must appear in the declaration section
</div><div id="l256" class="code_block">of the program:
</div><div id="l257" class="code_block"><span class="c">%%</span>
</div><div id="l258" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l259" class="code_block">vstrDEFINE(buf);  
</div><div id="l260" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l261" class="code_block"><span class="c">%%</span>
</div><div id="l262" class="code_block">There is one important consideration concerning VarString with the
</div><div id="l263" class="code_block"><span class="k">\emph</span><span class="nb">{</span>automatic<span class="nb">}</span> storage class: they must be
</div><div id="l264" class="code_block"><span class="k">\emph</span><span class="nb">{</span>destroyed<span class="nb">}</span> on exit (see <span class="nb">{</span><span class="k">\tt</span> vstrDESTROY<span class="nb">}</span>, below) from the procedure
</div><div id="l265" class="code_block">that defines them, or else there will be a memory leak. 
</div><div id="l266" class="code_block">It is not necessary to destroy static <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span>&#39;s.
</div><div id="l267" class="code_block">
</div><div id="l268" class="code_block">The public attributes of the type are <span class="nb">{</span><span class="k">\tt</span> int length<span class="nb">}</span> and <span class="nb">{</span><span class="k">\tt</span> char *string<span class="nb">}</span>.
</div><div id="l269" class="code_block">Thus, <span class="nb">{</span><span class="k">\tt</span> buf.string<span class="nb">}</span> represents the actual contents of the buffer and
</div><div id="l270" class="code_block"><span class="nb">{</span><span class="k">\tt</span> buf.length<span class="nb">}</span> is the length of that data. Although the length and the
</div><div id="l271" class="code_block">contents of a <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span> string is readily accessible, the user <span class="nb">{</span><span class="k">\bf</span> must
</div><div id="l272" class="code_block">not<span class="nb">}</span> modify these items directly. Instead, he should use the macros
</div><div id="l273" class="code_block">provided for that purpose:
</div><div id="l274" class="code_block"><span class="c">%%</span>
</div><div id="l275" class="code_block"><span class="k">\begin</span><span class="nb">{</span>itemize<span class="nb">}</span>
</div><div id="l276" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrSET(VarString *vstr, char *str)<span class="nb">}</span>:~
</div><div id="l277" class="code_block">    Assign the value of the regular null-terminated C string to the
</div><div id="l278" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span> <span class="nb">{</span><span class="k">\tt</span> vstr<span class="nb">}</span>. The size of <span class="nb">{</span><span class="k">\tt</span> vstr<span class="nb">}</span> is adjusted
</div><div id="l279" class="code_block">    automatically.
</div><div id="l280" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrSETV(VarString *vstr1, VarString *vstr2)<span class="nb">}</span>:~
</div><div id="l281" class="code_block">    Like <span class="nb">{</span><span class="k">\tt</span> vstrSET<span class="nb">}</span>, but the second argument is a variable-length
</div><div id="l282" class="code_block">    string, not a regular C string.
</div><div id="l283" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrAPPEND(VarString *vstr, char *str)<span class="nb">}</span>:~
</div><div id="l284" class="code_block">    Append the null-terminated string <span class="nb">{</span><span class="k">\tt</span> str<span class="nb">}</span> to the <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span> <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l285" class="code_block">      vstr<span class="nb">}</span>. The size of <span class="nb">{</span><span class="k">\tt</span> vstr<span class="nb">}</span> is adjusted.
</div><div id="l286" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrPREPEND(VarString *vstr, char *str)<span class="nb">}</span>:~
</div><div id="l287" class="code_block">    Like <span class="nb">{</span><span class="k">\tt</span> vstrAPPEND<span class="nb">}</span>, except that <span class="nb">{</span><span class="k">\tt</span> str<span class="nb">}</span> is prepended.
</div><div id="l288" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrAPPENDV(VarString *vstr1, VarString *vstr2)<span class="nb">}</span>:~
</div><div id="l289" class="code_block">    Like <span class="nb">{</span><span class="k">\tt</span> vstrAPPEND<span class="nb">}</span>, except that the second string is also a
</div><div id="l290" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span>.
</div><div id="l291" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrPREPENDV(VarString *vstr1, VarString *vstr2)<span class="nb">}</span>:~
</div><div id="l292" class="code_block">    Like <span class="nb">{</span><span class="k">\tt</span> vstrAPPENDV<span class="nb">}</span>, except that the second string is prepended.
</div><div id="l293" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrCOMPARE(VarString *vstr1, VarString *vstr2)<span class="nb">}</span>:~
</div><div id="l294" class="code_block">    Compares two <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span>. If the first one is lexicographically
</div><div id="l295" class="code_block">    larger, then the result is positive; if the first string is smaller,
</div><div id="l296" class="code_block">    than the result is negative; if the two strings have the same content
</div><div id="l297" class="code_block">    (<span class="nb">{</span><span class="k">\it</span> i.e.<span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> vstr1-&gt;string<span class="nb">}</span> equals <span class="nb">{</span><span class="k">\tt</span> vstr2-&gt;string<span class="nb">}</span> then the
</div><div id="l298" class="code_block">    result is zero.
</div><div id="l299" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrSTRCMP(VarString *vstr, char *str)<span class="nb">}</span>:~
</div><div id="l300" class="code_block">    Like <span class="nb">{</span><span class="k">\tt</span> vstrCOMPARE<span class="nb">}</span> but the second argument is a regular,
</div><div id="l301" class="code_block">    null-terminated string.
</div><div id="l302" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrAPPENDBLK(VarString *vstr, char *blk, int size)<span class="nb">}</span>:~
</div><div id="l303" class="code_block">    This is like <span class="nb">{</span><span class="k">\tt</span> vstrAPPEND<span class="nb">}</span>, but the second argument is not assumed
</div><div id="l304" class="code_block">    to be null-terminated. Instead, <span class="nb">{</span><span class="k">\tt</span> size<span class="nb">}</span> characters pointed to by
</div><div id="l305" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> blk<span class="nb">}</span> are appended to <span class="nb">{</span><span class="k">\tt</span> vstr<span class="nb">}</span>. The size of <span class="nb">{</span><span class="k">\tt</span> vstr<span class="nb">}</span> is
</div><div id="l306" class="code_block">    adjusted, but the content is <span class="k">\emph</span><span class="nb">{</span>not<span class="nb">}</span> null terminated.
</div><div id="l307" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrPREPENDBLK(VarString *vstr, char *blk, int size)<span class="nb">}</span>:~
</div><div id="l308" class="code_block">    Like <span class="nb">{</span><span class="k">\tt</span> vstrPREPEND<span class="nb">}</span>, but <span class="nb">{</span><span class="k">\tt</span> blk<span class="nb">}</span> is not assumed to point to a
</div><div id="l309" class="code_block">    null-terminated string. Instead, <span class="nb">{</span><span class="k">\tt</span> size<span class="nb">}</span> characters from the region
</div><div id="l310" class="code_block">    pointed to by <span class="nb">{</span><span class="k">\tt</span> blk<span class="nb">}</span> are prepended to <span class="nb">{</span><span class="k">\tt</span> vstr<span class="nb">}</span>.
</div><div id="l311" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrNULL<span class="k">\_TERMINATE</span>(VarString *vstr)<span class="nb">}</span>:~
</div><div id="l312" class="code_block">    Null-terminates the <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span>  string <span class="nb">{</span><span class="k">\tt</span> vstr<span class="nb">}</span>. This is used in
</div><div id="l313" class="code_block">    conjunction with <span class="nb">{</span><span class="k">\tt</span> vstrAPPENDBLK<span class="nb">}</span>, because the latter does not
</div><div id="l314" class="code_block">    null-terminate variable-length strings.
</div><div id="l315" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrENSURE<span class="nb">_</span>SIZE(VarString *vstr, int minsize)<span class="nb">}</span>:~
</div><div id="l316" class="code_block">    Ensure that the string has room for at least <span class="nb">{</span><span class="k">\tt</span> minsize<span class="nb">}</span> bytes.
</div><div id="l317" class="code_block">    This is a low-level routine, which is used to interface to procedures
</div><div id="l318" class="code_block">    that do not use <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span> internally.
</div><div id="l319" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrSHRINK(VarString *vstr, int increment)<span class="nb">}</span>:~
</div><div id="l320" class="code_block">    Shrink the size of <span class="nb">{</span><span class="k">\tt</span> vstr<span class="nb">}</span> to the minimum necessary to hold the
</div><div id="l321" class="code_block">    data. <span class="nb">{</span><span class="k">\tt</span> increment<span class="nb">}</span> becomes the new increment by which <span class="nb">{</span><span class="k">\tt</span> vstr<span class="nb">}</span> is
</div><div id="l322" class="code_block">    adjusted. Since <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span> is automatically shrunk by <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l323" class="code_block">      vstrSET<span class="nb">}</span>, it is rarely necessary to shrink a <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span> explicitly.
</div><div id="l324" class="code_block">    However, one might want to change the adustment increment using this
</div><div id="l325" class="code_block">    macro (the default increment is 128).
</div><div id="l326" class="code_block">  <span class="k">\item</span> <span class="nb">{</span><span class="k">\tt</span> vstrDESTROY(VarString *vstr)<span class="nb">}</span>:~
</div><div id="l327" class="code_block">    Destroys a <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span>.  Explicit destruction is necessary for
</div><div id="l328" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> VarString<span class="nb">}</span>&#39;s with the automatic storage class. Otherwise, memory
</div><div id="l329" class="code_block">    leak is possible.
</div><div id="l330" class="code_block"><span class="k">\end</span><span class="nb">{</span>itemize<span class="nb">}</span>
</div><div id="l331" class="code_block"><span class="c">%%</span>
</div><div id="l332" class="code_block">
</div><div id="l333" class="code_block">
</div><div id="l334" class="code_block"><span class="k">\section</span><span class="nb">{</span>Passing Data into an XSB Module<span class="nb">}</span>
</div><div id="l335" class="code_block">
</div><div id="l336" class="code_block">The previous chapter described the low-level XSB/C interface that supports
</div><div id="l337" class="code_block">passing the data of arbitrary complexity between XSB and C. However, in
</div><div id="l338" class="code_block">cases when data needs to be passed into an executable XSB module by the
</div><div id="l339" class="code_block">main C program, the following higher-level interface should suffice.  (This
</div><div id="l340" class="code_block">interface is actually implemented using macros that call the lower level
</div><div id="l341" class="code_block">functions.)  These routines can be used to construct commands and queries
</div><div id="l342" class="code_block">into <span class="k">\ourprolog</span> &#39;s register 1, which is necessary before calling <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l343" class="code_block">  xsb<span class="k">\_query</span>()<span class="nb">}</span> or <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_command</span>()<span class="nb">}</span>.
</div><div id="l344" class="code_block">
</div><div id="l345" class="code_block">
</div><div id="l346" class="code_block"><span class="k">\begin</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l347" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>void xsb<span class="k">\_make\_vars</span>((int) N)<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_make\_vars</span><span class="nb">}}</span>
</div><div id="l348" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_make\_vars</span><span class="nb">}</span> creates a return structure of arity <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span>
</div><div id="l349" class="code_block">in Register 2.  So this routine may called before calling any of <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l350" class="code_block">xsb<span class="k">\_query</span><span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query\_string</span><span class="nb">}</span>, <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_command</span><span class="nb">}</span>, or <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l351" class="code_block">xsb<span class="k">\_command\_string</span><span class="nb">}</span> if parameters are to be set to be sent to the
</div><div id="l352" class="code_block">goal.  It must be called before calling one of the <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l353" class="code_block">xsb<span class="k">\_set\_var\_*</span><span class="nb">}</span> routines can be called. <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span> must be the number
</div><div id="l354" class="code_block">of variables in the query that is to be evaluated.
</div><div id="l355" class="code_block">
</div><div id="l356" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>void xsb<span class="k">\_set\_var\_int</span>((int) Val, (int) N)<span class="nb">}</span> 
</div><div id="l357" class="code_block"><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_set\_var\_int</span><span class="nb">}}</span>
</div><div id="l358" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> set<span class="k">\_and\_int</span><span class="nb">}</span> sets the <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> field in the return
</div><div id="l359" class="code_block">structure to the integer value <span class="nb">{</span><span class="k">\tt</span> Val<span class="nb">}</span>.  It is used to set the value of
</div><div id="l360" class="code_block">the <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> variable in a query before calling <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> or
</div><div id="l361" class="code_block"><span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query\_string</span><span class="nb">}</span>.  When called in <span class="k">\ourprolog</span>, the query will
</div><div id="l362" class="code_block">have the <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> variable set to this value.
</div><div id="l363" class="code_block">
</div><div id="l364" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>void xsb<span class="k">\_set\_var\_string</span>((char *) Val, (int) N)<span class="nb">}</span> 
</div><div id="l365" class="code_block"><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_set\_var\_string</span><span class="nb">}}</span>
</div><div id="l366" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> set<span class="k">\_and\_string</span><span class="nb">}</span> sets the <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> field in the return
</div><div id="l367" class="code_block">structure to the atom with name <span class="nb">{</span><span class="k">\tt</span> Val<span class="nb">}</span>.  It is used to set the
</div><div id="l368" class="code_block">value of the <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> variable in a query before calling <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l369" class="code_block">xsb<span class="k">\_query</span><span class="nb">}</span> or <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query\_string</span><span class="nb">}</span>.  When called in <span class="k">\ourprolog</span>,
</div><div id="l370" class="code_block">the query will have the <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> variable set to this value.
</div><div id="l371" class="code_block">
</div><div id="l372" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>void xsb<span class="k">\_set\_var\_float</span>((float) Val, (int) N)<span class="nb">}</span> 
</div><div id="l373" class="code_block"><span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_set\_var\_float</span><span class="nb">}}</span>
</div><div id="l374" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> set<span class="k">\_and\_float</span><span class="nb">}</span> sets the <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> field in the return
</div><div id="l375" class="code_block">structure to the floating point number with value <span class="nb">{</span><span class="k">\tt</span> Val<span class="nb">}</span>.  It is
</div><div id="l376" class="code_block">used to set the value of the <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> variable in a query before
</div><div id="l377" class="code_block">calling <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> or <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query\_string</span><span class="nb">}</span>.  When called in
</div><div id="l378" class="code_block"><span class="k">\ourprolog</span>, the query will have the <span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> variable set to this
</div><div id="l379" class="code_block">value.
</div><div id="l380" class="code_block">
</div><div id="l381" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>void xsb<span class="k">\_var\_int</span>((int) N)<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_var\_int</span><span class="nb">}}</span>
</div><div id="l382" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_var\_int</span><span class="nb">}</span> is called after <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> or <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l383" class="code_block">xsb<span class="k">\_query\_string</span><span class="nb">}</span> returns an answer.  It returns the value of the
</div><div id="l384" class="code_block"><span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> variable in the query as set in the returned answer.
</div><div id="l385" class="code_block">This variable must have an integer value.
</div><div id="l386" class="code_block">
</div><div id="l387" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>void xsb<span class="k">\_var\_string</span>((int) N)<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_var\_string</span><span class="nb">}}</span>
</div><div id="l388" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_var\_string</span><span class="nb">}</span> is called after <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> or <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l389" class="code_block">xsb<span class="k">\_query\_string</span><span class="nb">}</span> returns an answer.  It returns the value of the
</div><div id="l390" class="code_block"><span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> variable in the query as set in the returned answer.
</div><div id="l391" class="code_block">This variable must have an atom value.
</div><div id="l392" class="code_block">
</div><div id="l393" class="code_block"><span class="k">\ouritem</span><span class="nb">{</span>void xsb<span class="k">\_var\_float</span>((int) N)<span class="nb">}</span> <span class="k">\index</span><span class="nb">{{</span><span class="k">\tt</span> xsb<span class="k">\_var\_float</span><span class="nb">}}</span>
</div><div id="l394" class="code_block">    <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_var\_float</span><span class="nb">}</span> is called after <span class="nb">{</span><span class="k">\tt</span> xsb<span class="k">\_query</span><span class="nb">}</span> or <span class="nb">{</span><span class="k">\tt</span>
</div><div id="l395" class="code_block">xsb<span class="k">\_query\_string</span><span class="nb">}</span> returns an answer.  It returns the value of the
</div><div id="l396" class="code_block"><span class="nb">{</span><span class="k">\tt</span> N<span class="nb">}</span><span class="s">$</span><span class="nb">^{th}</span><span class="s">$</span> variable in the query as set in the returned answer.
</div><div id="l397" class="code_block">This variable must have an floating point value.
</div><div id="l398" class="code_block">
</div><div id="l399" class="code_block">
</div><div id="l400" class="code_block"><span class="k">\end</span><span class="nb">{</span>description<span class="nb">}</span>
</div><div id="l401" class="code_block">
</div><div id="l402" class="code_block">
</div><div id="l403" class="code_block"><span class="k">\section</span><span class="nb">{</span>Creating an XSB Module that Can be Called from C<span class="nb">}</span>
</div><div id="l404" class="code_block">
</div><div id="l405" class="code_block">To create an executable that includes calls to the above C functions,
</div><div id="l406" class="code_block">these routines, and the <span class="k">\ourprolog\</span> routines that they call, must be
</div><div id="l407" class="code_block">included in the link (<span class="nb">{</span><span class="k">\tt</span> ld<span class="nb">}</span>) step.
</div><div id="l408" class="code_block">
</div><div id="l409" class="code_block"><span class="k">\paragraph</span><span class="nb">{</span>Unix instructions:<span class="nb">}</span>
</div><div id="l410" class="code_block">First, you must create a relocatable file, named <span class="nb">{</span><span class="k">\tt</span> xsb.o<span class="nb">}</span>, that
</div><div id="l411" class="code_block">contains all the <span class="k">\ourprolog\</span> routines.  To do this, get into the
</div><div id="l412" class="code_block"><span class="nb">{</span><span class="k">\tt</span> XSB/build<span class="nb">}</span> subdirectory, and execute:
</div><div id="l413" class="code_block"><span class="c">%%</span>
</div><div id="l414" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l415" class="code_block">    <span class="c">% makexsb module</span>
</div><div id="l416" class="code_block"><span class="k">\end</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l417" class="code_block"><span class="c">%%</span>
</div><div id="l418" class="code_block">This will place the relocatable file in:
</div><div id="l419" class="code_block"><span class="c">%%</span>
</div><div id="l420" class="code_block"><span class="k">\begin</span><span class="nb">{</span>verbatim<span class="nb">}</span>
</div><div id="l421" class="code_block"> <span class="s">$</span><span class="nb">XSB_DIR</span><span class="o">/</span><span class="nb">config</span><span class="o">/</span><span class="nb">&lt;your</span><span class="o">-</span><span class="nb">system</span><span class="o">-</span><span class="nb">architecture&gt;</span><span class="o">/</span><span class="nb">saved.o</span><span class="o">/</span><span class="nb">xsb.o  </span>
</div><div id="l422" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l423" class="code_block"><span class="c">%%$</span>
</div><div id="l424" class="code_block">
</div><div id="l425" class="code_block"><span class="nb">Second, you must compile your C program, which includes a main</span>
</div><div id="l426" class="code_block"><span class="nb">procedure.  You should include the file {</span><span class="nv">\tt</span><span class="nb"> cinterf.h} located in the</span>
</div><div id="l427" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> XSB</span><span class="o">/</span><span class="nb">emu} subdirectory, which defines the routines described here</span>
</div><div id="l428" class="code_block"><span class="nb">that you will need to use.</span>
</div><div id="l429" class="code_block">
</div><div id="l430" class="code_block"><span class="nb">Third, to create your executable, after you have created the object</span>
</div><div id="l431" class="code_block"><span class="nb">file, say {</span><span class="nv">\tt</span><span class="nb"> ruleproc.o}, for your C routine, you could execute:</span>
</div><div id="l432" class="code_block"><span class="nv">\begin</span><span class="nb">{verbatim}</span>
</div><div id="l433" class="code_block"><span class="nb">    </span><span class="c">% gcc -o ruleproc ruleproc.o $XSB_DIR/config/&lt;your-system-architecture&gt;/saved.o/xsb.o</span>
</div><div id="l434" class="code_block"><span class="nv">\end</span><span class="nb">{verbatim}</span>
</div><div id="l435" class="code_block">
</div><div id="l436" class="code_block"><span class="nb">The file {</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\$</span><span class="nb">XSB</span><span class="nv">\_</span><span class="nb">DIR</span><span class="o">/</span><span class="nb">config</span><span class="o">/</span><span class="nb">your</span><span class="o">-</span><span class="nb">system</span><span class="o">-</span><span class="nb">architecture</span><span class="o">/</span><span class="nb">modMakefile} is a</span>
</div><div id="l437" class="code_block"><span class="nb">makefile you can use to build your programs and link them with XSB.  It is</span>
</div><div id="l438" class="code_block"><span class="nb">generated automatically and contains all the right settings for your</span>
</div><div id="l439" class="code_block"><span class="nb">architecture, but you will have to fill in the name of your program, etc.</span>
</div><div id="l440" class="code_block">
</div><div id="l441" class="code_block"><span class="nb">There are simple examples of C programs calling </span><span class="nv">\ourprolog\</span><span class="nb"> in the</span>
</div><div id="l442" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> </span><span class="nv">\$</span><span class="nb">XSB</span><span class="nv">\_</span><span class="nb">DIR</span><span class="o">/</span><span class="nb">examples</span><span class="o">/</span><span class="nb">c</span><span class="nv">\_</span><span class="nb">calling</span><span class="nv">\_</span><span class="nb">XSB} directory, in files {</span><span class="nv">\tt</span><span class="nb"> cmain.c},</span>
</div><div id="l443" class="code_block"><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> ctest.P}, {</span><span class="nv">\tt</span><span class="nb"> cmain</span><span class="m">2</span><span class="nb">.c}.</span>
</div><div id="l444" class="code_block">
</div><div id="l445" class="code_block"><span class="nv">\paragraph</span><span class="nb">{Windows instructions:}</span>
</div><div id="l446" class="code_block"><span class="nb">To call XSB from C, you must build it as a DLL. To do this, you specify</span>
</div><div id="l447" class="code_block"><span class="nb">DLL</span><span class="o">=</span><span class="nb">&#39;&#39;yes&#39;&#39; on command line. {</span><span class="nv">\it</span><span class="nb"> E.g.}, </span>
</div><div id="l448" class="code_block"><span class="c">%%</span>
</div><div id="l449" class="code_block"><span class="nv">\begin</span><span class="nb">{quote}</span>
</div><div id="l450" class="code_block"><span class="nb"> {</span><span class="nv">\tt</span><span class="nb"> NMAKE </span><span class="o">/</span><span class="nb">f &quot;MS</span><span class="nv">\_</span><span class="nb">VC</span><span class="nv">\_</span><span class="nb">Mfile.mak&quot; CFG</span><span class="o">=</span><span class="nb">&quot;release&quot; DLL</span><span class="o">=</span><span class="nb">&quot;yes&quot;  }</span>
</div><div id="l451" class="code_block"><span class="nv">\end</span><span class="nb">{quote}</span>
</div><div id="l452" class="code_block"><span class="c">%%</span>
</div><div id="l453" class="code_block"><span class="nb">The DLL, which you can call dynamically from your program is then found in </span>
</div><div id="l454" class="code_block"><span class="c">%%</span>
</div><div id="l455" class="code_block"><span class="nv">\[</span>
</div><div id="l456" class="code_block"><span class="nb"> </span><span class="nv">\tt</span>
</div><div id="l457" class="code_block"><span class="nb"> </span><span class="nv">\$</span><span class="nb">XSB</span><span class="nv">\_</span><span class="nb">DIR</span><span class="nv">\backslash</span><span class="nb"> config</span><span class="nv">\backslash</span><span class="nb"> </span><span class="nv">\mbox</span><span class="nb">{</span><span class="nv">\tt</span><span class="nb"> x</span><span class="m">86</span><span class="o">-</span><span class="nb">pc</span><span class="o">-</span><span class="nb">windows}</span><span class="nv">\backslash</span>
</div><div id="l458" class="code_block"><span class="nb"> saved.o </span><span class="nv">\backslash</span><span class="nb"> xsb.dll</span>
</div><div id="l459" class="code_block"><span class="nv">\]</span>
</div><div id="l460" class="code_block"><span class="c">%%</span>
</div><div id="l461" class="code_block">
</div><div id="l462" class="code_block">
</div><div id="l463" class="code_block"><span class="c">%%% Local Variables: </span>
</div><div id="l464" class="code_block"><span class="c">%%% mode: latex</span>
</div><div id="l465" class="code_block"><span class="c">%%% TeX-master: &quot;manual2&quot;</span>
</div><div id="l466" 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 = 'bf0bf24d-d12c-4904-b5bc-5e2285e4124f';  
            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/1610/tree/trunk/XSB/docs/userman/ccallingxsb.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>