Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > by-pkgid > 2fc07611b08d4a735fd34d5eb60d8e16 > files > 2045

ciao-1.10p8-3mdv2010.0.i586.rpm

<HTML>
<HEAD>
<!-- Created by texi2html 1.56k + clip patches and <A href="http://www.clip.dia.fi.upm.es/Software">lpdoc</A> from ciao.texi on 28 January 2007 -->

<LINK rel="stylesheet" href="ciao.css" type="text/css">
<TITLE>The Ciao Prolog System               - Andorra execution</TITLE>
</HEAD>
<BODY> 
Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_102.html">previous</A>, <A HREF="ciao_104.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>.
<P><HR><P>


<H1><A NAME="SEC425" HREF="ciao_toc.html#TOC425">Andorra execution</A></H1>
<P>
<A NAME="IDX5364"></A>


<P>
<STRONG>Author(s):</STRONG> Claudio Vaucheret, Francisco Bueno.


<P>
<STRONG>Version:</STRONG> 1.10#7 (2006/4/26, 19:22:13 CEST)


<P>
<STRONG>Version of last change:</STRONG> 1.7#144 (2001/11/12, 17:57:47 CET)


<P>
This package allows the execution under the Basic Andorra Model [War88]. The model classifies goals as a 
<A NAME="IDX5365"></A>
<A NAME="IDX5366"></A>
<EM>determinate goal</EM>, if at most one clause matches the goal, or nondeterminate goal, otherwise. In this model a goal is delayed until either it becomes determinate or it becomes the leftmost goal and no determinate goal is available. The implementation of this selection rule is based on the use of attributed variables [Hol92,Hol90]. 


<P>
In order to test determinacy we verify only the heads of clauses and builtins in the bodies of clauses before the first cut, if any. By default, determinacy of a goal is detected dynamically: when called, if at most one clause matches, it is executed; otherwise, it is delayed. For goals delayed the test is repeated each time a variable appearing in the goal is instantiated. In addition, efficiency can be improved by using declarations that specify the determinacy conditions. These will be considered for testing instead of the generic test on all clauses that can match. 


<P>
As with any other Ciao package, the andorra computation rule affects only the module that uses the package. If execution passes across two modules that use the computation rule, determinate goals are run in advance <EM>within</EM> one module and also within the other module. But determinate goals of one module do not run ahead of goals of the other module. 


<P>
It is however possible to preserve the computation rule for calls to predicates defined in other modules. These modules should obviously also use this package. In addition <EM>all</EM> predicates from such modules should imported, i.e., the directive <CODE>:- use_module(module)</CODE>, should be used in this case instead of <CODE>:- use_module(module,[...])</CODE>. Otherwise calls to predicates outside the module will only be called when they became the leftmost goal. 



<UL>
<LI><A HREF="ciao_103.html#SEC426">Usage and interface (andorra)</A>
<LI><A HREF="ciao_103.html#SEC427">Documentation on new declarations (andorra)</A>
<LI><A HREF="ciao_103.html#SEC428">Documentation on exports (andorra)</A>
<LI><A HREF="ciao_103.html#SEC429">Other information (andorra)</A>
</UL>



<H2><A NAME="SEC426" HREF="ciao_toc.html#TOC426">Usage and interface (<CODE>andorra</CODE>)</A></H2>

<div class="cartouche">

<UL>

<LI><STRONG>Library usage:</STRONG>

<CODE>:- use_package(andorra).</CODE>

or

<CODE>:- module(...,...,[andorra]).</CODE>

<LI><STRONG>Exports:</STRONG>


<UL>

<LI><EM>Regular Types:</EM>

<A NAME="IDX5367"></A>
<CODE>detcond/1</CODE>, 
<A NAME="IDX5368"></A>
<CODE>path/1</CODE>.

</UL>

<LI><STRONG>New operators defined:</STRONG>

<A NAME="IDX5369"></A>
<CODE>?\=/2</CODE> [700,xfx], 
<A NAME="IDX5370"></A>
<CODE>?=/2</CODE> [700,xfx].

<LI><STRONG>New declarations defined:</STRONG>

<A NAME="IDX5371"></A>
<CODE>determinate/2</CODE>.

</UL>

</div class="cartouche">



<H2><A NAME="SEC427" HREF="ciao_toc.html#TOC427">Documentation on new declarations (<CODE>andorra</CODE>)</A></H2>
<P>
<A NAME="IDX5372"></A>
<A NAME="IDX5373"></A>
<DL>
<DT><span class="define">DECLARATION:</span> <B>determinate/2:</B>
<DD><A NAME="IDX5374"></A>


<P>
:- <CODE>determinate(Pred, Cond)</CODE>.


<P>
Declares determinacy conditions for a predicate. Conditions <CODE>Cond</CODE> are on variables of arguments of <CODE>Pred</CODE>. For example, in: 

<PRE>
:- determinate(member(A,B,C), ( A ?= term(B,[1])  ; C?=[_|_]) ).

member(A,[A|B],B).
member(A,[B|C],[B|D]) :-
        A==B,
        member(A,C,D).
</PRE>

<P>
the declaration states that a call <CODE>member(A,B,C)</CODE> is determinate when either <CODE>A</CODE> doesn't unify with the first argument of <CODE>B</CODE> or <CODE>C</CODE> doesn't unify with <CODE>[_|_]</CODE>.


<P>
<STRONG>Usage:</STRONG> :- <CODE>determinate(Pred, Cond)</CODE>.

<UL>
<LI><EM>Description:</EM> States that the predicate <CODE>Pred</CODE> is determinate when <CODE>Cond</CODE> holds.

<LI><EM>The following properties should hold at call time:</EM>

<CODE>Pred</CODE> is a Name/Arity structure denoting a predicate name: 

<PRE>
predname(P/A) :-
        atm(P),
        nnegint(A).
</PRE>

 (<CODE>basic_props:predname/1</CODE>)

<CODE>Cond</CODE> is a determinacy condition.
 (<CODE>user(... /andorra_doc):detcond/1</CODE>)
</UL>

</DL>



<H2><A NAME="SEC428" HREF="ciao_toc.html#TOC428">Documentation on exports (<CODE>andorra</CODE>)</A></H2>
<P>
<A NAME="IDX5375"></A>
<A NAME="IDX5376"></A>
<DL>
<DT><span class="define">REGTYPE:</span> <B>detcond/1:</B>
<DD><A NAME="IDX5377"></A>


<P>
Defined by: 

<PRE>
detcond(ground(X)) :-
        var(X).
detcond(nonvar(X)) :-
        var(X).
detcond(instatiated(A,Path)) :-
        var(A),
        list(Path,int).
detcond(?\=(Term1,Term2)) :-
        path(Term1),
        path(Term2).
detcond(?=(Term1,Term2)) :-
        path(Term1),
        path(Term2).
detcond(Test) :-
        test(Test).
</PRE>


<UL>
<LI><CODE>ground/1</CODE> and <CODE>nonvar/1</CODE> have the usual meaning.

<LI><CODE>instatiated(A,Path)</CODE> means that the subterm of <CODE>A</CODE> addressed by <CODE>Path</CODE> is not a variable. <CODE>Path</CODE> is a list of integer numbers describing a path to the subterm regarding the whole term A as a tree. For example, <CODE>instantiated(f(g(X),h(i(Z),Y)),[2,1])</CODE> tests whether <CODE>i(Z)</CODE> is not a variable.

<LI><CODE>Term1 ?\= Term2</CODE> means "terms <CODE>Term1</CODE> and <CODE>Term2</CODE> do not unify (when instantiated)". <CODE>Term1</CODE> and <CODE>Term2</CODE> can be either an argument of the predicate or a term <CODE>term(V,Path)</CODE>, which refers to the subterm of <CODE>V</CODE> addressed by <CODE>Path</CODE>.

<LI><CODE>Term1 ?= Term2</CODE> means "terms <CODE>Term1</CODE> and <CODE>Term2</CODE> unify (when instantiated)". The same considerations above apply to <CODE>Term1</CODE> and <CODE>Term2</CODE>.

<LI>any other test that does not unify variables can also be used ( <CODE>==/2</CODE>, <CODE>\==/2</CODE>, <CODE>atomic/1</CODE>).

</UL>

<P>
<STRONG>Usage:</STRONG> <CODE>detcond(X)</CODE>

<UL>
<LI><EM>Description:</EM> <CODE>X</CODE> is a determinacy condition.

</UL>

</DL>

<P>
<A NAME="IDX5378"></A>
<A NAME="IDX5379"></A>
<DL>
<DT><span class="define">REGTYPE:</span> <B>path/1:</B>
<DD><A NAME="IDX5380"></A>


<P>
Defined by: 

<PRE>
path(X) :-
        var(X).
path(X) :-
        list(X,int).
</PRE>

</DL>



<H2><A NAME="SEC429" HREF="ciao_toc.html#TOC429">Other information (<CODE>andorra</CODE>)</A></H2>

<P>
The andorra transformation will include the following predicates into the code of the module that uses the package. Be careful not to define predicates by these names: 

<UL>
<LI><CODE>detcond_andorra/4</CODE>

<LI><CODE>path_andorra/4</CODE>

<LI><CODE>detcond_susp/4</CODE>

<LI><CODE>path_susp/4</CODE>

<LI><CODE>list_andorra2/5</CODE>

<LI><CODE>test_andorra2/4</CODE>

</UL>

<P><HR><P>
Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_102.html">previous</A>, <A HREF="ciao_104.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>.
</BODY>
</HTML>