<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 - Call on determinate</TITLE> </HEAD> <BODY> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_103.html">previous</A>, <A HREF="ciao_105.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="SEC430" HREF="ciao_toc.html#TOC430">Call on determinate</A></H1> <P> <A NAME="IDX5381"></A> <P> <STRONG>Author(s):</STRONG> José Morales, Manuel Carro. <P> <STRONG>Version:</STRONG> 1.7#149 (2001/11/19, 19:17:51 CET) <P> Offers an enriched variant of call and cut <CODE>!!/0</CODE> which executes pending goals when the computation has no more alternatives. <P> This library is useful to, for example, get rid of external connections once the necessary data has been obtained. <UL> <LI><A HREF="ciao_104.html#SEC431">Usage and interface (det_hook_rt)</A> <LI><A HREF="ciao_104.html#SEC432">Documentation on exports (det_hook_rt)</A> <LI><A HREF="ciao_104.html#SEC433">Documentation on internals (det_hook_rt)</A> <LI><A HREF="ciao_104.html#SEC434">Other information (det_hook_rt)</A> <LI><A HREF="ciao_104.html#SEC435">Known bugs and planned improvements (det_hook_rt)</A> </UL> <H2><A NAME="SEC431" HREF="ciao_toc.html#TOC431">Usage and interface (<CODE>det_hook_rt</CODE>)</A></H2> <div class="cartouche"> <UL> <LI><STRONG>Library usage:</STRONG> <PRE> :- use_module(library(det_hook_rt)). </PRE> in which case, <CODE>!!/0</CODE> is not available. Typically, this library is used as a package: <PRE> :- use_package(det_hook). </PRE> <LI><STRONG>Exports:</STRONG> <UL> <LI><EM>Predicates:</EM> <A NAME="IDX5382"></A> <CODE>det_try/3</CODE>. </UL> </UL> </div class="cartouche"> <H2><A NAME="SEC432" HREF="ciao_toc.html#TOC432">Documentation on exports (<CODE>det_hook_rt</CODE>)</A></H2> <P> <A NAME="IDX5383"></A> <A NAME="IDX5384"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>det_try/3:</B> <DD><A NAME="IDX5385"></A> <P> <EM>Meta-predicate</EM> with arguments: <CODE>det_try(goal,goal,goal)</CODE>. <P> <STRONG>Usage:</STRONG> <CODE>det_try(Goal, OnCut, OnFail)</CODE> <UL> <LI><EM>Description:</EM> <CODE>Action</CODE> is called, and <CODE>OnCut</CODE> and <CODE>OnFail</CODE> are goals to be executed when <CODE>Goal</CODE> is cut or when it finitely fails, respectively. In order for this to work, cutting must be performed in a special way, by using the <A NAME="IDX5386"></A> <CODE>!!/0</CODE> predicate, also provided by this module. <LI><EM>The following properties should hold at call time:</EM> <CODE>Goal</CODE> is a term which represents a goal, i.e., an atom or a structure. (<CODE>basic_props:callable/1</CODE>) <CODE>OnCut</CODE> is a term which represents a goal, i.e., an atom or a structure. (<CODE>basic_props:callable/1</CODE>) <CODE>OnFail</CODE> is a term which represents a goal, i.e., an atom or a structure. (<CODE>basic_props:callable/1</CODE>) </UL> </DL> <H2><A NAME="SEC433" HREF="ciao_toc.html#TOC433">Documentation on internals (<CODE>det_hook_rt</CODE>)</A></H2> <P> <A NAME="IDX5387"></A> <A NAME="IDX5388"></A> <DL> <DT><span class="define">PREDICATE:</span> <B>!!/0:</B> <DD><A NAME="IDX5389"></A> <P> <STRONG>Usage:</STRONG> <UL> <LI><EM>Description:</EM> Performs a special cut which prunes alternatives away, as the usual cut, but which also executes the goals specified as <CODE>OnCut</CODE> for any call in the scope of the cut. </UL> </DL> <H2><A NAME="SEC434" HREF="ciao_toc.html#TOC434">Other information (<CODE>det_hook_rt</CODE>)</A></H2> <P> As an example, the program <PRE> :- module(_, _, [det_hook]). enumerate(X):- display(enumerating), nl, OnCut = (display('goal cut'), nl), OnFail = (display('goal failed'), nl), det_try(enum(X), OnCut, OnFail). enum(1). enum(2). enum(3). </PRE> <P> behaves as follows: <PRE> ?- enumerate(X). enumerating X = 1 ? ; X = 2 ? ; X = 3 ? ; goal failed </PRE> <P> (note the message inserted on failure). The execution can be cut as follows: <PRE> ?- use_package(det_hook). {Including /home/clip/lib/ciao/ciao-1.7/library/det_hook/det_hook.pl } yes ?- enumerate(X), '!!'. enumerating goal cut X = 1 ? ; no </PRE> <H2><A NAME="SEC435" HREF="ciao_toc.html#TOC435">Known bugs and planned improvements (<CODE>det_hook_rt</CODE>)</A></H2> <UL> <LI> If the started goals do not exhaust their solutions, and '!!'/0 is not used, the database will populate with facts which will be consulted the next time a '!!'/0 is used. This could cause incorrect executions. </UL> <P><HR><P> Go to the <A HREF="ciao_1.html">first</A>, <A HREF="ciao_103.html">previous</A>, <A HREF="ciao_105.html">next</A>, <A HREF="ciao_241.html">last</A> section, <A HREF="ciao_toc.html">table of contents</A>. </BODY> </HTML>