/usr/share/doc/swi-prolog-doc/Manual/control.html is in swi-prolog-doc 5.6.59-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>SWI-Prolog 5.6.59 Reference Manual: Section 4.7</TITLE><LINK REL=home HREF="index.html">
<LINK REL=contents HREF="Contents.html">
<LINK REL=index HREF="DocIndex.html">
<LINK REL=previous HREF="compare.html">
<LINK REL=next HREF="metacall.html">
<STYLE type="text/css">
/* Style sheet for SWI-Prolog latex2html
*/
dd.defbody
{ margin-bottom: 1em;
}
dt.pubdef
{ background-color: #c5e1ff;
}
pre.code
{ margin-left: 1.5em;
margin-right: 1.5em;
border: 1px dotted;
padding-top: 5px;
padding-left: 5px;
padding-bottom: 5px;
background-color: #f8f8f8;
}
div.navigate
{ text-align: center;
background-color: #f0f0f0;
border: 1px dotted;
padding: 5px;
}
div.title
{ text-align: center;
padding-bottom: 1em;
font-size: 200%;
font-weight: bold;
}
div.author
{ text-align: center;
font-style: italic;
}
div.abstract
{ margin-top: 2em;
background-color: #f0f0f0;
border: 1px dotted;
padding: 5px;
margin-left: 10%; margin-right:10%;
}
div.abstract-title
{ text-align: center;
padding: 5px;
font-size: 120%;
font-weight: bold;
}
div.toc-h1
{ font-size: 200%;
font-weight: bold;
}
div.toc-h2
{ font-size: 120%;
font-weight: bold;
margin-left: 2em;
}
div.toc-h3
{ font-size: 100%;
font-weight: bold;
margin-left: 4em;
}
div.toc-h4
{ font-size: 100%;
margin-left: 6em;
}
span.sec-nr
{
}
span.sec-title
{
}
span.pred-ext
{ font-weight: bold;
}
span.pred-tag
{ float: right;
font-size: 80%;
font-style: italic;
color: #202020;
}
/* Footnotes */
sup.fn { color: blue; text-decoration: underline; }
span.fn-text { display: none; }
sup.fn span {display: none;}
sup:hover span
{ display: block !important;
position: absolute; top: auto; left: auto; width: 80%;
color: #000; background: white;
border: 2px solid;
padding: 5px; margin: 10px; z-index: 100;
font-size: smaller;
}
</STYLE>
</HEAD>
<BODY BGCOLOR="white">
<DIV class="navigate"><A class="nav" href="index.html"><IMG SRC="home.gif" BORDER=0 ALT="Home"></A>
<A class="nav" href="Contents.html"><IMG SRC="index.gif" BORDER=0 ALT="Contents"></A>
<A class="nav" href="DocIndex.html"><IMG SRC="yellow_pages.gif" BORDER=0 ALT="Index"></A>
<A class="nav" href="compare.html"><IMG SRC="prev.gif" BORDER=0 ALT="Previous"></A>
<A class="nav" href="metacall.html"><IMG SRC="next.gif" BORDER=0 ALT="Next"></A>
</DIV>
<H2><A NAME="sec:4.7"><SPAN class="sec-nr">4.7</SPAN> <SPAN class="sec-title">Control
Predicates</SPAN></A></H2>
<A NAME="sec:control"></A>
<P>The predicates of this section implement control structures. Normally
the constructs in this section, except for <A NAME="idx:repeat0:497"></A><A class="pred" href="control.html#repeat/0">repeat/0</A>,
are translated by the compiler. Please note that complex goals passed as
arguments to meta-predicates such as <A NAME="idx:findall3:498"></A><A class="pred" href="allsolutions.html#findall/3">findall/3</A>
below cause the goal to be compiled to a temporary location before
execution. It is faster to define a sub-predicate (i.e. one_character_atom/1
in the example below) and make a call to this simple predicate.
<PRE class="code">
one_character_atoms(As) :-
findall(A, (current_atom(A), atom_length(A, 1)), As).
</PRE>
<DL>
<DT class="pubdef"><span class="pred-tag">[ISO]</span><A NAME="fail/0"><STRONG>fail</STRONG></A></DT>
<DD class="defbody">
Always fail. The predicate <A NAME="idx:fail0:499"></A><A class="pred" href="control.html#fail/0">fail/0</A>
is translated into a single virtual machine instruction.
</DD>
<DT class="pubdef"><A NAME="false/0"><STRONG>false</STRONG></A></DT>
<DD class="defbody">
Same as fail, but the name has a more declarative conotation.
</DD>
<DT class="pubdef"><span class="pred-tag">[ISO]</span><A NAME="true/0"><STRONG>true</STRONG></A></DT>
<DD class="defbody">
Always succeed. The predicate <A NAME="idx:true0:500"></A><A class="pred" href="control.html#true/0">true/0</A>
is translated into a single virtual machine instruction.
</DD>
<DT class="pubdef"><span class="pred-tag">[ISO]</span><A NAME="repeat/0"><STRONG>repeat</STRONG></A></DT>
<DD class="defbody">
Always succeed, provide an infinite number of choice points.
</DD>
<DT class="pubdef"><span class="pred-tag">[ISO]</span><A NAME="!/0"><STRONG>!</STRONG></A></DT>
<DD class="defbody">
Cut. Discard choice points of parent frame and frames created after the
parent frame. As of SWI-Prolog 3.3, the semantics of the cut are
compliant with the ISO standard. This implies that the cut is
transparent to <A class="pred" href="control.html#;/2">;/2</A>, <A class="pred" href="control.html#send_arrow/2">->/2</A>
and <A class="pred" href="control.html#*->/2">*->/2</A>. Cuts
appearing in the <EM>condition</EM> part of <A class="pred" href="control.html#send_arrow/2">->/2</A>
and
<A class="pred" href="control.html#*->/2">*->/2</A> as well as in <A class="pred" href="control.html#\+/1">\+/1</A>
are local to the condition.<SUP class="fn">29<SPAN class="fn-text">Up to
version 4.0.6, the sequence X=!, X acted as a true cut. This feature has
been deleted for ISO compliance.</SPAN></SUP>
<P>
<CENTER>
<TABLE BORDER=0 FRAME=void RULES=groups>
<TR VALIGN=top><TD><CODE>t1 :- (a, !, fail ; b).</CODE> </TD><TD>% cuts a/0
and t1/0 </TD></TR>
<TR VALIGN=top><TD><CODE>t2 :- (a -> b, ! ; c).</CODE> </TD><TD>%
cuts b/0 and t2/0 </TD></TR>
<TR VALIGN=top><TD><CODE>t3 :- call((a, !, fail ; b)).</CODE> </TD><TD>%
cuts a/0 </TD></TR>
<TR VALIGN=top><TD><CODE>t4 :- <CODE>\+</CODE>(a, !, fail ; b).</CODE> </TD><TD>%
cuts a/0 </TD></TR>
</TABLE>
</CENTER>
</DD>
<DT class="pubdef"><span class="pred-tag">[ISO]</span><A NAME=",/2"><VAR>+Goal1</VAR> <STRONG>,</STRONG> <VAR>+Goal2</VAR></A></DT>
<DD class="defbody">
Conjunction. True if both `Goal1' and `Goal2' can be proved. It is
defined as (this definition does not lead to a loop as the second comma
is handled by the compiler):
<PRE class="code">
Goal1, Goal2 :- Goal1, Goal2.
</PRE>
</DD>
<DT class="pubdef"><span class="pred-tag">[ISO]</span><A NAME=";/2"><VAR>+Goal1</VAR> <STRONG>;</STRONG> <VAR>+Goal2</VAR></A></DT>
<DD class="defbody">
The `or' predicate is defined as:
<PRE class="code">
Goal1 ; _Goal2 :- Goal1.
_Goal1 ; Goal2 :- Goal2.
</PRE>
</DD>
<DT class="pubdef"><A NAME="|/2"><VAR>+Goal1</VAR> <STRONG>|</STRONG> <VAR>+Goal2</VAR></A></DT>
<DD class="defbody">
Equivalent to <A class="pred" href="control.html#;/2">;/2</A>. Retained
for compatibility only. New code should use <A class="pred" href="control.html#;/2">;/2</A>.</DD>
<DT class="pubdef"><span class="pred-tag">[ISO]</span><A NAME="send_arrow/2"><VAR>+Condition</VAR> <STRONG>-></STRONG> <VAR>+Action</VAR></A></DT>
<DD class="defbody">
If-then and If-Then-Else. The <A class="pred" href="control.html#send_arrow/2">->/2</A>
construct commits to the choices made at its left-hand side, destroying
choice-points created inside the clause (by <A class="pred" href="control.html#;/2">;/2</A>),
or by goals called by this clause. Unlike <A class="pred" href="control.html#!/0">!/0</A>,
the choice-point of the predicate as a whole (due to multiple clauses)
is <STRONG>not</STRONG> destroyed. The combination <A class="pred" href="control.html#;/2">;/2</A>
and <A class="pred" href="control.html#send_arrow/2">->/2</A> acts as
if defines by:
<PRE class="code">
If -> Then; _Else :- If, !, Then.
If -> _Then; Else :- !, Else.
If -> Then :- If, !, Then.
</PRE>
<P>Please note that (If <CODE>-></CODE> Then) acts as (If <CODE>-></CODE>
Then ;
<B>fail</B>), making the construct <EM>fail</EM> if the condition fails.
This unusual semantics is part of the ISO and all de-facto Prolog
standards.</DD>
<DT class="pubdef"><A NAME="*->/2"><VAR>+Condition</VAR> <STRONG>*-></STRONG> <VAR>+Action
; +Else</VAR></A></DT>
<DD class="defbody">
This construct implements the so-called `soft-cut'. The control is
defined as follows: If <VAR>Condition</VAR> succeeds at least once, the
semantics is the same as (<VAR>Condition</VAR>, <VAR>Action</VAR>). If
<VAR>Condition</VAR> does not succeed, the semantics is that of (<CODE>\+</CODE> <VAR>Condition</VAR>, <VAR>Else</VAR>).
In other words, If
<VAR>Condition</VAR> succeeds at least once, simply behave as the
conjunction of <VAR>Condition</VAR> and <VAR>Action</VAR>, otherwise
execute <VAR>Else</VAR>.
<P>The construct <VAR>A</VAR> <CODE>*-></CODE> <VAR>B</VAR>, i.e. without
an
<VAR>Else</VAR> branch, is translated as the normal conjunction <VAR>A</VAR>,
<VAR>B</VAR>.<SUP class="fn">bug<SPAN class="fn-text">The decompiler
implemented by <A NAME="idx:clause2:501"></A><A class="pred" href="examineprog.html#clause/2">clause/2</A>
returns this construct as a normal conjunction too.</SPAN></SUP></DD>
<DT class="pubdef"><span class="pred-tag">[ISO]</span><A NAME="\+/1"><STRONG>\+</STRONG> <VAR>+Goal</VAR></A></DT>
<DD class="defbody">
True if `Goal' cannot be proven (mnemonic: <CODE><CODE>+</CODE></CODE>
refers to <EM>provable</EM> and the backslash (<CODE><CODE>\</CODE></CODE>)
is normally used to indicate negation in Prolog).
</DD>
</DL>
<P></BODY></HTML>
|